Skip to content

Commit

Permalink
Fixed bug on counting primitives [#59 state:resolved]
Browse files Browse the repository at this point in the history
Not sure if Neo4j.number_of_properties_in_use will return the exact number of properties in use, but its works better then before ...
  • Loading branch information
andreas committed Jul 30, 2009
1 parent 8fe1d1a commit 4c5ef26
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/neo4j/neo.rb
Expand Up @@ -115,10 +115,27 @@ def self.number_of_relationships_in_use
instance.neo.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.api.core.Relationship.java_class)
end

def self.number_of_properties_in_use
# Total number of relationships, nodes and properties in use
def self.number_of_ids_in_use
instance.neo.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.impl.nioneo.store.PropertyStore.java_class)
end

def self.number_of_properties_in_use
self.number_of_ids_in_use - self.number_of_relationships_in_use - self.number_of_nodes_in_use + 1
end

# Prints some info about the database
def self.info
puts "Neo4j version: #{Neo4j::VERSION}"
puts "Neo4j db running #{self.running?}"
puts "number_of_nodes_in_use: #{self.number_of_nodes_in_use}"
puts "number_of_relationships_in_use: #{self.number_of_relationships_in_use}"
puts "number_of_properties_in_use: #{self.number_of_properties_in_use}"
puts "number_of_ids_in_use: #{self.number_of_ids_in_use}"
puts "neo db storage location: #{Neo4j::Config[:storage_path]}"
puts "lucene index storage location: #{Lucene::Config[:storage_path]}"
puts "keep lucene index in memory: #{!Lucene::Config[:store_on_file]}"
end
#
# Allows run and stop the Neo4j service
# Contains global ćonstants such as location of the neo storage and index files
Expand Down
19 changes: 19 additions & 0 deletions test/neo4j/neo_spec.rb
Expand Up @@ -80,6 +80,25 @@ class Foo
Neo4j.number_of_properties_in_use.should == 1
end

it "should only count properties using Neo4j.number_of_properties_in_use" do
# only reference node exists
node1 = node2 = nil
Neo4j::Transaction.run do
node1 = Neo4j::Node.new
node2 = Neo4j::Node.new
end

Neo4j.number_of_properties_in_use.should == 1 # a bit weird, should be 3 since each node sets the classname property ...


Neo4j::Transaction.run do
node1.relationships.outgoing(:baaz) << node2
Neo4j::Node.new
end

Neo4j.number_of_properties_in_use.should == 1
end

it "should return correct number of properties when using Neo4j.number_of_relationships_in_use" do
# create two nodes that we can create relationships between
node1 = node2 = nil
Expand Down

0 comments on commit 4c5ef26

Please sign in to comment.