Class: Neon::Session::Embedded

Inherits:
Object
  • Object
show all
Includes:
TransactionHelpers
Defined in:
lib/neon/session/embedded.rb

Overview

A session to an embedded instance of Neo4J

Instance Method Summary collapse

Constructor Details

#initialize(path = "neo4j", auto_tx = true) ⇒ Embedded

Create a new session to an embedded database.

Parameters:

  • path (String) (defaults to: "neo4j")

    a path to the location of the embedded database.

  • auto_tx (Boolean) (defaults to: true)

    an optional flag to set auto transaction (defaults to true).



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_txObject



8
9
10
# File 'lib/neon/session/embedded.rb', line 8

def auto_tx
  @auto_tx
end

#begin_txObject



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

#databaseJava::OrgNeo4jKernel::EmbeddedGraphDatabase

Returns the Java graph database backing this session.

Returns:

  • (Java::OrgNeo4jKernel::EmbeddedGraphDatabase)

    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.

Returns:

  • (Boolean)

    wether the session is running or not.



24
25
26
# File 'lib/neon/session/embedded.rb', line 24

def running?
  @running
end

#startBoolean

Returns wether the session started successfully.

Returns:

  • (Boolean)

    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.new_embedded_database(@db_location)
  @running = true
end

#stopBoolean

Returns wether the session stopped successfully.

Returns:

  • (Boolean)

    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_sObject



71
72
73
# File 'lib/neon/session/embedded.rb', line 71

def to_s
  @db_location
end