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,224 +0,0 @@
1
- module Neo4j
2
-
3
- class PruneEvaluator # :nodoc:
4
- include org.neo4j.graphdb.traversal.PruneEvaluator
5
- def initialize(proc)
6
- @proc = proc
7
- end
8
-
9
- def prune_after(path)
10
- @proc.call(path)
11
- end
12
- end
13
-
14
- class RelExpander
15
- include org.neo4j.graphdb.RelationshipExpander
16
-
17
- attr_accessor :reversed
18
-
19
- def initialize(&block)
20
- @block = block
21
- @reverse = false
22
- end
23
-
24
- def self.create_pair(&block)
25
- normal = RelExpander.new(&block)
26
- reversed = RelExpander.new(&block)
27
- normal.reversed = reversed
28
- reversed.reversed = normal
29
- reversed.reverse!
30
- normal
31
- end
32
-
33
- def expand(node)
34
- @block.arity == 1 ? @block.call(node) : @block.call(node, @reverse)
35
- end
36
-
37
- def reverse!
38
- @reverse = true
39
- end
40
- end
41
-
42
- class FilterPredicate # :nodoc:
43
- include org.neo4j.helpers.Predicate
44
- def initialize
45
- @procs = []
46
- end
47
-
48
- def add(proc)
49
- @procs << proc
50
- end
51
-
52
- def include_start_node
53
- @include_start_node = true
54
- end
55
-
56
- def accept(path)
57
- return false if @include_start_node && path.length == 0
58
- # find the first filter which returns false
59
- # if not found then we will accept this path
60
- @procs.find {|p| !p.call(path)}.nil?
61
- end
62
- end
63
-
64
-
65
- class NodeTraverser
66
- include Enumerable
67
- include ToJava
68
- include WillPaginate::Finders::Base
69
-
70
-
71
- def initialize(from, type = nil, dir=nil)
72
- @from = from
73
- @depth = 1
74
- if type.nil? || dir.nil?
75
- @td = org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl.new.breadth_first()
76
- else
77
- @type = type_to_java(type)
78
- @dir = dir_to_java(dir)
79
- @td = org.neo4j.kernel.impl.traversal.TraversalDescriptionImpl.new.breadth_first().relationships(@type, @dir)
80
- end
81
- end
82
-
83
-
84
- def to_s
85
- "NodeTraverser [from: #{@from.neo_id} depth: #{@depth} type: #{@type} dir:#{@dir}"
86
- end
87
-
88
-
89
- def wp_query(options, pager, args, &block) #:nodoc:
90
- page = pager.current_page || 1
91
- per_page = pager.per_page
92
- to = per_page * page
93
- from = to - per_page
94
- i = 0
95
- res = []
96
- iterator.each do |node|
97
- res << node.wrapper if i >= from
98
- i += 1
99
- break if i >= to
100
- end
101
- pager.replace res
102
- pager.total_entries ||= count
103
- end
104
-
105
- def <<(other_node)
106
- new(other_node)
107
- self
108
- end
109
-
110
- def new(other_node)
111
- case @dir
112
- when org.neo4j.graphdb.Direction::OUTGOING
113
- @from.create_relationship_to(other_node, @type)
114
- when org.neo4j.graphdb.Direction::INCOMING
115
- other_node._java_node.create_relationship_to(@from, @type)
116
- else
117
- raise "Only allowed to create outgoing or incoming relationships (not #@dir)"
118
- end
119
- end
120
-
121
- def both(type)
122
- @type = type_to_java(type) if type
123
- @dir = dir_to_java(:both)
124
- @td = @td.relationships(type_to_java(type), @dir)
125
- self
126
- end
127
-
128
- def expander(&expander)
129
- @td = @td.expand(RelExpander.create_pair(&expander))
130
- self
131
- end
132
-
133
- def outgoing(type)
134
- @type = type_to_java(type) if type
135
- @dir = dir_to_java(:outgoing)
136
- @td = @td.relationships(type_to_java(type), @dir)
137
- self
138
- end
139
-
140
- def incoming(type)
141
- @type = type_to_java(type) if type
142
- @dir = dir_to_java(:incoming)
143
- @td = @td.relationships(type_to_java(type), @dir)
144
- self
145
- end
146
-
147
- def filter_method(name, &proc)
148
- # add method name
149
- singelton = class << self; self; end
150
- singelton.send(:define_method, name) {filter &proc}
151
- self
152
- end
153
-
154
- def functions_method(func, rule_node, rule_name)
155
- singelton = class << self; self; end
156
- singelton.send(:define_method, func.class.function_name) do |*args|
157
- function_id = args.empty? ? "_classname" : args[0]
158
- function = rule_node.find_function(rule_name, func.class.function_name, function_id)
159
- function.value(rule_node.rule_node, rule_name)
160
- end
161
- self
162
- end
163
-
164
- def prune(&block)
165
- @td = @td.prune(PruneEvaluator.new(block))
166
- self
167
- end
168
-
169
- def filter(&block)
170
- # we keep a reference to filter predicate since only one filter is allowed and we might want to modify it
171
- @filter_predicate ||= FilterPredicate.new
172
- @filter_predicate.add(block)
173
- @td = @td.filter(@filter_predicate)
174
- self
175
- end
176
-
177
- # Sets depth, if :all then it will traverse any depth
178
- def depth(d)
179
- @depth = d
180
- self
181
- end
182
-
183
- def include_start_node
184
- @include_start_node = true
185
- self
186
- end
187
-
188
- def size
189
- [*self].size
190
- end
191
-
192
- alias_method :length, :size
193
-
194
- def [](index)
195
- each_with_index {|node,i| break node if index == i}
196
- end
197
-
198
- def empty?
199
- first == nil
200
- end
201
-
202
- def each
203
- iterator.each {|i| yield i.wrapper}
204
- end
205
-
206
- # Same as #each but does not wrap each node in a Ruby class, yields the Java Neo4j Node instance instead.
207
- def each_raw
208
- iterator.each {|i| yield i}
209
- end
210
-
211
- def iterator
212
- unless @include_start_node
213
- if @filter_predicate
214
- @filter_predicate.include_start_node
215
- else
216
- @td = @td.filter(org.neo4j.kernel.Traversal.return_all_but_start_node)
217
- end
218
- end
219
- @td = @td.prune(org.neo4j.kernel.Traversal.pruneAfterDepth( @depth ) ) unless @depth == :all
220
- @td.traverse(@from).nodes
221
- end
222
- end
223
-
224
- 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::Relationship
3
- RelationshipMixin = Neo4j::Mapping::RelationshipMixin
4
- end
@@ -1,92 +0,0 @@
1
- module Neo4j
2
-
3
- class RelationshipTraverser
4
- include Enumerable
5
- include ToJava
6
-
7
- def initialize(node, types, direction)
8
- @node = node
9
- if types.size > 1
10
- @types = types.inject([]) { |result, type| result << type_to_java(type) }.to_java(:'org.neo4j.graphdb.RelationshipType')
11
- elsif types.size == 1
12
- @type = type_to_java(types[0])
13
- end
14
- @direction = direction
15
- end
16
-
17
- def to_s
18
- if @type
19
- "#{self.class} [type: #{@type} dir:#{@direction}]"
20
- elsif @types
21
- "#{self.class} [types: #{@types.join(',')} dir:#{@direction}]"
22
- else
23
- "#{self.class} [types: ANY dir:#{@direction}]"
24
- end
25
- end
26
-
27
- def each
28
- iter = iterator
29
- while (iter.hasNext())
30
- rel = iter.next
31
- yield rel.wrapper if match_to_other?(rel)
32
- end
33
- end
34
-
35
- def empty?
36
- first == nil
37
- end
38
-
39
- def iterator
40
- if @types
41
- @node.get_relationships(@types).iterator
42
- elsif @type
43
- @node.get_relationships(@type, dir_to_java(@direction))
44
- else
45
- @node.get_relationships(dir_to_java(@direction))
46
- end
47
- end
48
-
49
- def match_to_other?(rel)
50
- if @to_other.nil?
51
- true
52
- elsif @direction == :outgoing
53
- rel._end_node == @to_other
54
- elsif @direction == :incoming
55
- rel._start_node == @to_other
56
- else
57
- rel._start_node == @to_other || rel._end_node == @to_other
58
- end
59
- end
60
-
61
- def to_other(to_other)
62
- @to_other = to_other
63
- self
64
- end
65
-
66
- def del
67
- each { |rel| rel.del }
68
- end
69
-
70
- def size
71
- [*self].size
72
- end
73
-
74
- def both
75
- @direction = :both
76
- self
77
- end
78
-
79
- def incoming
80
- raise "Not allowed calling incoming when finding several relationships types" if @types
81
- @direction = :incoming
82
- self
83
- end
84
-
85
- def outgoing
86
- raise "Not allowed calling outgoing when finding several relationships types" if @types
87
- @direction = :outgoing
88
- self
89
- end
90
-
91
- end
92
- end