neo4j 1.0.0.beta.24-java → 1.0.0.beta.25-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/lib/generators/neo4j.rb +1 -1
  2. data/lib/generators/neo4j/model/model_generator.rb +1 -1
  3. data/lib/neo4j.rb +5 -3
  4. data/lib/neo4j/algo.rb +290 -0
  5. data/lib/neo4j/database.rb +19 -12
  6. data/lib/neo4j/jars/neo4j-graph-algo-0.7-1.2.jar +0 -0
  7. data/lib/neo4j/jars/{neo4j-index-1.2-1.2.M04.jar → neo4j-index-1.2-1.2.jar} +0 -0
  8. data/lib/neo4j/jars/{neo4j-kernel-1.2-1.2.M04.jar → neo4j-kernel-1.2-1.2.jar} +0 -0
  9. data/lib/neo4j/jars/neo4j-lucene-index-0.2-1.2.jar +0 -0
  10. data/lib/neo4j/mapping/class_methods/relationship.rb +1 -1
  11. data/lib/neo4j/node.rb +9 -9
  12. data/lib/neo4j/node_relationship.rb +14 -0
  13. data/lib/neo4j/node_traverser.rb +33 -0
  14. data/lib/neo4j/rails/attributes.rb +8 -8
  15. data/lib/neo4j/rails/relationships/mapper.rb +25 -18
  16. data/lib/neo4j/rails/relationships/relationships.rb +9 -9
  17. data/lib/neo4j/relationship.rb +4 -8
  18. data/lib/neo4j/to_java.rb +13 -0
  19. data/lib/neo4j/version.rb +1 -1
  20. data/lib/tmp/neo4j/index.db +0 -0
  21. data/lib/tmp/neo4j/index/lucene-store.db +0 -0
  22. data/lib/tmp/neo4j/index/lucene/node/Network-exact/_0.cfs +0 -0
  23. data/lib/tmp/neo4j/index/lucene/node/Network-exact/segments.gen +0 -0
  24. data/lib/tmp/neo4j/index/lucene/node/Network-exact/segments_2 +0 -0
  25. data/lib/tmp/neo4j/lucene-fulltext/lucene-store.db +0 -0
  26. data/lib/tmp/neo4j/lucene/lucene-store.db +0 -0
  27. data/lib/tmp/neo4j/messages.log +43 -43
  28. data/lib/tmp/neo4j/neostore +0 -0
  29. data/lib/tmp/neo4j/neostore.nodestore.db +0 -0
  30. data/lib/tmp/neo4j/neostore.nodestore.db.id +0 -0
  31. data/lib/tmp/neo4j/neostore.propertystore.db +0 -0
  32. data/lib/tmp/neo4j/neostore.propertystore.db.id +0 -0
  33. data/lib/tmp/neo4j/neostore.propertystore.db.strings +0 -0
  34. data/lib/tmp/neo4j/neostore.propertystore.db.strings.id +0 -0
  35. data/lib/tmp/neo4j/neostore.relationshipstore.db +0 -0
  36. data/lib/tmp/neo4j/neostore.relationshipstore.db.id +0 -0
  37. data/lib/tmp/neo4j/neostore.relationshiptypestore.db +0 -0
  38. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.id +0 -0
  39. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.names +0 -0
  40. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.names.id +0 -0
  41. data/lib/tmp/neo4j/tm_tx_log.1 +0 -0
  42. metadata +12 -6
  43. data/lib/neo4j/jars/neo4j-lucene-index-0.2-1.2.M04.jar +0 -0
@@ -2,7 +2,7 @@ require 'rails/generators/named_base'
2
2
  require 'rails/generators/active_model'
3
3
 
4
4
  module Neo4j
5
- module Generators
5
+ module Generators #:nodoc:
6
6
  end
7
7
  end
8
8
 
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '..', 'neo4j.rb')
2
2
 
3
- class Neo4j::Generators::ModelGenerator < Neo4j::Generators::Base
3
+ class Neo4j::Generators::ModelGenerator < Neo4j::Generators::Base #:nodoc:
4
4
  argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
5
5
 
6
6
  check_class_collision
@@ -5,11 +5,12 @@ require 'forwardable'
5
5
  require 'time'
6
6
  require 'date'
7
7
 
8
- require 'neo4j/jars/neo4j-index-1.2-1.2.M04.jar'
9
- require 'neo4j/jars/neo4j-kernel-1.2-1.2.M04.jar'
10
- require 'neo4j/jars/neo4j-lucene-index-0.2-1.2.M04.jar'
8
+ require 'neo4j/jars/neo4j-index-1.2-1.2.jar'
9
+ require 'neo4j/jars/neo4j-kernel-1.2-1.2.jar'
10
+ require 'neo4j/jars/neo4j-lucene-index-0.2-1.2.jar'
11
11
  require 'neo4j/jars/geronimo-jta_1.1_spec-1.1.1.jar'
12
12
  require 'neo4j/jars/lucene-core-3.0.2.jar'
13
+ require 'neo4j/jars/neo4j-graph-algo-0.7-1.2'
13
14
 
14
15
  require 'will_paginate/collection'
15
16
  require 'will_paginate/finders/base'
@@ -56,6 +57,7 @@ require 'neo4j/mapping/rule_node'
56
57
  require 'neo4j/node_mixin'
57
58
  require 'neo4j/relationship_mixin'
58
59
  require 'neo4j/mapping/class_methods/rule'
60
+ require 'neo4j/algo'
59
61
 
60
62
  # rails
61
63
  require 'rails/railtie'
@@ -0,0 +1,290 @@
1
+ module Neo4j
2
+
3
+
4
+ class Algo
5
+ include Enumerable
6
+ include ToJava
7
+
8
+ class EstimateEvaluator #:nodoc
9
+ include org.neo4j.graphalgo.EstimateEvaluator
10
+ include ToJava
11
+
12
+ def initialize(&evaluator)
13
+ @evaluator = evaluator
14
+ end
15
+
16
+ # Implements T getCost(Node node, Node goal)
17
+ # Estimate the weight of the remaining path from one node to another.
18
+ def get_cost(node, goal)
19
+ @evaluator.call(node, goal)
20
+ end
21
+ end
22
+
23
+ class CostEvaluator #:nodoc
24
+ include org.neo4j.graphalgo.CostEvaluator
25
+ include ToJava
26
+
27
+ def initialize(&evaluator)
28
+ @evaluator = evaluator
29
+ end
30
+
31
+ # Implements the Java Method: T getCost(Relationship relationship, Direction direction)
32
+ # From the JavaDoc: <pre>
33
+ # This is the general method for looking up costs for relationships.
34
+ # This can do anything, like looking up a property or running some small calculation.
35
+ # Parameters:
36
+ # relationship -
37
+ # direction - The direction in which the relationship is being evaluated, either Direction.INCOMING or Direction.OUTGOING.
38
+ # Returns:
39
+ # The cost for this edge/relationship
40
+ # </pre>
41
+ def get_cost(relationship, direction)
42
+ @evaluator.call(relationship, dir_from_java(direction))
43
+ end
44
+ end
45
+
46
+ def initialize(from, to, &factory_proc) #:nodoc:
47
+ @from = from
48
+ @to = to
49
+ @factory_proc = factory_proc
50
+ @type_and_dirs = []
51
+
52
+ end
53
+
54
+ def _depth #:nodoc:
55
+ @depth || java.lang.Integer::MAX_VALUE
56
+ end
57
+
58
+ def _expander #:nodoc:
59
+ expander = @expander
60
+ expander ||= @type_and_dirs.empty? ? org.neo4j.kernel.Traversal.expanderForAllTypes() : org.neo4j.kernel.Traversal.expanderForTypes(*@type_and_dirs)
61
+ expander
62
+ end
63
+
64
+ def _cost_evaluator #:nodoc:
65
+ raise "Algorithm requeries a cost evalulator, use the cost_evaluator to provide one" unless @cost_evaluator
66
+ @cost_evaluator
67
+ end
68
+
69
+ def _estimate_evaluator #:nodoc:
70
+ raise "Algorithm requeries a estimate evaluator, use the estimate_evaluator to provide one" unless @estimate_evaluator
71
+ @estimate_evaluator
72
+ end
73
+
74
+ # Specifies which outgoing relationship should be traversed for the graph algorithm
75
+ #
76
+ # ==== Parameters
77
+ # * rel :: relationship type (symbol)
78
+ def outgoing(rel)
79
+ @type_and_dirs << type_to_java(rel)
80
+ @type_and_dirs << dir_to_java(:outgoing)
81
+ self
82
+ end
83
+
84
+ # Specifies which incoming relationship should be traversed for the graph algorithm
85
+ #
86
+ # ==== Parameters
87
+ # * rel :: relationship type (symbol)
88
+ def incoming(rel)
89
+ @type_and_dirs << type_to_java(rel)
90
+ @type_and_dirs << dir_to_java(:incoming)
91
+ self
92
+ end
93
+
94
+ # Specifies which relationship should be traversed for the graph algorithm
95
+ #
96
+ # ==== Example
97
+ # The following:
98
+ #
99
+ # Neo4j::Algo.shortest_path(@x,@y).expand{|node| node._rels(:outgoing, :friends)}
100
+ #
101
+ # Is the same as
102
+ # Neo4j::Algo.shortest_path(@x,@y).outgoing(:friends)
103
+ #
104
+ # ==== Parameters
105
+ # * expander_proc :: a proc relationship type (symbol)
106
+ def expand(&expander_proc)
107
+ @expander = (RelExpander.create_pair(&expander_proc))
108
+ self
109
+ end
110
+
111
+ # If only a single path should be returned,
112
+ # default for some algorithms, like shortest_path
113
+ def single
114
+ @single = true
115
+ self
116
+ end
117
+
118
+ # See #single
119
+ # Not sure if this method is useful
120
+ def many
121
+ @single = false
122
+ end
123
+
124
+ # The depth of the traversal
125
+ # Notice not all algorithm uses this argument (aStar and dijkstra)
126
+ def depth(depth)
127
+ @depth = depth
128
+ self
129
+ end
130
+
131
+ # Specifies a cost evaluator for the algorithm.
132
+ # Only available for the aStar and dijkstra algorithms.
133
+ #
134
+ # ==== Example
135
+ # Neo4j::Algo.dijkstra(@x,@y).cost_evaluator{|rel,*| rel[:weight]}
136
+ #
137
+ def cost_evaluator(&cost_evaluator_proc)
138
+ @cost_evaluator = CostEvaluator.new(&cost_evaluator_proc)
139
+ self
140
+ end
141
+
142
+ # Specifies an evaluator that returns an (optimistic) estimation of the cost to get from the current node (in the traversal) to the end node.
143
+ # Only available for the aStar algorithm.
144
+ #
145
+ # The provided proc estimate the weight of the remaining path from one node to another.
146
+ # The proc takes two parameters:
147
+ # * node :: the node to estimate the weight from.
148
+ # * goal :: the node to estimate the weight to.
149
+ #
150
+ # The proc should return an estimation of the weight of the path from the first node to the second.
151
+ #
152
+ # ==== Example
153
+ #
154
+ # Neo4j::Algo.a_star(@x,@y).cost_evaluator{...}.estimate_evaluator{|node,goal| some calucalation retuning a Float}
155
+ #
156
+ def estimate_evaluator(&estimate_evaluator_proc)
157
+ @estimate_evaluator = EstimateEvaluator.new(&estimate_evaluator_proc)
158
+ self
159
+ end
160
+
161
+ # Specifies that nodes should be returned from as result (this is default)
162
+ # See also #rels
163
+ def nodes
164
+ @path_finder_method = :nodes
165
+ self
166
+ end
167
+
168
+ # Specifies that relationships should be returned from as result (this is default)
169
+ # See also #nodes
170
+ #
171
+ def rels
172
+ @path_finder_method = :relationships
173
+ self
174
+ end
175
+
176
+
177
+ # So that one can call directly method on the PathFinder result from an executed algorithm.
178
+ def method_missing(m, *args, &block)
179
+ execute_algo.send(m, *args)
180
+ end
181
+
182
+ def each(&block) #:nodoc:
183
+ if @single
184
+ execute_algo.send(@path_finder_method || :nodes).each &block
185
+ else
186
+ execute_algo.each &block
187
+ end
188
+ end
189
+
190
+ def execute_algo #:nodoc:
191
+ instance = self.instance_eval(&@factory_proc)
192
+ if @single
193
+ instance.find_single_path(@from._java_node, @to._java_node)
194
+ else
195
+ instance.find_all_paths(@from._java_node, @to._java_node)
196
+ end
197
+ end
198
+
199
+ # Returns an instance of Neo4j::Algo which can find all available paths between two nodes.
200
+ # These returned paths can contain loops (i.e. a node can occur more than once in any returned path).
201
+ def self.all_paths(from, to)
202
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.all_paths(_expander, _depth) }
203
+ end
204
+
205
+ # See #all_paths, returns the first path found
206
+ def self.all_path(from, to)
207
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.all_paths(_expander, _depth) }.single
208
+ end
209
+
210
+ # Returns an instance of Neo4j::Algo which can find all simple paths between two nodes.
211
+ # These returned paths cannot contain loops (i.e. a node cannot occur more than once in any returned path).
212
+ def self.all_simple_paths(from, to)
213
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.all_simple_paths(_expander, _depth) }
214
+ end
215
+
216
+ # See #all_simple_paths, returns the first path found
217
+ def self.all_simple_path(from, to)
218
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.all_simple_paths(_expander, _depth) }.single
219
+ end
220
+
221
+ # Returns an instance of Neo4j::Algo which can find all shortest paths (that is paths with as short Path.length() as possible) between two nodes.
222
+ # These returned paths cannot contain loops (i.e. a node cannot occur more than once in any returned path).
223
+ def self.shortest_paths(from, to)
224
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.shortest_path(_expander, _depth) }
225
+ end
226
+
227
+ # See #shortest_paths, returns the first path found
228
+ def self.shortest_path(from, to)
229
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.shortest_path(_expander, _depth) }.single
230
+ end
231
+
232
+ # Returns an instance of Neo4j::Algo which uses the Dijkstra algorithm to find the cheapest path between two nodes.
233
+ # The definition of "cheap" is the lowest possible cost to get from the start node to the end node, where the cost is returned from costEvaluator.
234
+ # These returned paths cannot contain loops (i.e. a node cannot occur more than once in any returned path).
235
+ # See http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm for more information.
236
+ #
237
+ # Example
238
+ #
239
+ # Neo4j::Algo.dijkstra_path(node_a,node_b).cost_evaluator{|rel,*| rel[:weight]}.rels
240
+ #
241
+ def self.dijkstra_paths(from, to)
242
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.dijkstra(_expander, _cost_evaluator) }
243
+ end
244
+
245
+ # See #dijkstra_paths, returns the first path found
246
+ #
247
+ def self.dijkstra_path(from, to)
248
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.dijkstra(_expander, _cost_evaluator) }.single
249
+ end
250
+
251
+ # Returns an instance of Neo4j::Algo which uses the A* algorithm to find the cheapest path between two nodes.
252
+ # The definition of "cheap" is the lowest possible cost to get from the start node to the end node, where the cost is returned from lengthEvaluator and estimateEvaluator. These returned paths cannot contain loops (i.e. a node cannot occur more than once in any returned path).
253
+ # See http://en.wikipedia.org/wiki/A*_search_algorithm for more information.
254
+ #
255
+ # Expacts an cost evaluator and estimate evaluator, see Algo#cost_evaluator and Algo#estimate_evaluator
256
+ #
257
+ # Example:
258
+ #
259
+ # Neo4j::Algo.a_star_path(@x,@y).cost_evaluator{|rel,*| rel[:weight]}.estimate_evaluator{|node,goal| returns a float value}
260
+ #
261
+ def self.a_star_paths(from, to)
262
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.a_star(_expander, _cost_evaluator, _estimate_evaluator) }
263
+ end
264
+
265
+ # See #a_star_paths, returns the first path found
266
+ #
267
+ def self.a_star_path(from, to)
268
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.a_star(_expander, _cost_evaluator, _estimate_evaluator) }.single
269
+ end
270
+
271
+ # Returns an instance of Neo4j::Algo can find all paths of a certain length(depth) between two nodes.
272
+ # These returned paths cannot contain loops (i.e. a node cannot occur more than once in any returned path).
273
+ # Expects setting the depth parameter (the lenghto of the path) by the Algo#depth method.
274
+ #
275
+ # Example:
276
+ #
277
+ # Neo4j::Algo.with_length_paths(node_a,node_b).depth(2).each {|x| puts "Node #{x}"}
278
+ #
279
+ def self.with_length_paths(from,to)
280
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.paths_with_length(_expander, _depth) }
281
+ end
282
+
283
+ # See #with_length_paths, returns the first path found
284
+ #
285
+ def self.with_length_path(from,to)
286
+ Algo.new(from, to) { org.neo4j.graphalgo.GraphAlgoFactory.paths_with_length(_expander, _depth) }.single
287
+ end
288
+
289
+ end
290
+ end
@@ -1,15 +1,19 @@
1
- require 'drb'
2
- require 'socket'
3
-
4
1
  module Neo4j
5
- class Database #:nodoc:
2
+ # Wraps both Java Neo4j GraphDatabaseService and Lucene.
3
+ # You can access the raw java neo4j and lucene db's with the <tt>graph</tt> and <tt>lucene</tt>
4
+ # properties.
5
+ #
6
+ # This class is also responsible for checking if there is already a running neo4j database.
7
+ # If one tries to start an already started database then a read only instance to neo4j will be used.
8
+ #
9
+ class Database
6
10
  attr_reader :graph, :lucene, :event_handler
7
11
 
8
12
  def initialize()
9
13
  @event_handler = EventHandler.new
10
14
  end
11
15
 
12
- def start
16
+ def start #:nodoc:
13
17
  return if running?
14
18
  @running = true
15
19
 
@@ -22,26 +26,29 @@ module Neo4j
22
26
  at_exit { shutdown }
23
27
  end
24
28
 
25
- def start_readonly_graph_db
29
+ def start_readonly_graph_db #:nodoc:
26
30
  puts "Starting Neo4j in readonly mode since the #{Config[:storage_path]} is locked"
27
31
  @graph = org.neo4j.kernel.EmbeddedReadOnlyGraphDatabase.new(Config[:storage_path])
28
32
  end
29
33
 
30
- def start_local_graph_db
34
+ def start_local_graph_db #:nodoc:
31
35
  @graph = org.neo4j.kernel.EmbeddedGraphDatabase.new(Config[:storage_path])
32
36
  @graph.register_transaction_event_handler(@event_handler)
33
37
  @lucene = @graph.index #org.neo4j.index.impl.lucene.LuceneIndexProvider.new
34
38
  @event_handler.neo4j_started(self)
35
39
  end
36
40
 
37
- def running?
41
+ def running? #:nodoc:
38
42
  @running
39
43
  end
40
44
 
45
+ # Returns true if the neo4j db was started in read only mode.
46
+ # This can occur if the database was locked (it was already one instance running).
41
47
  def read_only?
42
48
  @graph.isReadOnly
43
49
  end
44
50
 
51
+ # check if the database is locked. A neo4j database is locked when there is running.
45
52
  def self.locked?
46
53
  lock_file = File.join(::Neo4j::Config[:storage_path], 'neostore')
47
54
  return false unless File.exist?(lock_file)
@@ -55,7 +62,7 @@ module Neo4j
55
62
  end
56
63
  end
57
64
 
58
- def shutdown
65
+ def shutdown #:nodoc:
59
66
  if @running
60
67
  @graph.unregister_transaction_event_handler(@event_handler) unless read_only?
61
68
  @event_handler.neo4j_shutdown(self)
@@ -67,19 +74,19 @@ module Neo4j
67
74
 
68
75
  end
69
76
 
70
- def begin_tx
77
+ def begin_tx #:nodoc:
71
78
  @graph.begin_tx
72
79
  end
73
80
 
74
81
 
75
- def each_node
82
+ def each_node #:nodoc:
76
83
  iter = @graph.all_nodes.iterator
77
84
  while (iter.hasNext)
78
85
  yield iter.next.wrapper
79
86
  end
80
87
  end
81
88
 
82
- def _each_node
89
+ def _each_node #:nodoc:
83
90
  iter = @graph.all_nodes.iterator
84
91
  while (iter.hasNext)
85
92
  yield iter.next
@@ -33,7 +33,7 @@ module Neo4j::Mapping
33
33
 
34
34
  module_eval(%Q{
35
35
  def #{rel_type}_rels
36
- dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
36
+ dsl = _decl_rels_for('#{rel_type}'.to_sym)
37
37
  dsl.all_relationships(self)
38
38
  end}, __FILE__, __LINE__)
39
39
 
@@ -8,20 +8,20 @@ module Neo4j
8
8
  include Neo4j::Equal
9
9
  include Neo4j::Index
10
10
 
11
- # Delete the node and all its relationship
11
+ # Delete the node and all its relationship.
12
+ #
13
+ # It might raise an exception if this method was called without a Transaction,
14
+ # or if it failed to delete the node (it maybe was already deleted).
15
+ #
16
+ # If this method raise an exception you may also get an exception when the transaction finish.
12
17
  #
13
18
  # ==== Returns
14
- # true :: if the node was deleted
15
- # false :: if node was not deleted, maybe it has already been deleted
19
+ # nil or raise an exception
16
20
  #
17
21
  def del
18
22
  rels.each {|r| r.del}
19
- begin
20
- delete
21
- true
22
- rescue
23
- false
24
- end
23
+ delete
24
+ nil
25
25
  end
26
26
 
27
27
  # returns true if the node exists in the database
@@ -5,6 +5,20 @@ module Neo4j
5
5
  include ToJava
6
6
 
7
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
+
8
22
  # Returns the outgoing nodes for this node.
9
23
  #
10
24
  # ==== Returns
@@ -11,6 +11,34 @@ module Neo4j
11
11
  end
12
12
  end
13
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
+
14
42
  class FilterPredicate # :nodoc:
15
43
  include org.neo4j.helpers.Predicate
16
44
  def initialize
@@ -97,6 +125,11 @@ module Neo4j
97
125
  self
98
126
  end
99
127
 
128
+ def expander(&expander)
129
+ @td = @td.expand(RelExpander.create_pair(&expander))
130
+ self
131
+ end
132
+
100
133
  def outgoing(type)
101
134
  @type = type_to_java(type) if type
102
135
  @dir = dir_to_java(:outgoing)
@@ -1,13 +1,13 @@
1
- # This module handles the getting, setting and updating of attributes or properties
2
- # in a Railsy way. This typically means not writing anything to the DB until the
3
- # object is saved (after validation).
4
- #
5
- # Externally, when we talk about properties (e.g. #property?, #property_names, #properties),
6
- # we mean all of the stored properties for this object include the 'hidden' props
7
- # with underscores at the beginning such as _neo_id and _classname. When we talk
8
- # about attributes, we mean all the properties apart from those hidden ones.
9
1
  module Neo4j
10
2
  module Rails
3
+ # This module handles the getting, setting and updating of attributes or properties
4
+ # in a Railsy way. This typically means not writing anything to the DB until the
5
+ # object is saved (after validation).
6
+ #
7
+ # Externally, when we talk about properties (e.g. #property?, #property_names, #properties),
8
+ # we mean all of the stored properties for this object include the 'hidden' props
9
+ # with underscores at the beginning such as _neo_id and _classname. When we talk
10
+ # about attributes, we mean all the properties apart from those hidden ones.
11
11
  module Attributes
12
12
  extend ActiveSupport::Concern
13
13
 
@@ -2,11 +2,14 @@ module Neo4j
2
2
  module Rails
3
3
  module Relationships
4
4
 
5
- class Mapper
6
- def initialize(rel_type, dsl=nil)
5
+ class Mapper #:nodoc:
6
+ attr_reader :dsl
7
+
8
+ def initialize(rel_type, dsl, node)
7
9
  @rel_type = rel_type
8
10
  @relationships = []
9
11
  @dsl = dsl
12
+ @node = node
10
13
  end
11
14
 
12
15
  def rel_type
@@ -17,41 +20,45 @@ module Neo4j
17
20
  (@dsl && @dsl.direction) || :outgoing
18
21
  end
19
22
 
20
- def to_s
23
+ def to_s #:nodoc:
21
24
  "#{self.class} #{object_id} dir: #{direction} rel_type: #{@rel_type} wrapped #{@dsl}"
22
25
  end
23
26
 
24
27
  def single_relationship(*)
25
- @relationships.first
28
+ use_persisted_rels? ? @dsl.single_relationship(@node) : @relationships.first
26
29
  end
27
30
 
28
- def each(&block)
29
- # TODO direction
30
- # TODO DRY
31
- @relationships.each do |rel|
32
- block.call rel.end_node
31
+ def all_relationships(*)
32
+ if use_persisted_rels?
33
+ @dsl.all_relationships(@node)
34
+ else
35
+ @relationships
33
36
  end
34
- @dsl.each(&block) if @dsl
35
37
  end
36
38
 
37
- def each_node(node, direction, &block) #:nodoc:
38
- # TODO direction
39
- @relationships.each do |rel|
40
- block.call rel.end_node
39
+ def each_node(node, direction, &block)
40
+ if use_persisted_rels?
41
+ @dsl.each_node(node, direction, &block)
42
+ else
43
+ # TODO direction
44
+ @relationships.each do |rel|
45
+ block.call rel.end_node
46
+ end
41
47
  end
42
- @dsl.each_node(node, direction, &block) if @dsl && node.persisted?
48
+ end
49
+
50
+ def use_persisted_rels?
51
+ @relationships.empty? && @node.persisted?
43
52
  end
44
53
 
45
54
  def del_rel(rel)
46
- # TODO, we need to delete this when it is saved
47
55
  @relationships.delete(rel)
48
56
  end
49
57
 
50
58
  def create_relationship_to(from, to)
51
- #rel_type = (@dsl && @dsl.rel_type) || @rel_type
52
- #from, to = (@dsl && @dsl.incoming?) ? [to, from] : [from, to]
53
59
  @relationships << Relationship.new(@rel_type, from, to, self)
54
60
  end
61
+
55
62
 
56
63
  def single_node(from)
57
64
  if !@relationships.empty?
@@ -13,11 +13,15 @@ module Neo4j
13
13
 
14
14
  def <<(other)
15
15
  @mapper.create_relationship_to(@from_node, other)
16
+ self
17
+ end
18
+
19
+ def size
20
+ @mapper.dsl.all_relationships(@from_node).size
16
21
  end
17
22
 
18
23
  def each(&block)
19
- # TODO Direction
20
- @mapper.each &block
24
+ @mapper.each_node(@from_node, :outgoing, &block)
21
25
  end
22
26
  end
23
27
 
@@ -37,7 +41,7 @@ module Neo4j
37
41
  if false && persisted?
38
42
  dsl
39
43
  else
40
- @relationships[type] ||= Mapper.new(type, dsl)
44
+ @relationships[type] ||= Mapper.new(type, dsl, self)
41
45
  end
42
46
  end
43
47
 
@@ -51,12 +55,8 @@ module Neo4j
51
55
  # Creates or traverse relationships in memory without communicating with the neo4j database.
52
56
  #
53
57
  def outgoing(rel_type)
54
- if persisted?
55
- super
56
- else
57
- @relationships[rel_type] ||= Mapper.new(rel_type)
58
- OutgoingRelationship.new(self, @relationships[rel_type])
59
- end
58
+ dsl = _decl_rels_for(rel_type)
59
+ OutgoingRelationship.new(self, dsl)
60
60
  end
61
61
  end
62
62
  end
@@ -11,17 +11,13 @@ module Neo4j
11
11
 
12
12
  # Deletes the relationship between the start and end node
13
13
  #
14
+ # May raise an exception if delete was unsuccessful.
15
+ #
14
16
  # ==== Returns
15
- # true :: if the relationship was deleted
16
- # false :: if relationship was NOT deleted, maybe it has already been deleted
17
+ # nil
17
18
  #
18
19
  def del
19
- begin
20
- delete
21
- true
22
- rescue
23
- false
24
- end
20
+ delete
25
21
  end
26
22
 
27
23
  def end_node # :nodoc:
@@ -5,6 +5,19 @@ module Neo4j
5
5
  org.neo4j.graphdb.DynamicRelationshipType.withName(type.to_s)
6
6
  end
7
7
 
8
+ def type_from_java(type)
9
+ type.get_type
10
+ end
11
+
12
+ def dir_from_java(dir)
13
+ case dir
14
+ when org.neo4j.graphdb.Direction::OUTGOING then :outgoing
15
+ when org.neo4j.graphdb.Direction::BOTH then :both
16
+ when org.neo4j.graphdb.Direction::INCOMING then :incoming
17
+ else raise "unknown direction '#{dir} / #{dir.class}'"
18
+ end
19
+ end
20
+
8
21
  def dir_to_java(dir)
9
22
  case dir
10
23
  when :outgoing then org.neo4j.graphdb.Direction::OUTGOING
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "1.0.0.beta.24"
2
+ VERSION = "1.0.0.beta.25"
3
3
  end
Binary file
@@ -1,43 +1,43 @@
1
- Wed Dec 15 10:16:02 CET 2010: Creating new db @ tmp/neo4j/neostore
2
- Wed Dec 15 10:16:02 CET 2010: Opened [tmp/neo4j/nioneo_logical.log.1] clean empty log, version=0
3
- Wed Dec 15 10:16:02 CET 2010: Opened [tmp/neo4j/lucene/lucene.log.1] clean empty log, version=0
4
- Wed Dec 15 10:16:02 CET 2010: Opened [tmp/neo4j/lucene-fulltext/lucene.log.1] clean empty log, version=0
5
- Wed Dec 15 10:16:02 CET 2010: Opened [/home/andreas/projects/neo4j/lib/tmp/neo4j/index/lucene.log.1] clean empty log, version=0
6
- Wed Dec 15 10:16:02 CET 2010: Extension org.neo4j.graphdb.index.IndexProvider[lucene] initialized ok
7
- Wed Dec 15 10:16:02 CET 2010: TM new log: tm_tx_log.1
8
- Wed Dec 15 10:16:02 CET 2010: --- CONFIGURATION START ---
9
- Wed Dec 15 10:16:02 CET 2010: Physical mem: 4017MB, Heap size: 483MB
10
- Wed Dec 15 10:16:02 CET 2010: Kernel version: Neo4j - Graph Database Kernel 1.2-1.2.M04
11
- Wed Dec 15 10:16:02 CET 2010: Operating System: Linux; version: 2.6.32-26-generic-pae; arch: i386
12
- Wed Dec 15 10:16:02 CET 2010: VM Name: Java HotSpot(TM) Client VM
13
- Wed Dec 15 10:16:02 CET 2010: VM Vendor: Sun Microsystems Inc.
14
- Wed Dec 15 10:16:02 CET 2010: VM Version: 17.1-b03
15
- Wed Dec 15 10:16:02 CET 2010: Boot Class Path: /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/resources.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/rt.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/jsse.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/jce.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/charsets.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/classes:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/jruby.jar
16
- Wed Dec 15 10:16:02 CET 2010: Class Path: :
17
- Wed Dec 15 10:16:02 CET 2010: Library Path: /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/client:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
18
- Wed Dec 15 10:16:02 CET 2010: Garbage Collector: Copy: [Eden Space, Survivor Space]
19
- Wed Dec 15 10:16:02 CET 2010: Garbage Collector: MarkSweepCompact: [Eden Space, Survivor Space, Tenured Gen, Perm Gen, Perm Gen [shared-ro], Perm Gen [shared-rw]]
20
- Wed Dec 15 10:16:02 CET 2010: VM Arguments: [-Djruby.memory.max=500m, -Djruby.stack.max=1024k, -Xmx500m, -Xss1024k, -Djffi.boot.library.path=/home/andreas/.rvm/rubies/jruby-1.5.5/lib/native/i386-Linux:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/native/ppc-Linux:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/native/x86_64-Linux, -Xbootclasspath/a:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/jruby.jar, -Djruby.home=/home/andreas/.rvm/rubies/jruby-1.5.5, -Djruby.lib=/home/andreas/.rvm/rubies/jruby-1.5.5/lib, -Djruby.script=jruby, -Djruby.shell=/bin/sh]
21
- Wed Dec 15 10:16:02 CET 2010:
22
- Wed Dec 15 10:16:02 CET 2010: create=true
23
- Wed Dec 15 10:16:02 CET 2010: dir=tmp/neo4j/lucene-fulltext
24
- Wed Dec 15 10:16:02 CET 2010: logical_log=tmp/neo4j/nioneo_logical.log
25
- Wed Dec 15 10:16:02 CET 2010: neo_store=tmp/neo4j/neostore
26
- Wed Dec 15 10:16:02 CET 2010: neostore.nodestore.db.mapped_memory=20M
27
- Wed Dec 15 10:16:02 CET 2010: neostore.propertystore.db.arrays.mapped_memory=130M
28
- Wed Dec 15 10:16:02 CET 2010: neostore.propertystore.db.index.keys.mapped_memory=1M
29
- Wed Dec 15 10:16:02 CET 2010: neostore.propertystore.db.index.mapped_memory=1M
30
- Wed Dec 15 10:16:02 CET 2010: neostore.propertystore.db.mapped_memory=90M
31
- Wed Dec 15 10:16:02 CET 2010: neostore.propertystore.db.strings.mapped_memory=130M
32
- Wed Dec 15 10:16:02 CET 2010: neostore.relationshipstore.db.mapped_memory=100M
33
- Wed Dec 15 10:16:02 CET 2010: rebuild_idgenerators_fast=true
34
- Wed Dec 15 10:16:02 CET 2010: store_dir=tmp/neo4j
35
- Wed Dec 15 10:16:02 CET 2010: --- CONFIGURATION END ---
36
- Wed Dec 15 10:16:02 CET 2010: Extension org.neo4j.graphdb.index.IndexProvider[lucene] loaded ok
37
- Wed Dec 15 10:16:43 CET 2010: Closed log tmp/neo4j/nioneo_logical.log
38
- Wed Dec 15 10:16:43 CET 2010: NeoStore closed
39
- Wed Dec 15 10:16:43 CET 2010: Closed log /home/andreas/projects/neo4j/lib/tmp/neo4j/index/lucene.log
40
- Wed Dec 15 10:16:43 CET 2010: Closed log tmp/neo4j/lucene/lucene.log
41
- Wed Dec 15 10:16:43 CET 2010: NeoStore closed
42
- Wed Dec 15 10:16:43 CET 2010: Closed log tmp/neo4j/lucene-fulltext/lucene.log
43
- Wed Dec 15 10:16:43 CET 2010: TM shutting down
1
+ Thu Dec 30 12:24:53 CET 2010: Creating new db @ tmp/neo4j/neostore
2
+ Thu Dec 30 12:24:54 CET 2010: Opened [tmp/neo4j/nioneo_logical.log.1] clean empty log, version=0
3
+ Thu Dec 30 12:24:54 CET 2010: Opened [tmp/neo4j/lucene/lucene.log.1] clean empty log, version=0
4
+ Thu Dec 30 12:24:54 CET 2010: Opened [tmp/neo4j/lucene-fulltext/lucene.log.1] clean empty log, version=0
5
+ Thu Dec 30 12:24:54 CET 2010: Opened [/home/andreas/projects/neo4j/lib/tmp/neo4j/index/lucene.log.1] clean empty log, version=0
6
+ Thu Dec 30 12:24:54 CET 2010: Extension org.neo4j.graphdb.index.IndexProvider[lucene] initialized ok
7
+ Thu Dec 30 12:24:54 CET 2010: TM new log: tm_tx_log.1
8
+ Thu Dec 30 12:24:54 CET 2010: --- CONFIGURATION START ---
9
+ Thu Dec 30 12:24:54 CET 2010: Physical mem: 4016MB, Heap size: 483MB
10
+ Thu Dec 30 12:24:54 CET 2010: Kernel version: Neo4j - Graph Database Kernel 1.2-1.2.M04
11
+ Thu Dec 30 12:24:54 CET 2010: Operating System: Linux; version: 2.6.35-24-generic-pae; arch: i386
12
+ Thu Dec 30 12:24:54 CET 2010: VM Name: Java HotSpot(TM) Client VM
13
+ Thu Dec 30 12:24:54 CET 2010: VM Vendor: Sun Microsystems Inc.
14
+ Thu Dec 30 12:24:54 CET 2010: VM Version: 17.1-b03
15
+ Thu Dec 30 12:24:54 CET 2010: Boot Class Path: /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/resources.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/rt.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/jsse.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/jce.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/charsets.jar:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/classes:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/jruby.jar
16
+ Thu Dec 30 12:24:54 CET 2010: Class Path: :
17
+ Thu Dec 30 12:24:54 CET 2010: Library Path: /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/client:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
18
+ Thu Dec 30 12:24:54 CET 2010: Garbage Collector: Copy: [Eden Space, Survivor Space]
19
+ Thu Dec 30 12:24:54 CET 2010: Garbage Collector: MarkSweepCompact: [Eden Space, Survivor Space, Tenured Gen, Perm Gen, Perm Gen [shared-ro], Perm Gen [shared-rw]]
20
+ Thu Dec 30 12:24:54 CET 2010: VM Arguments: [-Djruby.memory.max=500m, -Djruby.stack.max=1024k, -Xmx500m, -Xss1024k, -Djffi.boot.library.path=/home/andreas/.rvm/rubies/jruby-1.5.5/lib/native/i386-Linux:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/native/ppc-Linux:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/native/x86_64-Linux, -Xbootclasspath/a:/home/andreas/.rvm/rubies/jruby-1.5.5/lib/jruby.jar, -Djruby.home=/home/andreas/.rvm/rubies/jruby-1.5.5, -Djruby.lib=/home/andreas/.rvm/rubies/jruby-1.5.5/lib, -Djruby.script=jruby, -Djruby.shell=/bin/sh]
21
+ Thu Dec 30 12:24:54 CET 2010:
22
+ Thu Dec 30 12:24:54 CET 2010: create=true
23
+ Thu Dec 30 12:24:54 CET 2010: dir=tmp/neo4j/lucene-fulltext
24
+ Thu Dec 30 12:24:54 CET 2010: logical_log=tmp/neo4j/nioneo_logical.log
25
+ Thu Dec 30 12:24:54 CET 2010: neo_store=tmp/neo4j/neostore
26
+ Thu Dec 30 12:24:54 CET 2010: neostore.nodestore.db.mapped_memory=20M
27
+ Thu Dec 30 12:24:54 CET 2010: neostore.propertystore.db.arrays.mapped_memory=130M
28
+ Thu Dec 30 12:24:54 CET 2010: neostore.propertystore.db.index.keys.mapped_memory=1M
29
+ Thu Dec 30 12:24:54 CET 2010: neostore.propertystore.db.index.mapped_memory=1M
30
+ Thu Dec 30 12:24:54 CET 2010: neostore.propertystore.db.mapped_memory=90M
31
+ Thu Dec 30 12:24:54 CET 2010: neostore.propertystore.db.strings.mapped_memory=130M
32
+ Thu Dec 30 12:24:54 CET 2010: neostore.relationshipstore.db.mapped_memory=100M
33
+ Thu Dec 30 12:24:54 CET 2010: rebuild_idgenerators_fast=true
34
+ Thu Dec 30 12:24:54 CET 2010: store_dir=tmp/neo4j
35
+ Thu Dec 30 12:24:54 CET 2010: --- CONFIGURATION END ---
36
+ Thu Dec 30 12:24:54 CET 2010: Extension org.neo4j.graphdb.index.IndexProvider[lucene] loaded ok
37
+ Thu Dec 30 14:15:48 CET 2010: Closed log tmp/neo4j/nioneo_logical.log
38
+ Thu Dec 30 14:15:48 CET 2010: NeoStore closed
39
+ Thu Dec 30 14:15:48 CET 2010: Closed log /home/andreas/projects/neo4j/lib/tmp/neo4j/index/lucene.log
40
+ Thu Dec 30 14:15:48 CET 2010: Closed log tmp/neo4j/lucene/lucene.log
41
+ Thu Dec 30 14:15:48 CET 2010: NeoStore closed
42
+ Thu Dec 30 14:15:48 CET 2010: Closed log tmp/neo4j/lucene-fulltext/lucene.log
43
+ Thu Dec 30 14:15:48 CET 2010: TM shutting down
Binary file
Binary file
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 24
11
- version: 1.0.0.beta.24
10
+ - 25
11
+ version: 1.0.0.beta.25
12
12
  platform: java
13
13
  authors:
14
14
  - Andreas Ronge
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-15 00:00:00 +01:00
19
+ date: 2011-01-05 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -110,6 +110,7 @@ files:
110
110
  - lib/tmp/neo4j/neostore.relationshipstore.db
111
111
  - lib/tmp/neo4j/neostore.propertystore.db.index.id
112
112
  - lib/tmp/neo4j/neostore.propertystore.db.id
113
+ - lib/tmp/neo4j/index.db
113
114
  - lib/tmp/neo4j/neostore.propertystore.db
114
115
  - lib/tmp/neo4j/tm_tx_log.1
115
116
  - lib/tmp/neo4j/neostore.relationshiptypestore.db
@@ -119,6 +120,9 @@ files:
119
120
  - lib/tmp/neo4j/lucene-fulltext/lucene.log.active
120
121
  - lib/tmp/neo4j/index/lucene-store.db
121
122
  - lib/tmp/neo4j/index/lucene.log.active
123
+ - lib/tmp/neo4j/index/lucene/node/Network-exact/segments.gen
124
+ - lib/tmp/neo4j/index/lucene/node/Network-exact/segments_2
125
+ - lib/tmp/neo4j/index/lucene/node/Network-exact/_0.cfs
122
126
  - lib/tmp/neo4j/lucene/lucene-store.db
123
127
  - lib/tmp/neo4j/lucene/lucene.log.active
124
128
  - lib/neo4j/event_handler.rb
@@ -127,6 +131,7 @@ files:
127
131
  - lib/neo4j/node_traverser.rb
128
132
  - lib/neo4j/relationship_traverser.rb
129
133
  - lib/neo4j/config.rb
134
+ - lib/neo4j/algo.rb
130
135
  - lib/neo4j/transaction.rb
131
136
  - lib/neo4j/neo4j.rb
132
137
  - lib/neo4j/node.rb
@@ -161,11 +166,12 @@ files:
161
166
  - lib/neo4j/rails/mapping/property.rb
162
167
  - lib/neo4j/rails/validations/uniqueness.rb
163
168
  - lib/neo4j/rails/validations/non_nil.rb
164
- - lib/neo4j/jars/neo4j-index-1.2-1.2.M04.jar
165
- - lib/neo4j/jars/neo4j-lucene-index-0.2-1.2.M04.jar
169
+ - lib/neo4j/jars/neo4j-graph-algo-0.7-1.2.jar
170
+ - lib/neo4j/jars/neo4j-lucene-index-0.2-1.2.jar
166
171
  - lib/neo4j/jars/geronimo-jta_1.1_spec-1.1.1.jar
167
172
  - lib/neo4j/jars/lucene-core-3.0.2.jar
168
- - lib/neo4j/jars/neo4j-kernel-1.2-1.2.M04.jar
173
+ - lib/neo4j/jars/neo4j-kernel-1.2-1.2.jar
174
+ - lib/neo4j/jars/neo4j-index-1.2-1.2.jar
169
175
  - lib/neo4j/mapping/rule.rb
170
176
  - lib/neo4j/mapping/decl_relationship_dsl.rb
171
177
  - lib/neo4j/mapping/rule_node.rb