Class: Neon::Session::Embedded
- Inherits:
-
Object
- Object
- Neon::Session::Embedded
- Includes:
- TransactionHelpers
- Defined in:
- lib/neon/session/embedded.rb
Overview
A session to an embedded instance of Neo4J
Instance Method Summary collapse
- #auto_tx ⇒ Object
- #begin_tx ⇒ Object
-
#create_node(attributes, labels) ⇒ Object
Nodes Create a new node.
-
#database ⇒ Java::OrgNeo4jKernel::EmbeddedGraphDatabase
The Java graph database backing this session.
-
#initialize(path = "neo4j", auto_tx = true) ⇒ Embedded
constructor
Create a new session to an embedded database.
- #load(id) ⇒ Object
- #load_rel(id) ⇒ Object
- #run_tx(&block) ⇒ Object
-
#running? ⇒ Boolean
Wether the session is running or not.
-
#start ⇒ Boolean
Wether the session started successfully.
-
#stop ⇒ Boolean
Wether the session stopped successfully.
- #to_s ⇒ Object
Constructor Details
#initialize(path = "neo4j", auto_tx = true) ⇒ Embedded
Create a new session to an embedded database.
16 17 18 19 20 21 |
# File 'lib/neon/session/embedded.rb', line 16 def initialize(path = "neo4j", auto_tx = true) raise "Cannot start a embedded session without JRuby" if RUBY_PLATFORM != 'java' @db_location = path @running = false @auto_tx = auto_tx end |
Instance Method Details
#auto_tx ⇒ Object
8 9 10 |
# File 'lib/neon/session/embedded.rb', line 8 def auto_tx @auto_tx end |
#begin_tx ⇒ Object
49 50 51 |
# File 'lib/neon/session/embedded.rb', line 49 def begin_tx @db.begin_tx end |
#create_node(attributes, labels) ⇒ Object
Nodes Create a new node. If auto_tx is true then we begin a new transaction and commit it after the creation
59 60 61 |
# File 'lib/neon/session/embedded.rb', line 59 def create_node(attributes, labels) run_in_transaction { _create_node attributes, labels } end |
#database ⇒ Java::OrgNeo4jKernel::EmbeddedGraphDatabase
Returns the Java graph database backing this session.
29 30 31 |
# File 'lib/neon/session/embedded.rb', line 29 def database @db end |
#load(id) ⇒ Object
63 64 65 |
# File 'lib/neon/session/embedded.rb', line 63 def load(id) run_in_transaction { _load id } end |
#load_rel(id) ⇒ Object
67 68 69 |
# File 'lib/neon/session/embedded.rb', line 67 def load_rel(id) run_in_transaction { _load_rel id } end |
#run_tx(&block) ⇒ Object
53 54 55 |
# File 'lib/neon/session/embedded.rb', line 53 def run_tx(&block) Transaction::Placebo.run(begin_tx, &block) end |
#running? ⇒ Boolean
Returns wether the session is running or not.
24 25 26 |
# File 'lib/neon/session/embedded.rb', line 24 def running? @running end |
#start ⇒ Boolean
Returns wether the session started successfully.
34 35 36 37 38 39 |
# File 'lib/neon/session/embedded.rb', line 34 def start return false if @started @started = true @db = Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory.new.(@db_location) @running = true end |
#stop ⇒ Boolean
Returns wether the session stopped successfully.
42 43 44 45 46 47 |
# File 'lib/neon/session/embedded.rb', line 42 def stop return false if @stopped @db.shutdown @running = false @stopped = true end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/neon/session/embedded.rb', line 71 def to_s @db_location end |