neo4j 2.0.0.alpha.5-java → 2.0.0.alpha.6-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +12 -0
- data/Gemfile +0 -4
- data/README.rdoc +106 -62
- data/lib/neo4j.rb +7 -33
- data/lib/neo4j/performance.rb +43 -0
- data/lib/neo4j/rails/accept_id.rb +19 -18
- data/lib/neo4j/rails/attributes.rb +366 -120
- data/lib/neo4j/rails/finders.rb +41 -15
- data/lib/neo4j/rails/has_n.rb +203 -0
- data/lib/neo4j/rails/identity.rb +25 -0
- data/lib/neo4j/rails/model.rb +65 -242
- data/lib/neo4j/rails/nested_attributes.rb +108 -0
- data/lib/neo4j/rails/node_persistance.rb +56 -0
- data/lib/neo4j/rails/observer.rb +0 -2
- data/lib/neo4j/rails/persistence.rb +32 -154
- data/lib/neo4j/rails/rack_middleware.rb +26 -2
- data/lib/neo4j/rails/rails.rb +9 -6
- data/lib/neo4j/rails/railtie.rb +1 -2
- data/lib/neo4j/rails/relationship.rb +18 -125
- data/lib/neo4j/rails/relationship_persistence.rb +107 -0
- data/lib/neo4j/rails/relationships/node_dsl.rb +72 -44
- data/lib/neo4j/rails/relationships/relationships.rb +187 -59
- data/lib/neo4j/rails/relationships/rels_dsl.rb +18 -17
- data/lib/neo4j/rails/relationships/storage.rb +19 -17
- data/lib/neo4j/rails/timestamps.rb +53 -51
- data/lib/neo4j/rails/transaction.rb +9 -1
- data/lib/neo4j/rails/validations/uniqueness.rb +1 -1
- data/lib/neo4j/rails/versioning/versioning.rb +2 -2
- data/lib/neo4j/version.rb +1 -1
- data/lib/orm_adapter/adapters/neo4j.rb +47 -46
- data/neo4j.gemspec +1 -1
- metadata +10 -69
- data/lib/neo4j/algo/algo.rb +0 -294
- data/lib/neo4j/batch/batch.rb +0 -4
- data/lib/neo4j/batch/indexer.rb +0 -109
- data/lib/neo4j/batch/inserter.rb +0 -179
- data/lib/neo4j/batch/rule_inserter.rb +0 -24
- data/lib/neo4j/batch/rule_node.rb +0 -72
- data/lib/neo4j/config.rb +0 -177
- data/lib/neo4j/core_ext/class/inheritable_attributes.rb +0 -12
- data/lib/neo4j/core_ext/class/rewrite_inheritable_attributes.rb +0 -170
- data/lib/neo4j/database.rb +0 -158
- data/lib/neo4j/equal.rb +0 -21
- data/lib/neo4j/event_handler.rb +0 -263
- data/lib/neo4j/has_list/class_methods.rb +0 -11
- data/lib/neo4j/has_list/has_list.rb +0 -3
- data/lib/neo4j/has_list/mapping.rb +0 -133
- data/lib/neo4j/has_n/class_methods.rb +0 -119
- data/lib/neo4j/has_n/decl_relationship_dsl.rb +0 -246
- data/lib/neo4j/has_n/has_n.rb +0 -3
- data/lib/neo4j/has_n/mapping.rb +0 -98
- data/lib/neo4j/identity_map.rb +0 -140
- data/lib/neo4j/index/class_methods.rb +0 -108
- data/lib/neo4j/index/index.rb +0 -39
- data/lib/neo4j/index/indexer.rb +0 -341
- data/lib/neo4j/index/indexer_registry.rb +0 -68
- data/lib/neo4j/index/lucene_query.rb +0 -256
- data/lib/neo4j/load.rb +0 -25
- data/lib/neo4j/migrations/class_methods.rb +0 -110
- data/lib/neo4j/migrations/extensions.rb +0 -58
- data/lib/neo4j/migrations/lazy_node_mixin.rb +0 -41
- data/lib/neo4j/migrations/migration.rb +0 -112
- data/lib/neo4j/migrations/migrations.rb +0 -6
- data/lib/neo4j/migrations/node_mixin.rb +0 -80
- data/lib/neo4j/migrations/ref_node_wrapper.rb +0 -32
- data/lib/neo4j/model.rb +0 -4
- data/lib/neo4j/neo4j.rb +0 -216
- data/lib/neo4j/node.rb +0 -270
- data/lib/neo4j/node_mixin/class_methods.rb +0 -51
- data/lib/neo4j/node_mixin/node_mixin.rb +0 -141
- data/lib/neo4j/paginated.rb +0 -23
- data/lib/neo4j/property/class_methods.rb +0 -79
- data/lib/neo4j/property/property.rb +0 -111
- data/lib/neo4j/rails/mapping/property.rb +0 -183
- data/lib/neo4j/rails/rel_persistence.rb +0 -237
- data/lib/neo4j/relationship.rb +0 -239
- data/lib/neo4j/relationship_mixin/class_methods.rb +0 -36
- data/lib/neo4j/relationship_mixin/relationship_mixin.rb +0 -142
- data/lib/neo4j/relationship_set.rb +0 -58
- data/lib/neo4j/rels/rels.rb +0 -110
- data/lib/neo4j/rels/traverser.rb +0 -102
- data/lib/neo4j/rule/class_methods.rb +0 -201
- data/lib/neo4j/rule/event_listener.rb +0 -66
- data/lib/neo4j/rule/functions/count.rb +0 -43
- data/lib/neo4j/rule/functions/function.rb +0 -74
- data/lib/neo4j/rule/functions/functions.rb +0 -3
- data/lib/neo4j/rule/functions/sum.rb +0 -29
- data/lib/neo4j/rule/rule.rb +0 -150
- data/lib/neo4j/rule/rule_node.rb +0 -217
- data/lib/neo4j/to_java.rb +0 -31
- data/lib/neo4j/transaction.rb +0 -73
- data/lib/neo4j/traversal/filter_predicate.rb +0 -25
- data/lib/neo4j/traversal/prune_evaluator.rb +0 -14
- data/lib/neo4j/traversal/rel_expander.rb +0 -31
- data/lib/neo4j/traversal/traversal.rb +0 -141
- data/lib/neo4j/traversal/traverser.rb +0 -284
- data/lib/neo4j/type_converters/type_converters.rb +0 -288
data/lib/neo4j/relationship.rb
DELETED
@@ -1,239 +0,0 @@
|
|
1
|
-
# external neo4j dependencies
|
2
|
-
require 'neo4j/property/property'
|
3
|
-
require 'neo4j/index/index'
|
4
|
-
require 'neo4j/equal'
|
5
|
-
require 'neo4j/load'
|
6
|
-
require 'neo4j/to_java'
|
7
|
-
|
8
|
-
module Neo4j
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
# A relationship between two nodes in the graph. A relationship has a start node, an end node and a type.
|
13
|
-
# You can attach properties to relationships with the API specified in Neo4j::JavaPropertyMixin.
|
14
|
-
#
|
15
|
-
# Relationship are created by invoking the << operator on the rels method on the node as follow:
|
16
|
-
# node.outgoing(:friends) << other_node << yet_another_node
|
17
|
-
#
|
18
|
-
# or using the Neo4j::Relationship#new method (which does the same thing):
|
19
|
-
# rel = Neo4j::Relationship.new(:friends, node, other_node)
|
20
|
-
#
|
21
|
-
# The fact that the relationship API gives meaning to start and end nodes implicitly means that all relationships have a direction.
|
22
|
-
# In the example above, rel would be directed from node to otherNode.
|
23
|
-
# 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:
|
24
|
-
#
|
25
|
-
# a = Neo4j::Node.new
|
26
|
-
# b = Neo4j::Node.new
|
27
|
-
# rel = Neo4j::Relationship.new(:some_type, a, b)
|
28
|
-
# # Now we have: (a) --- REL_TYPE ---> (b)
|
29
|
-
#
|
30
|
-
# rel.start_node # => a
|
31
|
-
# rel.end_node # => b
|
32
|
-
#
|
33
|
-
# Furthermore, Neo4j guarantees that a relationship is never "hanging freely,"
|
34
|
-
# i.e. start_node, end_node and other_node are guaranteed to always return valid, non-null nodes.
|
35
|
-
#
|
36
|
-
# === Wrapping
|
37
|
-
#
|
38
|
-
# Notice that the Neo4j::Relationship.new does not create a Ruby object. Instead, it returns a Java
|
39
|
-
# org.neo4j.graphdb.Relationship object which has been modified to feel more rubyish (like Neo4j::Node).
|
40
|
-
#
|
41
|
-
# === See also
|
42
|
-
# * Neo4j::RelationshipMixin if you want to wrap a relationship with your own Ruby class.
|
43
|
-
# * http://api.neo4j.org/1.4/org/neo4j/graphdb/Relationship.html
|
44
|
-
#
|
45
|
-
# === Included Mixins
|
46
|
-
# * Neo4j::Property
|
47
|
-
# * Neo4j::Equal
|
48
|
-
#
|
49
|
-
# (Those mixin are actually not included in the Neo4j::Relationship but instead directly included in the java class org.neo4j.kernel.impl.core.RelationshipProxy)
|
50
|
-
#
|
51
|
-
class Relationship
|
52
|
-
extend Neo4j::Index::ClassMethods
|
53
|
-
|
54
|
-
self.rel_indexer self
|
55
|
-
|
56
|
-
class << self
|
57
|
-
include Neo4j::Load
|
58
|
-
include Neo4j::ToJava
|
59
|
-
|
60
|
-
|
61
|
-
##
|
62
|
-
# :method: start_node
|
63
|
-
#
|
64
|
-
# Returns the start node of this relationship
|
65
|
-
|
66
|
-
|
67
|
-
##
|
68
|
-
# :method: end_node
|
69
|
-
#
|
70
|
-
# Returns the end node of this relationship
|
71
|
-
|
72
|
-
##
|
73
|
-
# :method: other_node
|
74
|
-
#
|
75
|
-
# A convenience operation that, given a node that is attached to this relationship, returns the other node.
|
76
|
-
# For example if node is a start node, the end node will be returned, and vice versa.
|
77
|
-
# This is a very convenient operation when you're manually traversing the node space by invoking one of the #rels
|
78
|
-
# method on a node. For example, to get the node "at the other end" of a relationship, use the following:
|
79
|
-
#
|
80
|
-
# end_node = node.rels.first.other_node(node)
|
81
|
-
#
|
82
|
-
# This operation will throw a runtime exception if node is neither this relationship's start node nor its end node.
|
83
|
-
#
|
84
|
-
# === Parameters
|
85
|
-
#
|
86
|
-
# node :: the node that we don't want to return
|
87
|
-
|
88
|
-
|
89
|
-
##
|
90
|
-
# :method: del
|
91
|
-
#
|
92
|
-
# Deletes this relationship. Invoking any methods on this relationship after delete() has returned is invalid and will lead t
|
93
|
-
|
94
|
-
# :method rel_type
|
95
|
-
#
|
96
|
-
# Returns the type of this relationship.
|
97
|
-
# A relationship's type is an immutable attribute that is specified at Relationship creation.
|
98
|
-
# The relationship type is othen used when traversing nodes, example finding all the
|
99
|
-
# outgoing nodes of relationship type :friends
|
100
|
-
#
|
101
|
-
# node.outgoing(:friends)
|
102
|
-
|
103
|
-
# Returns a org.neo4j.graphdb.Relationship java object (!)
|
104
|
-
# Will trigger a event that the relationship was created.
|
105
|
-
#
|
106
|
-
# === Parameters
|
107
|
-
# type :: the type of relationship
|
108
|
-
# from_node :: the start node of this relationship
|
109
|
-
# end_node :: the end node of this relationship
|
110
|
-
# props :: optional properties for the created relationship
|
111
|
-
#
|
112
|
-
# === Returns
|
113
|
-
# org.neo4j.graphdb.Relationship java object
|
114
|
-
#
|
115
|
-
# === Examples
|
116
|
-
#
|
117
|
-
# Neo4j::Relationship.new :friend, node1, node2, :since => '2001-01-02', :status => 'okey'
|
118
|
-
#
|
119
|
-
def new(type, start_node, end_node, props=nil)
|
120
|
-
java_type = type_to_java(type)
|
121
|
-
rel = start_node._java_node.create_relationship_to(end_node._java_node, java_type)
|
122
|
-
props.each_pair {|k,v| rel[k] = v} if props
|
123
|
-
rel
|
124
|
-
end
|
125
|
-
|
126
|
-
# create is the same as new
|
127
|
-
alias_method :create, :new
|
128
|
-
|
129
|
-
# Loads a relationship or wrapped relationship given a native java relationship or an id.
|
130
|
-
# If there is a Ruby wrapper for the node then it will create a Ruby object that will
|
131
|
-
# wrap the java node (see Neo4j::RelationshipMixin).
|
132
|
-
#
|
133
|
-
# If the relationship does not exist it will return nil
|
134
|
-
#
|
135
|
-
def load(rel_id, db = Neo4j.started_db)
|
136
|
-
rel = _load(rel_id, db)
|
137
|
-
return nil if rel.nil?
|
138
|
-
rel.wrapper
|
139
|
-
end
|
140
|
-
|
141
|
-
# Same as load but does not return the node as a wrapped Ruby object.
|
142
|
-
#
|
143
|
-
def _load(rel_id, db = Neo4j.started_db)
|
144
|
-
return nil if rel_id.nil?
|
145
|
-
rel = db.graph.get_relationship_by_id(rel_id.to_i)
|
146
|
-
rel.hasProperty('_classname') # since we want a IllegalStateException which is otherwise not triggered
|
147
|
-
rel
|
148
|
-
rescue java.lang.IllegalStateException
|
149
|
-
nil # the node has been deleted
|
150
|
-
rescue org.neo4j.graphdb.NotFoundException
|
151
|
-
nil
|
152
|
-
end
|
153
|
-
|
154
|
-
def extend_java_class(java_clazz) #:nodoc:
|
155
|
-
java_clazz.class_eval do
|
156
|
-
include Neo4j::Property
|
157
|
-
include Neo4j::Equal
|
158
|
-
|
159
|
-
alias_method :_end_node, :getEndNode
|
160
|
-
alias_method :_start_node, :getStartNode
|
161
|
-
alias_method :_other_node, :getOtherNode
|
162
|
-
|
163
|
-
|
164
|
-
# Deletes the relationship between the start and end node
|
165
|
-
#
|
166
|
-
# May raise an exception if delete was unsuccessful.
|
167
|
-
#
|
168
|
-
# ==== Returns
|
169
|
-
# nil
|
170
|
-
#
|
171
|
-
def del
|
172
|
-
delete
|
173
|
-
end
|
174
|
-
|
175
|
-
def end_node # :nodoc:
|
176
|
-
getEndNode.wrapper
|
177
|
-
end
|
178
|
-
|
179
|
-
def start_node # :nodoc:
|
180
|
-
getStartNode.wrapper
|
181
|
-
end
|
182
|
-
|
183
|
-
def other_node(node) # :nodoc:
|
184
|
-
getOtherNode(node._java_node).wrapper
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
# same as _java_rel
|
189
|
-
# Used so that we have same method for both relationship and nodes
|
190
|
-
def wrapped_entity
|
191
|
-
self
|
192
|
-
end
|
193
|
-
|
194
|
-
def _java_rel
|
195
|
-
self
|
196
|
-
end
|
197
|
-
|
198
|
-
|
199
|
-
# Returns true if the relationship exists
|
200
|
-
def exist?
|
201
|
-
Neo4j::Relationship.exist?(self)
|
202
|
-
end
|
203
|
-
|
204
|
-
# Loads the Ruby wrapper for this node
|
205
|
-
# If there is no _classname property for this node then it will simply return itself.
|
206
|
-
# Same as Neo4j::Node.load_wrapper(node)
|
207
|
-
def wrapper
|
208
|
-
self.class.wrapper(self)
|
209
|
-
end
|
210
|
-
|
211
|
-
|
212
|
-
# Returns the relationship name
|
213
|
-
#
|
214
|
-
# ==== Example
|
215
|
-
# a = Neo4j::Node.new
|
216
|
-
# a.outgoing(:friends) << Neo4j::Node.new
|
217
|
-
# a.rels.first.rel_type # => 'friends'
|
218
|
-
#
|
219
|
-
def rel_type
|
220
|
-
getType().name()
|
221
|
-
end
|
222
|
-
|
223
|
-
def class
|
224
|
-
Neo4j::Relationship
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
Neo4j::Relationship.extend_java_class(org.neo4j.kernel.impl.core.RelationshipProxy)
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module RelationshipMixin
|
3
|
-
module ClassMethods
|
4
|
-
def load_wrapper(rel)
|
5
|
-
wrapped_rel = self.orig_new
|
6
|
-
wrapped_rel.init_on_load(rel)
|
7
|
-
wrapped_rel
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
# Creates a relationship between given nodes.
|
12
|
-
#
|
13
|
-
# You can use two callback method to initialize the relationship
|
14
|
-
# init_on_load:: this method is called when the relationship is loaded from the database
|
15
|
-
# init_on_create:: called when the relationship is created, will be provided with the same argument as the new method
|
16
|
-
#
|
17
|
-
# ==== Parameters (when creating a new relationship in db)
|
18
|
-
# type:: the key and value to be set
|
19
|
-
# from_node:: create relationship from this node
|
20
|
-
# to_node:: create relationship to this node
|
21
|
-
# props:: optional hash of properties to initialize the create relationship with
|
22
|
-
#
|
23
|
-
def new(*args)
|
24
|
-
type, from_node, to_node = args
|
25
|
-
rel = Neo4j::Relationship.create(type, from_node, to_node)
|
26
|
-
wrapped_rel = super()
|
27
|
-
Neo4j::IdentityMap.add(rel, wrapped_rel)
|
28
|
-
wrapped_rel.init_on_load(rel)
|
29
|
-
wrapped_rel.init_on_create(*args)
|
30
|
-
wrapped_rel
|
31
|
-
end
|
32
|
-
|
33
|
-
alias_method :create, :new
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,142 +0,0 @@
|
|
1
|
-
# external neo4j dependencies
|
2
|
-
require 'neo4j/index/index'
|
3
|
-
require 'neo4j/property/property'
|
4
|
-
|
5
|
-
# internal dependencies
|
6
|
-
require 'neo4j/relationship_mixin/class_methods'
|
7
|
-
|
8
|
-
|
9
|
-
module Neo4j
|
10
|
-
|
11
|
-
# Use this mixin to wrap Neo4j Relationship Java object.
|
12
|
-
# This mixin is similar to Neo4j::NodeMixin which wraps Neo4j::Node Java objects.
|
13
|
-
#
|
14
|
-
# ==== Instance Methods, Mixins
|
15
|
-
# * Neo4j::Index :: relationships can also be indexed just like nodes
|
16
|
-
# *
|
17
|
-
# ==== Class Methods, Mixins
|
18
|
-
# * Neo4j::Index::ClassMethods :: for declaration for keeping lucene index and neo4j property in sync
|
19
|
-
# * Neo4j::Property::ClassMethods :: for declaration of convenience accessors of property
|
20
|
-
#
|
21
|
-
module RelationshipMixin
|
22
|
-
extend Forwardable
|
23
|
-
include Neo4j::Index
|
24
|
-
|
25
|
-
def_delegators :@_java_rel, :[]=, :[], :property?, :props, :attributes, :update, :neo_id, :id, :to_param, :getId,
|
26
|
-
:equal?, :eql?, :==, :delete, :getStartNode, :getEndNode, :getOtherNode, :exist?
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# --------------------------------------------------------------------------
|
31
|
-
# Initialization methods
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
# Init this node with the specified java neo4j relationship.
|
36
|
-
#
|
37
|
-
def init_on_load(java_rel) # :nodoc:
|
38
|
-
@_java_rel = java_rel
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
# Creates a new node and initialize with given properties.
|
43
|
-
#
|
44
|
-
def init_on_create(*args) # :nodoc:
|
45
|
-
type, from_node, to_node, props = args
|
46
|
-
self[:_classname] = self.class.to_s
|
47
|
-
if props.respond_to?(:each_pair)
|
48
|
-
props.each_pair { |k, v| respond_to?("#{k}=") ? self.send("#{k}=", v) : @_java_rel[k] = v }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
# --------------------------------------------------------------------------
|
54
|
-
# Instance Methods
|
55
|
-
#
|
56
|
-
|
57
|
-
# Returns the org.neo4j.graphdb.Relationship wrapped object
|
58
|
-
def _java_rel
|
59
|
-
@_java_rel
|
60
|
-
end
|
61
|
-
|
62
|
-
def _java_entity
|
63
|
-
@_java_rel
|
64
|
-
end
|
65
|
-
|
66
|
-
# Returns the end node of this relationship
|
67
|
-
def end_node
|
68
|
-
id = getEndNode.getId
|
69
|
-
Neo4j::Node.load(id)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns the start node of this relationship
|
73
|
-
def start_node
|
74
|
-
id = getStartNode.getId
|
75
|
-
Neo4j::Node.load(id)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Deletes this relationship
|
79
|
-
def del
|
80
|
-
delete
|
81
|
-
end
|
82
|
-
|
83
|
-
def exist?
|
84
|
-
Neo4j::Relationship.exist?(self)
|
85
|
-
end
|
86
|
-
|
87
|
-
# A convenience operation that, given a node that is attached to this relationship, returns the other node.
|
88
|
-
# For example if node is a start node, the end node will be returned, and vice versa.
|
89
|
-
# This is a very convenient operation when you're manually traversing the node space by invoking one of the #rels operations on node.
|
90
|
-
#
|
91
|
-
# This operation will throw a runtime exception if node is neither this relationship's start node nor its end node.
|
92
|
-
#
|
93
|
-
# ==== Example
|
94
|
-
# For example, to get the node "at the other end" of a relationship, use the following:
|
95
|
-
# Node endNode = node.rel(:some_rel_type).other_node(node)
|
96
|
-
#
|
97
|
-
def other_node(node)
|
98
|
-
neo_node = node.respond_to?(:_java_node)? node._java_node : node
|
99
|
-
id = getOtherNode(neo_node).getId
|
100
|
-
Neo4j::Node.load(id)
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
# Returns the neo relationship type that this relationship is used in.
|
105
|
-
# (see java API org.neo4j.graphdb.Relationship#getType and org.neo4j.graphdb.RelationshipType)
|
106
|
-
#
|
107
|
-
# ==== Returns
|
108
|
-
# the relationship type (of type Symbol)
|
109
|
-
#
|
110
|
-
def relationship_type
|
111
|
-
@_java_rel.getType.name.to_sym
|
112
|
-
end
|
113
|
-
|
114
|
-
# --------------------------------------------------------------------------
|
115
|
-
# Class Methods
|
116
|
-
#
|
117
|
-
|
118
|
-
class << self
|
119
|
-
def included(c) # :nodoc:
|
120
|
-
c.instance_eval do
|
121
|
-
class << self
|
122
|
-
alias_method :orig_new, :new
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
c.class_inheritable_accessor :_decl_props
|
127
|
-
c._decl_props ||= {}
|
128
|
-
|
129
|
-
c.extend ClassMethods
|
130
|
-
c.extend Neo4j::Property::ClassMethods
|
131
|
-
c.extend Neo4j::Index::ClassMethods
|
132
|
-
|
133
|
-
def c.inherited(subclass)
|
134
|
-
subclass.rel_indexer self
|
135
|
-
super
|
136
|
-
end
|
137
|
-
|
138
|
-
c.rel_indexer c
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
# == Represents a set of relationships.
|
3
|
-
# See Neo4j::EventHandler
|
4
|
-
class RelationshipSet
|
5
|
-
def initialize(size=0)
|
6
|
-
@relationship_type_set = java.util.HashSet.new(size)
|
7
|
-
@relationship_set = java.util.HashSet.new(size)
|
8
|
-
@relationship_map = java.util.HashMap.new(size)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Adds a relationship to the set
|
12
|
-
def add(rel)
|
13
|
-
@relationship_type_set.add(RelationshipSetEntry.new(rel.getEndNode().getId(),rel.rel_type))
|
14
|
-
relationships(rel.getEndNode().getId()) << rel
|
15
|
-
@relationship_set.add(rel.getId)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Returns a collection of relationships where the node with the specified end node id is the end node.
|
19
|
-
def relationships(end_node_id)
|
20
|
-
@relationship_map.get(end_node_id) || add_list(end_node_id)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Returns true if the specified relationship is in the set
|
24
|
-
def contains_rel?(rel)
|
25
|
-
@relationship_set.contains(rel.getId)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns true if a relationship with the specified end_node_id and relationship_type is present in the set.
|
29
|
-
def contains?(end_node_id,relationship_type)
|
30
|
-
@relationship_type_set.contains(RelationshipSetEntry.new(end_node_id,relationship_type))
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
def add_list(node_id)
|
35
|
-
@relationship_map.put(node_id,[])
|
36
|
-
@relationship_map.get(node_id)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class RelationshipSetEntry
|
41
|
-
attr_accessor :nodeid, :relationship_type
|
42
|
-
def initialize(nodeid,relationship_type)
|
43
|
-
@nodeid,@relationship_type = nodeid.to_s, relationship_type.to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
def ==(o)
|
47
|
-
eql?(o)
|
48
|
-
end
|
49
|
-
|
50
|
-
def eql?(other)
|
51
|
-
@nodeid == other.nodeid && @relationship_type == other.relationship_type
|
52
|
-
end
|
53
|
-
|
54
|
-
def hash
|
55
|
-
3 * @nodeid.hash + @relationship_type.hash
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|