Sha256: 585e869f9c562c326668792655e12708929986ea744f6f9b700b7d328859a958

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module Neo4jr
  class DB
    class << self
      def instance
        @neo ||= begin
          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)
        execute do |neo|
          neo.getNodeById(node_id)
        end
      end
      
      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
      
      def node_count
        instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.api.core.Node.java_class)
      end
      
      def stats
        {
          :path => Configuration.database_path,
          :nodes => node_count
        }
      end
      
      def to_s
        stats.inspect
      end      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
neo4jr-simple-0.1.6 lib/neo4jr/db.rb
neo4jr-simple-0.1.5 lib/neo4jr/db.rb