Class: Neo4jr::DB

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4jr/db.rb

Class Method Summary collapse

Class Method Details

.executeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/neo4jr/db.rb', line 22

def execute
  neo = instance
  result = nil
  transaction = neo.beginTx();
  begin
    result = yield neo
    transaction.success
  rescue Exception => e
    transaction.failure
    raise e
  ensure
    transaction.finish
  end
  result
end

.getNodeById(node_id) ⇒ Object



16
17
18
19
20
# File 'lib/neo4jr/db.rb', line 16

def getNodeById(node_id)
  execute do |neo|
    neo.getNodeById(node_id)
  end
end

.instanceObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/neo4jr/db.rb', line 5

def instance
  @neo ||= begin
    neo = EmbeddedGraphDatabase.new(Configuration.database_path)
    at_exit do
      neo.shutdown
    end
    Neo4jr::Indexer.use neo
    neo
  end
end

.node_countObject



38
39
40
# File 'lib/neo4jr/db.rb', line 38

def node_count
  instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.graphdb.Node.java_class)
end

.statsObject



42
43
44
45
46
47
# File 'lib/neo4jr/db.rb', line 42

def stats
  {
    :path => Configuration.database_path,
    :nodes => node_count
  }
end

.to_sObject



49
50
51
# File 'lib/neo4jr/db.rb', line 49

def to_s
  stats.inspect
end