neo4j 1.0.0.beta.27-java → 1.0.0.beta.28-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/CONTRIBUTORS +1 -0
  2. data/lib/neo4j.rb +38 -72
  3. data/lib/neo4j/{algo.rb → algo/algo.rb} +5 -1
  4. data/lib/neo4j/batch/batch.rb +2 -0
  5. data/lib/neo4j/batch/indexer.rb +108 -0
  6. data/lib/neo4j/batch/inserter.rb +168 -0
  7. data/lib/neo4j/database.rb +13 -8
  8. data/lib/neo4j/{mapping/class_methods/list.rb → has_list/class_methods.rb} +2 -4
  9. data/lib/neo4j/has_list/has_list.rb +3 -0
  10. data/lib/neo4j/{mapping/has_list.rb → has_list/mapping.rb} +2 -2
  11. data/lib/neo4j/{mapping/class_methods/relationship.rb → has_n/class_methods.rb} +42 -12
  12. data/lib/neo4j/has_n/decl_relationship_dsl.rb +216 -0
  13. data/lib/neo4j/has_n/has_n.rb +3 -0
  14. data/lib/neo4j/{mapping/has_n.rb → has_n/mapping.rb} +16 -7
  15. data/lib/neo4j/index/index.rb +5 -0
  16. data/lib/neo4j/index/indexer.rb +27 -22
  17. data/lib/neo4j/index/lucene_query.rb +3 -1
  18. data/lib/neo4j/jars/core/neo4j-graph-algo-0.8-1.3.M01.jar +0 -0
  19. data/lib/neo4j/jars/core/neo4j-index-1.3-1.3.M01.jar +0 -0
  20. data/lib/neo4j/jars/core/neo4j-kernel-1.3-1.3.M01.jar +0 -0
  21. data/lib/neo4j/jars/core/neo4j-lucene-index-0.5-1.3.M01.jar +0 -0
  22. data/lib/neo4j/jars/ha/{neo4j-ha-0.6-SNAPSHOT.jar → neo4j-ha-0.6-1.3.M01.jar} +0 -0
  23. data/lib/neo4j/jars/ha/neo4j-management-1.3-1.3.M01.jar +0 -0
  24. data/lib/neo4j/jars/ha/neo4j-shell-1.3-1.3.M01.jar +0 -0
  25. data/lib/neo4j/migrations/class_methods.rb +102 -0
  26. data/lib/neo4j/migrations/extensions.rb +10 -9
  27. data/lib/neo4j/migrations/lazy_node_mixin.rb +50 -0
  28. data/lib/neo4j/migrations/migration.rb +84 -81
  29. data/lib/neo4j/migrations/migrations.rb +6 -100
  30. data/lib/neo4j/migrations/node_mixin.rb +80 -0
  31. data/lib/neo4j/migrations/ref_node_wrapper.rb +32 -0
  32. data/lib/neo4j/neo4j.rb +11 -0
  33. data/lib/neo4j/node.rb +55 -25
  34. data/lib/neo4j/{mapping/class_methods/init_node.rb → node_mixin/class_methods.rb} +3 -3
  35. data/lib/neo4j/{mapping → node_mixin}/node_mixin.rb +35 -18
  36. data/lib/neo4j/{mapping/class_methods/property.rb → property/class_methods.rb} +5 -4
  37. data/lib/neo4j/{property.rb → property/property.rb} +2 -0
  38. data/lib/neo4j/rails/finders.rb +21 -7
  39. data/lib/neo4j/rails/rails.rb +19 -0
  40. data/lib/neo4j/rails/timestamps.rb +1 -1
  41. data/lib/neo4j/relationship.rb +7 -0
  42. data/lib/neo4j/{mapping/class_methods/init_rel.rb → relationship_mixin/class_methods.rb} +4 -4
  43. data/lib/neo4j/{mapping → relationship_mixin}/relationship_mixin.rb +23 -5
  44. data/lib/neo4j/rels/rels.rb +85 -0
  45. data/lib/neo4j/rels/traverser.rb +102 -0
  46. data/lib/neo4j/{mapping/class_methods/rule.rb → rule/class_methods.rb} +11 -11
  47. data/lib/neo4j/rule/functions/count.rb +37 -0
  48. data/lib/neo4j/rule/functions/function.rb +74 -0
  49. data/lib/neo4j/rule/functions/functions.rb +3 -0
  50. data/lib/neo4j/rule/functions/sum.rb +29 -0
  51. data/lib/neo4j/rule/rule.rb +5 -0
  52. data/lib/neo4j/rule/rule_event_listener.rb +162 -0
  53. data/lib/neo4j/rule/rule_node.rb +182 -0
  54. data/lib/neo4j/to_java.rb +0 -14
  55. data/lib/neo4j/traversal/filter_predicate.rb +25 -0
  56. data/lib/neo4j/traversal/prune_evaluator.rb +14 -0
  57. data/lib/neo4j/traversal/rel_expander.rb +31 -0
  58. data/lib/neo4j/traversal/traversal.rb +90 -0
  59. data/lib/neo4j/traversal/traverser.rb +173 -0
  60. data/lib/neo4j/{type_converters.rb → type_converters/type_converters.rb} +0 -0
  61. data/lib/neo4j/version.rb +1 -1
  62. data/lib/test.rb~ +2 -0
  63. data/neo4j.gemspec +11 -10
  64. metadata +48 -37
  65. data/lib/neo4j/functions/count.rb +0 -33
  66. data/lib/neo4j/functions/function.rb +0 -72
  67. data/lib/neo4j/functions/sum.rb +0 -27
  68. data/lib/neo4j/jars/core/neo4j-graph-algo-0.8-SNAPSHOT.jar +0 -0
  69. data/lib/neo4j/jars/core/neo4j-index-1.3-SNAPSHOT.jar +0 -0
  70. data/lib/neo4j/jars/core/neo4j-kernel-1.3-SNAPSHOT.jar +0 -0
  71. data/lib/neo4j/jars/core/neo4j-lucene-index-0.5-SNAPSHOT.jar +0 -0
  72. data/lib/neo4j/jars/ha/neo4j-management-1.3-SNAPSHOT.jar +0 -0
  73. data/lib/neo4j/jars/ha/neo4j-shell-1.3-SNAPSHOT.jar +0 -0
  74. data/lib/neo4j/mapping/decl_relationship_dsl.rb +0 -214
  75. data/lib/neo4j/mapping/rule.rb +0 -158
  76. data/lib/neo4j/mapping/rule_node.rb +0 -176
  77. data/lib/neo4j/migrations.rb +0 -12
  78. data/lib/neo4j/migrations/global_migration.rb +0 -29
  79. data/lib/neo4j/migrations/lazy_migration_mixin.rb +0 -47
  80. data/lib/neo4j/migrations/migration_mixin.rb +0 -78
  81. data/lib/neo4j/node_mixin.rb +0 -4
  82. data/lib/neo4j/node_relationship.rb +0 -161
  83. data/lib/neo4j/node_traverser.rb +0 -224
  84. data/lib/neo4j/relationship_mixin.rb +0 -4
  85. data/lib/neo4j/relationship_traverser.rb +0 -92
@@ -1,176 +0,0 @@
1
- module Neo4j::Mapping
2
-
3
-
4
- class RuleNode
5
- attr_reader :rules
6
-
7
- def initialize(clazz)
8
- @clazz = clazz
9
- @rules = []
10
- end
11
-
12
- def to_s
13
- "RuleNode #{@clazz}, node #{rule_node} #rules: #{@rules.size}"
14
- end
15
-
16
- def node_exist?
17
- !Neo4j.ref_node.rel?(@clazz)
18
- end
19
-
20
- def create_node
21
- Neo4j::Transaction.run do
22
- node = Neo4j::Node.new
23
- Neo4j.ref_node.outgoing(@clazz) << node
24
- node
25
- end
26
- end
27
-
28
- def inherit(subclass)
29
- @rules.each do |rule|
30
- subclass.rule rule.rule_name, rule.props, &rule.filter
31
- end
32
- end
33
-
34
- def delete_node
35
- if Neo4j.ref_node.rel?(@clazz)
36
- Neo4j.ref_node.outgoing(@clazz).each { |n| n.del }
37
- end
38
- clear_rule_node
39
- end
40
-
41
- def find_node
42
- Neo4j.ref_node.rel?(@clazz.to_s) && Neo4j.ref_node._rel(:outgoing, @clazz.to_s)._end_node
43
- end
44
-
45
- def on_neo4j_started
46
- # initialize the rule node when neo4j starts
47
- @rule_node = find_node || create_node
48
- end
49
-
50
- def rule_node
51
- @rule_node ||= find_node || create_node
52
- end
53
-
54
- def rule_node?(node)
55
- @rule_node == node
56
- end
57
-
58
- def clear_rule_node
59
- @rule_node = nil
60
- end
61
-
62
- def rule_names
63
- @rules.map { |r| r.rule_name }
64
- end
65
-
66
- def find_rule(rule_name)
67
- @rules.find { |rule| rule.rule_name == rule_name }
68
- end
69
-
70
- def add_rule(rule_name, props, &block)
71
- @rules << (rule = Rule.new(rule_name, props, &block))
72
- rule
73
- end
74
-
75
- def remove_rule(rule_name)
76
- r = find_rule(rule_name)
77
- r && @rules.delete(r)
78
- end
79
-
80
- # Return a traversal object with methods for each rule and function.
81
- # E.g. Person.all.old or Person.all.sum(:age)
82
- def traversal(rule_name)
83
- # define method on the traversal
84
- traversal = rule_node.outgoing(rule_name)
85
- @rules.each do |rule|
86
- traversal.filter_method(rule.rule_name) do |path|
87
- path.end_node.rel?(rule.rule_name, :incoming)
88
- end
89
- rule.functions && rule.functions.each do |func|
90
- traversal.functions_method(func, self, rule_name)
91
- end
92
- end
93
- traversal
94
- end
95
-
96
- def find_function(rule_name, function_name, function_id)
97
- rule = find_rule(rule_name)
98
- rule.find_function(function_name, function_id)
99
- end
100
-
101
- def execute_rules(node, *changes)
102
- @rules.each do |rule|
103
- execute_rule(rule, node, *changes)
104
- execute_other_rules(rule, node)
105
- end
106
- end
107
-
108
- def execute_other_rules(rule, node)
109
- rule.triggers && rule.triggers.each do |rel_type|
110
- node.incoming(rel_type).each { |n| n.trigger_rules }
111
- end
112
- end
113
-
114
- def execute_rule(rule, node, *changes)
115
- if rule.execute_filter(node)
116
- if connected?(rule.rule_name, node)
117
- # it was already connected - the node is in the same rule group but a property has changed
118
- execute_update_functions(rule, *changes)
119
- else
120
- # the node has changed or is in a new rule group
121
- connect(rule.rule_name, node)
122
- execute_add_functions(rule, *changes)
123
- end
124
- else
125
- if break_connection(rule.rule_name, node)
126
- # the node has been removed from a rule group
127
- execute_delete_functions(rule, *changes)
128
- end
129
- end
130
- end
131
-
132
- def execute_update_functions(rule, *changes)
133
- if functions = find_functions_for_changes(rule, *changes)
134
- functions && functions.each { |f| f.update(rule.rule_name, rule_node, changes[1], changes[2]) }
135
- end
136
- end
137
-
138
- def execute_add_functions(rule, *changes)
139
- if functions = find_functions_for_changes(rule, *changes)
140
- functions && functions.each { |f| f.add(rule.rule_name, rule_node, changes[2]) }
141
- end
142
- end
143
-
144
- def execute_delete_functions(rule, *changes)
145
- if functions = find_functions_for_changes(rule, *changes)
146
- functions.each { |f| f.delete(rule.rule_name, rule_node, changes[1]) }
147
- end
148
- end
149
-
150
- def find_functions_for_changes(rule, *changes)
151
- !changes.empty? && rule.functions_for(changes[0])
152
- end
153
-
154
- # work out if two nodes are connected by a particular relationship
155
- # uses the end_node to start with because it's more likely to have less relationships to go through
156
- # (just the number of superclasses it has really)
157
- def connected?(rule_name, end_node)
158
- end_node.incoming(rule_name).find { |n| n == rule_node }
159
- end
160
-
161
- def connect(rule_name, end_node)
162
- rule_node.outgoing(rule_name) << end_node
163
- end
164
-
165
- # sever a direct one-to-one relationship if it exists
166
- def break_connection(rule_name, end_node)
167
- rel = end_node._rels(:incoming, rule_name).find { |r| r._start_node == rule_node }
168
- rel && rel.del
169
- !rel.nil?
170
- end
171
-
172
- end
173
-
174
-
175
- end
176
-
@@ -1,12 +0,0 @@
1
- require 'neo4j/migrations/extensions'
2
- require 'neo4j/migrations/lazy_migration_mixin'
3
- require 'neo4j/migrations/migration'
4
- require 'neo4j/migrations/migration_mixin'
5
- require 'neo4j/migrations/migrations'
6
- require 'neo4j/migrations/global_migration'
7
-
8
- module Neo4j
9
- module Migrations
10
-
11
- end
12
- end
@@ -1,29 +0,0 @@
1
- module Neo4j
2
-
3
- # This node stores the migrations for Neo4j.migrations
4
- # Uses the Neo4j.ref_node for keeping the current version of the db.
5
- # When the database starts it will check if it needs to run a migration.
6
- class GlobalMigration
7
- extend Neo4j::Migrations
8
-
9
- class << self
10
- def migrate!(version=nil)
11
- _migrate!(self, Neo4j.ref_node, version)
12
- end
13
-
14
- def db_version
15
- Neo4j.ref_node[:_db_version] || 0
16
- end
17
-
18
- # Remote all migration and set migrate_to = nil and set the current version to nil
19
- def reset_migrations!
20
- @migrations = nil
21
- @migrate_to = nil
22
- Neo4j::Transaction.run do
23
- Neo4j.ref_node[:_db_version] = nil
24
- end
25
- end
26
- end
27
- end
28
-
29
- end
@@ -1,47 +0,0 @@
1
- module Neo4j
2
-
3
- # Overrides the init_on_load method so that it will check if any migration is needed.
4
- # The init_on_create method is also overriden so that it sets the version to the latest migration number
5
- # when a new node is created.
6
- #
7
- # Migration will take place if needed when the node is loaded.
8
- #
9
- module LazyMigrationMixin
10
- extend ActiveSupport::Concern
11
-
12
- included do
13
- extend Neo4j::Migrations
14
- end
15
-
16
- module ClassMethods
17
- # Remote all migration and set migrate_to = nil
18
- # Does not change the version of nodes.
19
- def reset_migrations!
20
- @migrations = nil
21
- @migrate_to = nil
22
- end
23
- end
24
-
25
- def migrate!
26
- self.class._migrate!(self._java_node, self)
27
- end
28
-
29
- def init_on_create(*)
30
- super
31
- # set the db version to the current
32
- self[:_db_version] = self.class.migrate_to
33
- end
34
-
35
- def init_on_load(*) # :nodoc:
36
- super
37
- migrate!
38
- # this if for Neo4j::Rails::Model which keeps the properties in this variable
39
- @properties.clear if instance_variable_defined? :@properties
40
- end
41
-
42
- def db_version
43
- self[:_db_version]
44
- end
45
- end
46
-
47
- end
@@ -1,78 +0,0 @@
1
- module Neo4j
2
-
3
-
4
- # By including this mixing on a node class one can add migrations to it.
5
- # Each class has a unique db version.
6
- #
7
- # ==== Example
8
- #
9
- # class Person
10
- # include Neo4j::NodeMixin
11
- # include MigrationMixin
12
- # rule :all # adding the method all to make it possible to find all nodes of this class
13
- # end
14
- #
15
- # Person.migration 1, :split_property do
16
- # up do
17
- # all.each_raw do |node|
18
- # node[:given_name] = node[:name].split[0]
19
- # node[:surname] = node[:name].split[1]
20
- # node[:name] = nil
21
- # end
22
- # end
23
- #
24
- # down do
25
- # all.each_raw do |node|
26
- # node[:name] = "#{node[:given_name]} #{node[:surname]}"
27
- # node[:surename] = nil
28
- # node[:given_name] = nil
29
- # end
30
- # end
31
- # end
32
- #
33
- # Notice that the up and down methods are evaluated in the context of the class (where the all method is defined
34
- # if using the rule :all).
35
- #
36
- module MigrationMixin
37
- extend ActiveSupport::Concern
38
-
39
- included do
40
- extend Neo4j::Migrations
41
- end
42
-
43
- module ClassMethods
44
- def migrate!(version=nil)
45
- _migrate!(self, migration_meta_node, version)
46
- end
47
-
48
- # The node that holds the db version property
49
- def migration_meta_node
50
- Neo4j::Mapping::Rule.rule_node_for(self).rule_node
51
- end
52
-
53
- # Remote all migration and set migrate_to = nil and set the current version to nil
54
- def reset_migrations!
55
- @migrations = nil
56
- @migrate_to = nil
57
- Neo4j::Transaction.run do
58
- migration_meta_node[:_db_version] = nil
59
- end
60
- end
61
-
62
- # sets the migration db version for this class on a 'meta' node.
63
- def db_version=(version)
64
- Neo4j::Transaction.run do
65
- migration_meta_node[:_db_version] = version
66
- end
67
- end
68
-
69
- # returns the current version of the database for this class.
70
- def db_version
71
- migration_meta_node[:_db_version]
72
- end
73
- end
74
-
75
- end
76
-
77
-
78
- end
@@ -1,4 +0,0 @@
1
- module Neo4j
2
- # make an alias so that we don't have to write the long name Neo4j::Mapping::NodeMixin
3
- NodeMixin = Neo4j::Mapping::NodeMixin
4
- end
@@ -1,161 +0,0 @@
1
- module Neo4j
2
-
3
-
4
- module NodeRelationship
5
- include ToJava
6
-
7
-
8
- # A more powerful alternative of #outgoing, #incoming and #both method.
9
- # You can use this method for example to only traverse nodes based on properties on the relationships
10
- #
11
- # ==== Example
12
- #
13
- # some_node.expand { |n| n._rels.find_all { |r| r[:age] > 5 } }.depth(:all).to_a
14
- #
15
- # The above traverse all relationships with a property of age > 5
16
- #
17
- def expand(&expander)
18
- NodeTraverser.new(self).expander(&expander)
19
- end
20
-
21
-
22
- # Returns the outgoing nodes for this node.
23
- #
24
- # ==== Returns
25
- # a Neo4j::NodeTraverser which can be used to further specify which nodes should be included
26
- # in traversal by using the <tt>depth</tt>, <tt>filter</tt> and <tt>prune</tt> methods.
27
- #
28
- # ==== Examples
29
- # # Find all my friends (nodes of depth 1 of type <tt>friends</tt>)
30
- # me.outgoing(:friends).each {|friend| puts friend[:name]}
31
- #
32
- # # Find all my friends and their friends (nodes of depth 1 of type <tt>friends</tt>)
33
- # # me.outgoing(:friends).depth(2).each {|friend| puts friend[:name]}
34
- #
35
- # # Find all my friends and include my self in the result
36
- # me.outgoing(:friends).depth(4).include_start_node.each {...}
37
- #
38
- # # Find all my friends friends friends, etc. at any depth
39
- # me.outgoing(:friends).depth(:all).each {...}
40
- #
41
- # # Find all my friends friends but do not include my friends (only depth == 2)
42
- # me.outgoing(:friends).depth(2).filter{|path| path.length == 2}
43
- #
44
- # # Find all my friends but 'cut off' some parts of the traversal path
45
- # me.outgoing(:friends).depth(42).prune(|path| an_expression_using_path_returning_true_false }
46
- #
47
- # # Find all my friends and work colleges
48
- # me.outgoing(:friends).outgoing(:work).each {...}
49
- #
50
- # Of course all the methods <tt>outgoing</tt>, <tt>incoming</tt>, <tt>both</tt>, <tt>depth</tt>, <tt>include_start_node</tt>, <tt>filter</tt>, and <tt>prune</tt> can be combined.
51
- #
52
- def outgoing(type)
53
- if type
54
- NodeTraverser.new(self).outgoing(type)
55
- else
56
- raise "Not implemented getting all types of outgoing relationship. Specify a relationship type"
57
- end
58
- end
59
-
60
-
61
- # Returns the incoming nodes of given type(s).
62
- #
63
- # See #outgoing
64
- #
65
- def incoming(type)
66
- if type
67
- NodeTraverser.new(self).incoming(type)
68
- else
69
- raise "Not implemented getting all types of incoming relationship. Specify a relationship type"
70
- end
71
- end
72
-
73
- # Returns both incoming and outgoing nodes of given types(s)
74
- #
75
- # If a type is not given then it will return all types of relationships.
76
- #
77
- # See #outgoing
78
- #
79
- def both(type=nil)
80
- if type
81
- NodeTraverser.new(self).both(type)
82
- else
83
- NodeTraverser.new(self) # default is both
84
- end
85
- end
86
-
87
-
88
- # Returns an enumeration of relationship objects.
89
- # It always returns relationship of depth one.
90
- #
91
- # See Neo4j::Relationship
92
- #
93
- # ==== Examples
94
- # # Return both incoming and outgoing relationships
95
- # me.rels(:friends, :work).each {|relationship|...}
96
- #
97
- # # Only return outgoing relationship of given type
98
- # me.rels(:friends).outgoing.first.end_node # => my friend node
99
- #
100
- def rels(*type)
101
- RelationshipTraverser.new(self, type, :both)
102
- end
103
-
104
-
105
- # Returns the only relationship of a given type and direction that is attached to this node, or null.
106
- # This is a convenience method that is used in the commonly occuring situation where a node has exactly zero or
107
- # one relationships of a given type and direction to another node.
108
- # Typically this invariant is maintained by the rest of the code: if at any time more than one such relationships
109
- # exist, it is a fatal error that should generate an unchecked exception. This method reflects that semantics and
110
- # returns either:
111
- #
112
- # * nil if there are zero relationships of the given type and direction,
113
- # * the relationship if there's exactly one, or
114
- # * raise an exception in all other cases.
115
- def rel(dir, type)
116
- result = _rel(dir, type)
117
- result && result.wrapper
118
- end
119
-
120
- # Same as rel but does not return a ruby wrapped object but instead returns the Java object.
121
- def _rel(dir, type)
122
- get_single_relationship(type_to_java(type), dir_to_java(dir))
123
- end
124
-
125
- # Returns the raw java neo4j relationship object.
126
- def _rels(dir=:both, *types)
127
- if types.size > 1
128
- java_types = types.inject([]) { |result, type| result << type_to_java(type) }.to_java(:'org.neo4j.graphdb.RelationshipType')
129
- get_relationships(java_types)
130
- elsif types.size == 1
131
- get_relationships(type_to_java(types[0]), dir_to_java(dir))
132
- elsif dir == :both
133
- get_relationships(dir_to_java(dir))
134
- else
135
- raise "illegal argument, does not accept #{dir} #{types.join(',')} - only dir=:both for any relationship types"
136
- end
137
- end
138
-
139
- # Check if the given relationship exists
140
- # Returns true if there are one or more relationships from this node to other nodes
141
- # with the given relationship.
142
- #
143
- # ==== Parameters
144
- # type:: the key and value to be set, default any type
145
- # dir:: optional default :both (either, :outgoing, :incoming, :both)
146
- #
147
- # ==== Returns
148
- # true if one or more relationships exists for the given type and dir
149
- # otherwise false
150
- #
151
- def rel? (type=nil, dir=:both)
152
- if type
153
- hasRelationship(type_to_java(type), dir_to_java(dir))
154
- else
155
- hasRelationship
156
- end
157
- end
158
-
159
- end
160
-
161
- end