neo4j 1.0.0.beta.9 → 1.0.0.beta.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/README.rdoc +5 -1971
  2. data/lib/neo4j/mapping/class_methods/relationship.rb +2 -2
  3. data/lib/neo4j/mapping/decl_relationship_dsl.rb +6 -1
  4. data/lib/neo4j/mapping/has_n.rb +17 -1
  5. data/lib/neo4j/node_traverser.rb +14 -1
  6. data/lib/neo4j/rails/model.rb +127 -31
  7. data/lib/neo4j/rails/tx_methods.rb +11 -0
  8. data/lib/neo4j/rails/value.rb +44 -1
  9. data/lib/neo4j/version.rb +1 -1
  10. data/lib/neo4j.rb +1 -0
  11. metadata +4 -59
  12. data/lib/neo4j.old/batch_inserter.rb +0 -144
  13. data/lib/neo4j.old/config.rb +0 -138
  14. data/lib/neo4j.old/event_handler.rb +0 -73
  15. data/lib/neo4j.old/extensions/activemodel.rb +0 -158
  16. data/lib/neo4j.old/extensions/aggregate/aggregate_enum.rb +0 -40
  17. data/lib/neo4j.old/extensions/aggregate/ext/node_mixin.rb +0 -69
  18. data/lib/neo4j.old/extensions/aggregate/node_aggregate.rb +0 -8
  19. data/lib/neo4j.old/extensions/aggregate/node_aggregate_mixin.rb +0 -331
  20. data/lib/neo4j.old/extensions/aggregate/node_aggregator.rb +0 -216
  21. data/lib/neo4j.old/extensions/aggregate/node_group.rb +0 -43
  22. data/lib/neo4j.old/extensions/aggregate/prop_group.rb +0 -30
  23. data/lib/neo4j.old/extensions/aggregate/property_enum.rb +0 -24
  24. data/lib/neo4j.old/extensions/aggregate/props_aggregate.rb +0 -8
  25. data/lib/neo4j.old/extensions/aggregate/props_aggregate_mixin.rb +0 -31
  26. data/lib/neo4j.old/extensions/aggregate/props_aggregator.rb +0 -80
  27. data/lib/neo4j.old/extensions/aggregate.rb +0 -12
  28. data/lib/neo4j.old/extensions/find_path.rb +0 -117
  29. data/lib/neo4j.old/extensions/graph_algo/all_simple_paths.rb +0 -133
  30. data/lib/neo4j.old/extensions/graph_algo/neo4j-graph-algo-0.3.jar +0 -0
  31. data/lib/neo4j.old/extensions/graph_algo.rb +0 -1
  32. data/lib/neo4j.old/extensions/reindexer.rb +0 -104
  33. data/lib/neo4j.old/extensions/rest/rest.rb +0 -336
  34. data/lib/neo4j.old/extensions/rest/rest_mixin.rb +0 -193
  35. data/lib/neo4j.old/extensions/rest/server.rb +0 -50
  36. data/lib/neo4j.old/extensions/rest/stubs.rb +0 -141
  37. data/lib/neo4j.old/extensions/rest.rb +0 -21
  38. data/lib/neo4j.old/extensions/rest_master.rb +0 -34
  39. data/lib/neo4j.old/extensions/rest_slave.rb +0 -31
  40. data/lib/neo4j.old/extensions/tx_tracker.rb +0 -392
  41. data/lib/neo4j.old/indexer.rb +0 -187
  42. data/lib/neo4j.old/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  43. data/lib/neo4j.old/jars/neo4j-kernel-1.0.jar +0 -0
  44. data/lib/neo4j.old/jars.rb +0 -6
  45. data/lib/neo4j.old/mixins/java_list_mixin.rb +0 -139
  46. data/lib/neo4j.old/mixins/java_node_mixin.rb +0 -205
  47. data/lib/neo4j.old/mixins/java_property_mixin.rb +0 -169
  48. data/lib/neo4j.old/mixins/java_relationship_mixin.rb +0 -60
  49. data/lib/neo4j.old/mixins/migration_mixin.rb +0 -157
  50. data/lib/neo4j.old/mixins/node_mixin.rb +0 -249
  51. data/lib/neo4j.old/mixins/property_class_methods.rb +0 -265
  52. data/lib/neo4j.old/mixins/rel_class_methods.rb +0 -167
  53. data/lib/neo4j.old/mixins/relationship_mixin.rb +0 -103
  54. data/lib/neo4j.old/neo.rb +0 -247
  55. data/lib/neo4j.old/node.rb +0 -49
  56. data/lib/neo4j.old/reference_node.rb +0 -15
  57. data/lib/neo4j.old/relationship.rb +0 -85
  58. data/lib/neo4j.old/relationships/decl_relationship_dsl.rb +0 -164
  59. data/lib/neo4j.old/relationships/has_list.rb +0 -101
  60. data/lib/neo4j.old/relationships/has_n.rb +0 -129
  61. data/lib/neo4j.old/relationships/node_traverser.rb +0 -138
  62. data/lib/neo4j.old/relationships/relationship_dsl.rb +0 -149
  63. data/lib/neo4j.old/relationships/traversal_position.rb +0 -50
  64. data/lib/neo4j.old/relationships/wrappers.rb +0 -51
  65. data/lib/neo4j.old/search_result.rb +0 -72
  66. data/lib/neo4j.old/transaction.rb +0 -254
  67. data/lib/neo4j.old/version.rb +0 -3
data/lib/neo4j.old/neo.rb DELETED
@@ -1,247 +0,0 @@
1
- module Neo4j
2
-
3
- class << self
4
- extend Forwardable
5
-
6
- ##
7
- # Returns the current version of the database.
8
- # This version has been set by running one or more migrations.
9
- # The version is stored on the reference node, with property 'db_version'
10
- # (Delegates to the Reference Node that includes the MigrationMixin.)
11
- #
12
- # === See Also
13
- # Neo4j::MigrationMixin#db_version
14
- #
15
- # :singleton-method: db_version
16
-
17
- ##
18
- # Force Neo4j.rb to perform migrations
19
- #
20
- # === See Also
21
- # Neo4j::MigrationMixin#migrate!
22
- #
23
- # :singleton-method: migrate!
24
-
25
- ##
26
- # Specifies a single migration.
27
- #
28
- # === Example
29
- # Notice that the reference node is the context in the up and down blocks.
30
- #
31
- # Neo4j.migration 1, :create_articles do
32
- # up do
33
- # rels.outgoing(:colours) << Neo4j.new :colour => 'red' << Neo4j.new :colour => 'blue'
34
- # end
35
- # down do
36
- # rels.outgoing(:colours).each {|n| n.del }
37
- # end
38
- # end
39
- #
40
- # === See Also
41
- # Neo4j::MigrationMixin::ClassMethods#migration
42
- # Neo4j::ReferenceNode
43
- #
44
- # :singleton-method: migration
45
-
46
- ##
47
- # Returns all migrations that has been defined.
48
- #
49
- # === See Also
50
- # Neo4j::MigrationMixin::ClassMethods#migrations
51
- #
52
- # :singleton-method: migrations
53
-
54
- def_delegators :@ref_node, :db_version, :migrate!
55
- def_delegators Neo4j::ReferenceNode, :migration, :migrations
56
-
57
-
58
-
59
- # Starts neo4j unless it is not already started.
60
- # Before using neo4j it has to be started and the location of the Neo database on the file system must
61
- # have been configured, Neo4j::Config[:storage_path]. You do not have to call this method since
62
- # neo4j will be started automatically when needed.
63
- # Registers an at_exit handler that stops neo4j (see Neo4j::stop)
64
- #
65
- # === Parameters
66
- # neo_instance:: optional, an instance of org.neo4j.graphdb.GraphDatabaseService
67
- #
68
- # === Examples
69
- # Neo4j::Config[:storage_path] = '/var/neo4j-db'
70
- # Neo4j.start
71
- #
72
- # === Returns
73
- # nil
74
- #
75
- def start(neo_instance=nil)
76
- return if running?
77
- at_exit do
78
- Neo4j.stop
79
- end
80
- @neo = neo_instance || org.neo4j.kernel.EmbeddedGraphDatabase.new(Neo4j::Config[:storage_path])
81
- @ref_node = Neo4j::Transaction.run do
82
- ReferenceNode.new(@neo.getReferenceNode())
83
- end
84
-
85
- Neo4j::Transaction.run do
86
- Neo4j.event_handler.neo_started(self)
87
- end
88
-
89
- Neo4j::Transaction.run { @ref_node.migrate!}
90
- nil
91
- end
92
-
93
- # Return the org.neo4j.kernel.EmbeddedGraphDatabase
94
- #
95
- #
96
- def instance
97
- start unless running?
98
- @neo
99
- end
100
-
101
- # Stops the current instance unless it is not started.
102
- #
103
- def stop
104
- if running?
105
- Neo4j::Transaction.finish # just in case
106
- @neo.shutdown
107
- Neo4j.event_handler.neo_stopped(self)
108
- end
109
- @neo = nil
110
- end
111
-
112
- #
113
- # Returns true if neo4j is running
114
- #
115
- def running?
116
- !@neo.nil?
117
- end
118
-
119
-
120
- # Create a Neo4j::Node
121
- # This is the same as Neo4j::Node.new.
122
- # All nodes are created by this method
123
- def create_node(props = {}) # :nodoc:
124
- node = instance.createNode
125
- props.each_pair{|k,v| node[k] = v}
126
- node
127
- end
128
-
129
- # Creates a new Relationship
130
- # All relationships are created by this method.
131
- def create_rel(type, from_node, to_node, props = {}) # :nodoc:
132
- rel = from_node.add_rel(type, to_node)
133
- props.each_pair {|k,v| rel[k] = v}
134
- rel
135
- end
136
-
137
- # Return a Neo4j node.
138
- #
139
- # ==== Parameters
140
- # node_id:: the unique neo id for one node, should respond to 'to_i'
141
- # raw:: if the raw Java node object should be returned or the Ruby wrapped node, default false.
142
- #
143
- # ==== Returns
144
- # The node object or nil if not found
145
- #
146
- def load_node(node_id, raw = false)
147
- neo_node = @neo.getNodeById(node_id.to_i)
148
- if (raw)
149
- neo_node
150
- else
151
- neo_node.wrapper
152
- end
153
- rescue org.neo4j.graphdb.NotFoundException
154
- nil
155
- end
156
-
157
-
158
- # Return a Neo4j relationship.
159
- #
160
- # ==== Parameters
161
- # rel_id<String, to_i>:: the unique neo id for one node
162
- # raw<true|false(default)> :: if the raw Java relationship object should be returned or the Ruby wrapped node.
163
- #
164
- # ==== Returns
165
- # The node object or nil if not found
166
- #
167
- def load_rel(rel_id, raw = false)
168
- neo_rel = @neo.getRelationshipById(rel_id.to_i)
169
- if (raw)
170
- neo_rel
171
- else
172
- neo_rel.wrapper
173
- end
174
- rescue org.neo4j.graphdb.NotFoundException
175
- nil
176
- end
177
-
178
- # Returns all nodes in the node space.
179
- # Expects a block that will be yield.
180
- #
181
- # ==== Parameters
182
- # raw<true|false(default)> :: if the raw Java node object should be returned or the Ruby wrapped node.
183
- #
184
- # ==== Example
185
- #
186
- # Neo4j.all_nodes{|node| puts "Node id ${node.neo_id"}
187
- #
188
- def all_nodes(raw = false)
189
- iter = instance.all_nodes.iterator
190
- while (iter.hasNext)
191
- id = iter.next.neo_id
192
- yield load_node(id, raw)
193
- end
194
- end
195
-
196
- # Returns the reference node, which is a "starting point" in the node space.
197
- #
198
- # Usually, a client attaches relationships to this node that leads into various parts of the node space.
199
- # For more information about common node space organizational patterns, see the design guide at http://neo4j.org/doc.
200
- #
201
- # ==== Returns
202
- # The the Neo4j::ReferenceNode
203
- #
204
- def ref_node
205
- @ref_node
206
- end
207
-
208
-
209
- # Returns an event handler.
210
- # This event handler can be used for listen to event such as when the Neo4j is started/stopped or
211
- # when a node is created/deleted, a property/relationship is changed.
212
- #
213
- # ==== Returns
214
- # a Neo4j::EventHandler instance
215
- #
216
- def event_handler
217
- @event_handler ||= EventHandler.new
218
- end
219
-
220
-
221
- def number_of_nodes_in_use
222
- instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.graphdb.Node.java_class)
223
- end
224
-
225
- def number_of_relationships_in_use
226
- instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.graphdb.Relationship.java_class)
227
- end
228
-
229
- def number_of_properties_in_use
230
- instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.kernel.impl.nioneo.store.PropertyStore.java_class)
231
- end
232
-
233
- # Prints some info about the database
234
- def info
235
- puts "Neo4j version: #{Neo4j::VERSION}"
236
- puts "Neo4j db running #{running?}"
237
- puts "number_of_nodes_in_use: #{number_of_nodes_in_use}"
238
- puts "number_of_relationships_in_use: #{number_of_relationships_in_use}"
239
- puts "number_of_properties_in_use: #{number_of_properties_in_use}"
240
- puts "neo db storage location: #{Neo4j::Config[:storage_path]}"
241
- puts "lucene index storage location: #{Lucene::Config[:storage_path]}"
242
- puts "keep lucene index in memory: #{!Lucene::Config[:store_on_file]}"
243
- end
244
-
245
- end
246
- end
247
-
@@ -1,49 +0,0 @@
1
- module Neo4j
2
-
3
- org.neo4j.kernel.impl.core.NodeProxy.class_eval do
4
- include Neo4j::JavaPropertyMixin
5
- include Neo4j::JavaNodeMixin
6
- include Neo4j::JavaListMixin
7
- end
8
-
9
- # A node in the graph with properties and relationships to other entities.
10
- # Along with relationships, nodes are the core building blocks of the Neo4j data representation model.
11
- # Nodes are created by invoking the Neo4j::Node.new method.
12
- #
13
- # The new method of this class will return a Java org.neo4j.graphdb.Node
14
- #
15
- # === Included Mixins
16
- # * Neo4j::JavaPropertyMixin (operations that deal with relationships)
17
- # * Neo4j::JavaNodeMixin (operations that deal with properties
18
- # * Neo4j::JavaListMixin (operations that deals with list/timeline relationships)
19
- #
20
- # (Those mixin are actually not included in the Neo4j::Node but instead directly included in the java class org.neo4j.graphdb.Node)
21
- #
22
- # See also the Neo4j::NodeMixin if you want to wrap a node with your own Ruby class.
23
- #
24
- class Node
25
- class << self
26
- # Returns a org.neo4j.graphdb.Node java object (!)
27
- # Will trigger a event that the node was created.
28
- #
29
- # === Parameters
30
- # *args :: can be a hash of properties to initialize the node with or empty
31
- #
32
- # === Returns
33
- # org.neo4j.graphdb.Node java object
34
- #
35
- # === Examples
36
- #
37
- # Neo4j::Node.new
38
- # Neo4j::Node.new :name => 'foo', :age => 100
39
- #
40
- def new(*args)
41
- node = Neo4j.create_node(args[0] || {})
42
- yield node if block_given?
43
- Neo4j.event_handler.node_created(node)
44
- node
45
- end
46
- end
47
- end
48
-
49
- end
@@ -1,15 +0,0 @@
1
- module Neo4j
2
-
3
- # There is only one reference node in a neo space, which can always been found (Neo4j::Neo#:ref_node).
4
- # This is a "starting point" in the node space.
5
- # Usually, a client attaches relationships to this node that leads into various parts of the node space.
6
- # For more information about common node space organizational patterns, see the design guide at http://neo4j.org/doc.
7
- #
8
- # You can add your own has_n or has_list, has_one relationship to this node.
9
- #
10
- class ReferenceNode
11
- include Neo4j::NodeMixin
12
- include Neo4j::MigrationMixin
13
- end
14
-
15
- end
@@ -1,85 +0,0 @@
1
- module Neo4j
2
-
3
- org.neo4j.kernel.impl.core.RelationshipProxy.class_eval do
4
- include Neo4j::JavaPropertyMixin
5
- include Neo4j::JavaRelationshipMixin
6
-
7
- def end_node # :nodoc:
8
- id = getEndNode.getId
9
- Neo4j.load_node(id)
10
- end
11
-
12
- def start_node # :nodoc:
13
- id = getStartNode.getId
14
- Neo4j.load_node(id)
15
- end
16
-
17
- def other_node(node) # :nodoc:
18
- neo_node = node
19
- neo_node = node._java_node if node.respond_to?(:_java_node)
20
- id = getOtherNode(neo_node).getId
21
- Neo4j.load_node(id)
22
- end
23
- end
24
-
25
- #
26
- # A relationship between two nodes in the graph. A relationship has a start node, an end node and a type.
27
- # You can attach properties to relationships with the API specified in Neo4j::JavaPropertyMixin.
28
- #
29
- # Relationship are created by invoking the << operator on the rels method on the node as follow:
30
- # node.rels.outgoing(:friends) << other_node << yet_another_node
31
- #
32
- # or using the Neo4j::Relationship#new method (which does the same thing):
33
- # rel = Neo4j::Relationship.new(:friends, node, other_node)
34
- #
35
- # The fact that the relationship API gives meaning to start and end nodes implicitly means that all relationships have a direction.
36
- # In the example above, rel would be directed from node to otherNode.
37
- # A relationship's start node and end node and their relation to outgoing and incoming are defined so that the assertions in the following code are true:
38
- #
39
- # a = Neo4j::Node.new
40
- # b = Neo4j::Node.new
41
- # rel = Neo4j::Relationship.new(:some_type, a, b)
42
- # # Now we have: (a) --- REL_TYPE ---> (b)
43
- #
44
- # rel.start_node # => a
45
- # rel.end_node # => b
46
- #
47
- # Furthermore, Neo4j guarantees that a relationship is never "hanging freely,"
48
- # i.e. start_node, end_node and other_node are guaranteed to always return valid, non-null nodes.
49
- #
50
- # See also the Neo4j::RelationshipMixin if you want to wrap a relationship with your own Ruby class.
51
- #
52
- # === Included Mixins
53
- # * Neo4j::JavaPropertyMixin
54
- # * Neo4j::JavaRelationshipMixin
55
- #
56
- # (Those mixin are actually not included in the Neo4j::Relationship but instead directly included in the java class org.neo4j.kernel.impl.core.RelationshipProxy)
57
- #
58
- class Relationship
59
- class << self
60
- # Returns a org.neo4j.graphdb.Relationship java object (!)
61
- # Will trigger a event that the relationship was created.
62
- #
63
- # === Parameters
64
- # type :: the type of relationship
65
- # from_node :: the start node of this relationship
66
- # end_node :: the end node of this relationship
67
- # props :: optional properties for the created relationship
68
- #
69
- # === Returns
70
- # org.neo4j.graphdb.Relationship java object
71
- #
72
- # === Examples
73
- #
74
- # Neo4j::Relationship.new :friend, node1, node2, :since => '2001-01-02', :status => 'okey'
75
- #
76
- def new(type, from_node, to_node, props={})
77
- Neo4j.create_rel(type, from_node, to_node, props)
78
- end
79
- end
80
-
81
- end
82
-
83
- end
84
-
85
-
@@ -1,164 +0,0 @@
1
- module Neo4j
2
-
3
- module Relationships
4
-
5
- # A DSL for declared relationships has_n and has_one
6
- # This DSL will be used to create accessor methods for relationships.
7
- # Instead of using the 'raw' Neo4j::NodeMixin#rels method where one needs to know
8
- # the name of relationship and direction one can use the generated accessor methods.
9
- #
10
- # The DSL can also be used to specify a mapping to a Ruby class for a relationship, see Neo4j::Relationships::DeclRelationshipDsl#relationship
11
- #
12
- # ==== Example
13
- #
14
- # class Folder
15
- # include Neo4j::NodeMixin
16
- # property :name
17
- # # Declaring a Many relationship to any other node
18
- # has_n(:files)
19
- # end
20
- #
21
- # class File
22
- # include Neo4j::NodeMixin
23
- # # declaring a incoming relationship from Folder's relationship files
24
- # has_one(:folder).from(Folder, :files)
25
- # end
26
- #
27
- # The following methods will be generated:
28
- # <b>Folder#files</b> :: returns an Enumerable of outgoing nodes for relationship 'files'
29
- # <b>Folder#files_rels</b> :: returns an Enumerable of outgoing relationships for relationship 'files'
30
- # <b>File#folder</b> :: for adding one node for the relationship 'files' from the outgoing Folder node
31
- # <b>File#folder_rel</b> :: for accessing relationship 'files' from the outgoing Folder node
32
- # <b>File#folder</b> :: for accessing nodes from relationship 'files' from the outgoing Folder node
33
- #
34
- class DeclRelationshipDsl
35
-
36
- attr_reader :to_type, :to_class, :cascade_delete_prop_name, :counter, :rel_id
37
- CASCADE_DELETE_PROP_NAMES = { :outgoing => :_cascade_delete_outgoing, :incoming => :_cascade_delete_incoming}
38
-
39
- def initialize(rel_id, params)
40
- @outgoing = true
41
- @rel_id = rel_id
42
- @to_type = rel_id
43
- @namespace_type = rel_id
44
- @cascade_delete_prop_name = CASCADE_DELETE_PROP_NAMES[params[:cascade_delete]]
45
- @counter = params[:counter] == true
46
- end
47
-
48
- # If a counter was specified in the dsl for counting number of nodes in this relationship.
49
- #
50
- def counter?
51
- @counter
52
- end
53
-
54
- # If cascade delete was specified for this relationship
55
- #
56
- def cascade_delete?
57
- !@cascade_delete_prop_name.nil?
58
- end
59
-
60
- def class_and_type_from_args(args) # :nodoc:
61
- if (args.size > 1)
62
- return args[0], args[1]
63
- else
64
- return args[0], @rel_id
65
- end
66
- end
67
-
68
-
69
- # The actual relationship type that this DSL will use
70
- def namespace_type
71
- @to_class.nil? ? @to_type.to_s : "#{@to_class.to_s}##{@to_type.to_s}"
72
- end
73
-
74
-
75
- # The direction of the relationships
76
- # ==== Returns
77
- # <tt>:outgoing::</tt> or <tt>:incoming</tt>
78
- def direction
79
- (outgoing?)? :outgoing : :incoming
80
- end
81
-
82
- def outgoing?
83
- @outgoing
84
- end
85
-
86
-
87
- # Specifies an outgoing relationship.
88
- # The name of the outgoing class will be used as a prefix for the relationship used.
89
- #
90
- # ==== Arguments
91
- # clazz:: to which class this relationship goes
92
- # relationship:: optional, the relationship to use
93
- #
94
- # ==== Example
95
- # class FolderNode
96
- # include Neo4j::NodeMixin
97
- # has_n(:files).to(FileNode)
98
- # end
99
- #
100
- # folder = FolderNode.new
101
- # # generate a relationship between folder and file of type 'FileNode#files'
102
- # folder.files << FileNode.new
103
- #
104
- def to(*args)
105
- @outgoing = true
106
- @to_class, @to_type = class_and_type_from_args(args)
107
- self
108
- end
109
-
110
- # Specifies an incoming relationship.
111
- # Will use the outgoing relationship given by the from class.
112
- #
113
- # ==== Example
114
- # class FolderNode
115
- # include Neo4j::NodeMixin
116
- # has_n(:files).to(FileNode)
117
- # end
118
- #
119
- # class FileNode
120
- # include Neo4j::NodeMixin
121
- # has_one(:folder).from(FileNode, :files)
122
- # end
123
- #
124
- # file = FileNode.new
125
- # # create an outgoing relationship of type 'FileNode#files' from folder node to file
126
- # file.folder = FolderNode.new
127
- #
128
- def from(*args) #(clazz, type)
129
- @outgoing = false
130
- @to_class, @to_type = class_and_type_from_args(args)
131
- self
132
- end
133
-
134
- # Specifies which relationship ruby class to use for the relationship
135
- #
136
- # ==== Example
137
- #
138
- # class OrderLine
139
- # include Neo4j::RelationshipMixin
140
- # property :units
141
- # property :unit_price
142
- # end
143
- #
144
- # class Order
145
- # property :total_cost
146
- # property :dispatched
147
- # has_n(:products).to(Product).relationship(OrderLine)
148
- # end
149
- #
150
- # order = Order.new
151
- # order.products << Product.new
152
- # order.products_rels.first # => OrderLine
153
- #
154
- def relationship(rel_class)
155
- @relationship = rel_class
156
- self
157
- end
158
-
159
- def relationship_class # :nodoc:
160
- @relationship
161
- end
162
- end
163
- end
164
- end
@@ -1,101 +0,0 @@
1
- module Neo4j
2
-
3
- module Relationships
4
-
5
- # Provides appending and traversing nodes that are linked together in a list with
6
- # relationships to the next list item.
7
- #
8
- class HasList
9
- include Enumerable
10
- attr_reader :relationship_type
11
-
12
- def initialize(node, dsl, &filter)
13
- @node = node
14
- @relationship_type = "_list_#{dsl.to_type}_#{node.neo_id}"
15
- if (dsl.counter?)
16
- @counter_id = "_#{dsl.to_type}_size".to_sym
17
- end
18
- @cascade_delete = dsl.cascade_delete_prop_name
19
- end
20
-
21
- def size
22
- @node[@counter_id] || 0
23
- end
24
-
25
- # called by the event handler
26
- def self.on_node_deleted(node) #:nodoc:
27
- # check if node is member of one or more lists
28
- node.lists{|list_item| list_item.prev.next = list_item.next if list_item.prev; list_item.size -= 1}
29
- end
30
-
31
- # Appends one node to the end of the list
32
- #
33
- # :api: public
34
- def <<(other)
35
- # does node have a relationship ?
36
- new_rel = []
37
- if (@node.rel?(@relationship_type))
38
- # get that relationship
39
- first = @node.rels.outgoing(@relationship_type).first
40
-
41
- # delete this relationship
42
- first.del
43
- old_first = first.other_node(@node)
44
- new_rel << @node.add_rel(@relationship_type, other)
45
- new_rel << other.add_rel(@relationship_type, old_first)
46
- else
47
- # the first node will be set
48
- new_rel << @node.add_rel(@relationship_type, other)
49
- end
50
-
51
- if @cascade_delete
52
- # the @node.neo_id is only used for cascade_delete_incoming since that node will be deleted when all the list items has been deleted.
53
- # if cascade_delete_outgoing all nodes will be deleted when the root node is deleted
54
- # if cascade_delete_incoming then the root node will be deleted when all root nodes' outgoing nodes are deleted
55
- new_rel.each {|rel| rel[@cascade_delete] = @node.neo_id}
56
- end
57
- if @counter_id
58
- @node[@counter_id] ||= 0
59
- @node[@counter_id] += 1
60
- end
61
-
62
- self
63
- end
64
-
65
- # Returns true if the list is empty s
66
- #
67
- # :api: public
68
- def empty?
69
- !iterator.hasNext
70
- end
71
-
72
- def first
73
- return nil unless @node.rel?(@relationship_type, :outgoing)
74
- @node.rel(@relationship_type, :outgoing).end_node
75
- end
76
-
77
- def each
78
- iter = iterator
79
- while (iter.hasNext) do
80
- n = iter.next
81
- yield Neo4j.load_node(n.get_id)
82
- end
83
- end
84
-
85
- def iterator
86
- stop_evaluator = org.neo4j.graphdb.StopEvaluator::END_OF_GRAPH
87
- traverser_order = org.neo4j.graphdb.Traverser::Order::BREADTH_FIRST
88
- returnable_evaluator = org.neo4j.graphdb.ReturnableEvaluator::ALL_BUT_START_NODE
89
- types_and_dirs = []
90
- types_and_dirs << org.neo4j.graphdb.DynamicRelationshipType.withName(@relationship_type.to_s)
91
- types_and_dirs << org.neo4j.graphdb.Direction::OUTGOING
92
- @node._java_node.traverse(traverser_order, stop_evaluator, returnable_evaluator, types_and_dirs.to_java(:object)).iterator
93
- end
94
-
95
- end
96
-
97
-
98
- end
99
-
100
-
101
- end