neo4j-wrapper 0.0.1-java → 0.0.2-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/neo4j/node_mixin.rb +6 -5
- data/lib/neo4j/relationship_mixin.rb +1 -0
- data/lib/neo4j-wrapper/class_methods.rb +1 -1
- data/lib/neo4j-wrapper/node_mixin/class_methods.rb +13 -0
- data/lib/neo4j-wrapper/properties/class_methods.rb +1 -2
- data/lib/neo4j-wrapper/properties/instance_methods.rb +19 -0
- data/lib/neo4j-wrapper/relationship_mixin/class_methods.rb +13 -0
- data/lib/neo4j-wrapper/rule/functions/count.rb +5 -2
- data/lib/neo4j-wrapper/rule/rule.rb +5 -1
- data/lib/neo4j-wrapper/version.rb +1 -1
- data/lib/neo4j-wrapper.rb +2 -0
- metadata +3 -4
- data/lib/example.rb +0 -34
- data/lib/test.rb +0 -61
data/lib/neo4j/node_mixin.rb
CHANGED
@@ -15,11 +15,11 @@ module Neo4j
|
|
15
15
|
#
|
16
16
|
# = Class Method Modules
|
17
17
|
# * {Neo4j::Wrapper::ClassMethods}
|
18
|
-
# * {Neo4j::Wrapper::NodeMixin::ClassMethods}
|
19
|
-
# * {Neo4j::Wrapper::Property::ClassMethods}
|
20
|
-
# * {Neo4j::Wrapper::HasN::ClassMethods}
|
21
|
-
# * {Neo4j::Wrapper::Find}
|
22
|
-
# * {Neo4j::Wrapper::Rule::ClassMethods}
|
18
|
+
# * {Neo4j::Wrapper::NodeMixin::ClassMethods} - redefines the <tt>new</tt> method
|
19
|
+
# * {Neo4j::Wrapper::Property::ClassMethods} - defines <tt>property</tt> method
|
20
|
+
# * {Neo4j::Wrapper::HasN::ClassMethods} - defines <tt>has_n</tt> and <tt>has_one</tt> method
|
21
|
+
# * {Neo4j::Wrapper::Find} - defines <tt>find</tt> method
|
22
|
+
# * {Neo4j::Wrapper::Rule::ClassMethods} - defines <tt>rule</tt> method
|
23
23
|
# * {http://rdoc.info/github/andreasronge/neo4j-core/master/Neo4j/Core/Index/ClassMethods Neo4j::Core::Index::ClassMethods}
|
24
24
|
#
|
25
25
|
# = Instance Method Modules
|
@@ -29,6 +29,7 @@ module Neo4j
|
|
29
29
|
include Neo4j::Wrapper::NodeMixin::Initialize
|
30
30
|
include Neo4j::Wrapper::HasN::InstanceMethods
|
31
31
|
include Neo4j::Wrapper::Rule::InstanceMethods
|
32
|
+
include Neo4j::Wrapper::Property::InstanceMethods
|
32
33
|
include Neo4j::Core::Index
|
33
34
|
|
34
35
|
# @private
|
@@ -47,6 +47,19 @@ module Neo4j
|
|
47
47
|
end
|
48
48
|
|
49
49
|
alias_method :create, :new
|
50
|
+
|
51
|
+
# Loads a wrapped node from the database given a neo id.
|
52
|
+
# @param [#to_i, nil] neo_id
|
53
|
+
# @raise an exception if the loaded node/relationship is not of the same kind as this class.
|
54
|
+
# @return [Object, nil] If the node does not exist it will return nil otherwise the loaded node or wrapped node.
|
55
|
+
def load_entity(neo_id)
|
56
|
+
node = Neo4j::Node.load(neo_id)
|
57
|
+
return nil if node.nil?
|
58
|
+
return node if node.class == Neo4j::Node
|
59
|
+
raise "Expected loaded node #{neo_id} to be of type #{self} but it was #{node.class}" unless node.kind_of?(self)
|
60
|
+
node
|
61
|
+
end
|
62
|
+
|
50
63
|
end
|
51
64
|
end
|
52
65
|
end
|
@@ -129,8 +129,7 @@ module Neo4j
|
|
129
129
|
# @see Neo4j::TypeConverters::DefaultConverter
|
130
130
|
def _converter(prop_name)
|
131
131
|
prop_conf = _decl_props[prop_name.to_sym]
|
132
|
-
Neo4j::TypeConverters::DefaultConverter
|
133
|
-
prop_conf[:converter]
|
132
|
+
(prop_conf && prop_conf[:converter]) || Neo4j::TypeConverters::DefaultConverter
|
134
133
|
end
|
135
134
|
|
136
135
|
# Returns true if the given property name has been defined with the class
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Wrapper
|
3
|
+
module Property
|
4
|
+
module InstanceMethods
|
5
|
+
# Return a hash of 'public' properties.
|
6
|
+
# If there is an accessor method available it will use that.
|
7
|
+
# That means you can override the returned value of the property by implementing a method of the same name
|
8
|
+
# as the property. All properteis not starting with <tt>_</tt> are considered public.
|
9
|
+
# @return [Hash] hash of properties with keys not starting with <tt>_</tt>
|
10
|
+
def attributes
|
11
|
+
attr = props
|
12
|
+
ret = {}
|
13
|
+
attr.each_pair { |k, v| ret[k] = respond_to?(k) ? send(k) : v unless k.to_s[0] == ?_ }
|
14
|
+
ret
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -24,6 +24,19 @@ module Neo4j
|
|
24
24
|
end
|
25
25
|
|
26
26
|
alias_method :create, :new
|
27
|
+
|
28
|
+
# Loads a wrapped relationship from the database given a neo id.
|
29
|
+
# @param [#to_i, nil] neo_id
|
30
|
+
# @raise an exception if the loaded node/relationship is not of the same kind as this class.
|
31
|
+
# @return [Object, nil] If the node does not exist it will return nil otherwise the loaded relationship or wrapped relationship.
|
32
|
+
def load_entity(neo_id)
|
33
|
+
node = Neo4j::Relationship.load(neo_id)
|
34
|
+
return nil if node.nil?
|
35
|
+
return node if node.class == Neo4j::Relationship
|
36
|
+
raise "Expected loaded node #{neo_id} to be of type #{self} but it was #{node.class}" unless node.kind_of?(self)
|
37
|
+
node
|
38
|
+
end
|
39
|
+
|
27
40
|
end
|
28
41
|
end
|
29
42
|
end
|
@@ -7,6 +7,7 @@ module Neo4j
|
|
7
7
|
class Count < Function
|
8
8
|
def initialize
|
9
9
|
@property = '_classname'
|
10
|
+
@@lock ||= Java::java.lang.Object.new
|
10
11
|
end
|
11
12
|
|
12
13
|
def calculate?(changed_property)
|
@@ -31,8 +32,10 @@ module Neo4j
|
|
31
32
|
|
32
33
|
def classes_changed(rule_name, rule_node, class_change)
|
33
34
|
key = rule_node_property(rule_name)
|
34
|
-
|
35
|
-
|
35
|
+
@@lock.synchronized do
|
36
|
+
rule_node[key] ||= 0
|
37
|
+
rule_node[key] += class_change.net_change
|
38
|
+
end
|
36
39
|
end
|
37
40
|
|
38
41
|
def self.function_name
|
@@ -62,6 +62,8 @@ module Neo4j
|
|
62
62
|
|
63
63
|
@rule_nodes = {}
|
64
64
|
|
65
|
+
@lock = Java::java.lang.Object.new
|
66
|
+
|
65
67
|
class << self
|
66
68
|
|
67
69
|
def add(clazz, rule_name, props, &block)
|
@@ -79,7 +81,9 @@ module Neo4j
|
|
79
81
|
|
80
82
|
def rule_node_for(clazz)
|
81
83
|
return nil if clazz.nil?
|
82
|
-
@
|
84
|
+
@lock.synchronized do
|
85
|
+
@rule_nodes[clazz.to_s] ||= RuleNode.new(clazz)
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
def find_rule_node(node)
|
data/lib/neo4j-wrapper.rb
CHANGED
@@ -8,6 +8,8 @@ require 'neo4j-wrapper/node_mixin/class_methods'
|
|
8
8
|
require 'neo4j-wrapper/node_mixin/initialize'
|
9
9
|
|
10
10
|
require 'neo4j-wrapper/properties/class_methods'
|
11
|
+
require 'neo4j-wrapper/properties/instance_methods'
|
12
|
+
|
11
13
|
|
12
14
|
require 'neo4j-wrapper/has_n/class_methods'
|
13
15
|
require 'neo4j-wrapper/has_n/decl_rel'
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: neo4j-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Andreas Ronge
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-04-
|
13
|
+
date: 2012-04-04 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: neo4j-core
|
@@ -37,9 +37,7 @@ extensions: []
|
|
37
37
|
extra_rdoc_files:
|
38
38
|
- README.rdoc
|
39
39
|
files:
|
40
|
-
- lib/test.rb
|
41
40
|
- lib/neo4j-wrapper.rb
|
42
|
-
- lib/example.rb
|
43
41
|
- lib/neo4j-wrapper/find.rb
|
44
42
|
- lib/neo4j-wrapper/wrapper.rb
|
45
43
|
- lib/neo4j-wrapper/class_methods.rb
|
@@ -47,6 +45,7 @@ files:
|
|
47
45
|
- lib/neo4j-wrapper/relationship_mixin/initialize.rb
|
48
46
|
- lib/neo4j-wrapper/relationship_mixin/delegates.rb
|
49
47
|
- lib/neo4j-wrapper/relationship_mixin/class_methods.rb
|
48
|
+
- lib/neo4j-wrapper/properties/instance_methods.rb
|
50
49
|
- lib/neo4j-wrapper/properties/class_methods.rb
|
51
50
|
- lib/neo4j-wrapper/has_n/nodes.rb
|
52
51
|
- lib/neo4j-wrapper/has_n/instance_methods.rb
|
data/lib/example.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'neo4j-wrapper'
|
3
|
-
|
4
|
-
class Company
|
5
|
-
include Neo4j::NodeMixin
|
6
|
-
has_n(:employees)
|
7
|
-
end
|
8
|
-
|
9
|
-
class Person
|
10
|
-
include Neo4j::NodeMixin
|
11
|
-
property :name
|
12
|
-
property :age, :size, :type => Fixnum, :index => :exact
|
13
|
-
property :description, :index => :fulltext
|
14
|
-
|
15
|
-
has_one(:best_friend)
|
16
|
-
has_n(:employed_by).from(:employees)
|
17
|
-
end
|
18
|
-
|
19
|
-
Neo4j::Transaction.run do
|
20
|
-
Person.new(:name => 'jimmy', :age => 35)
|
21
|
-
end
|
22
|
-
|
23
|
-
person = Person.find(:age => (10..42)).first
|
24
|
-
|
25
|
-
Neo4j::Transaction.run do
|
26
|
-
person.best_friend = Person.new
|
27
|
-
person.employed_by << Company.new(:name => "Foo ab")
|
28
|
-
end
|
29
|
-
|
30
|
-
company = person.employed_by.find { |p| p[:name] == 'Foo ab' }
|
31
|
-
puts "Person #{person.name} employed by #{company[:name]}"
|
32
|
-
|
33
|
-
company.employees.each {|x| puts x.name}
|
34
|
-
|
data/lib/test.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
def calc(x)
|
2
|
-
x + 1
|
3
|
-
end
|
4
|
-
|
5
|
-
p = method(:calc)
|
6
|
-
t = Time.now
|
7
|
-
(0..10000).each { |x| calc(x) }
|
8
|
-
total = Time.now - t
|
9
|
-
puts "1. total = #{total}"
|
10
|
-
|
11
|
-
#p = Proc.new {|x| x + 1}
|
12
|
-
t = Time.now
|
13
|
-
(0..10000).each { |x| p.call(x) }
|
14
|
-
total = Time.now - t
|
15
|
-
puts "2. total = #{total}"
|
16
|
-
|
17
|
-
puts "================="
|
18
|
-
t = Time.now
|
19
|
-
(0..10000).each { |x| calc(x) }
|
20
|
-
total = Time.now - t
|
21
|
-
puts "1. total = #{total}"
|
22
|
-
|
23
|
-
t = Time.now
|
24
|
-
(0..10000).each { |x| p.call(x) }
|
25
|
-
total = Time.now - t
|
26
|
-
puts "2. total = #{total}"
|
27
|
-
|
28
|
-
puts "================="
|
29
|
-
t = Time.now
|
30
|
-
(0..10000).each { |x| calc(x) }
|
31
|
-
total = Time.now - t
|
32
|
-
puts "1. total = #{total}"
|
33
|
-
|
34
|
-
t = Time.now
|
35
|
-
(0..10000).each { |x| p.call(x) }
|
36
|
-
total = Time.now - t
|
37
|
-
puts "2. total = #{total}"
|
38
|
-
|
39
|
-
p = method(:calc).to_proc
|
40
|
-
|
41
|
-
puts "================= TO PROC"
|
42
|
-
t = Time.now
|
43
|
-
(0..10000).each { |x| calc(x) }
|
44
|
-
total = Time.now - t
|
45
|
-
puts "1. total = #{total}"
|
46
|
-
|
47
|
-
t = Time.now
|
48
|
-
(0..10000).each { |x| p.call(x) }
|
49
|
-
total = Time.now - t
|
50
|
-
puts "2. total = #{total}"
|
51
|
-
|
52
|
-
puts "================= TO PROC"
|
53
|
-
t = Time.now
|
54
|
-
(0..10000).each { |x| calc(x) }
|
55
|
-
total = Time.now - t
|
56
|
-
puts "1. total = #{total}"
|
57
|
-
|
58
|
-
t = Time.now
|
59
|
-
(0..10000).each { |x| p.call(x) }
|
60
|
-
total = Time.now - t
|
61
|
-
puts "2. total = #{total}"
|