lib/neo4jr/db.rb in neo4jr-simple-0.1.3 vs lib/neo4jr/db.rb in neo4jr-simple-0.1.5
- old
+ new
@@ -1,54 +1,53 @@
module Neo4jr
class DB
class << self
def instance
@neo ||= begin
- neo = org.neo4j.api.core.EmbeddedNeo.new(Configuration.database_path)
- neo.enable_remote_shell
+ neo = EmbeddedNeo.new(Configuration.database_path)
+ neo.enable_remote_shell if ENV['enable_neo_shell']
at_exit do
neo.shutdown
end
neo
end
end
def getNodeById(node_id)
- n = nil
execute do |neo|
- n = neo.getNodeById(node_id)
+ neo.getNodeById(node_id)
end
- return n
end
def execute
neo = instance
+ result = nil
transaction = neo.beginTx();
begin
- yield neo
+ result = yield neo
transaction.success
rescue Exception => e
transaction.failure
raise e
ensure
transaction.finish
end
+ result
end
def node_count
instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.api.core.Node.java_class)
end
def stats
- info = ['== Database Stats ==']
- info << "Path: #{Configuration.database_path}"
- info << "Nodes: #{node_count}"
- info << '===================='
- info.join("\n")
+ {
+ :path => Configuration.database_path,
+ :nodes => node_count
+ }
end
def to_s
- stats
+ stats.inspect
end
end
end
end
\ No newline at end of file