neo4j-core 5.1.14 → 6.0.0.alpha.1
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.
- checksums.yaml +4 -4
- data/lib/neo4j-core.rb +1 -1
- data/lib/neo4j-core/helpers.rb +6 -0
- data/lib/neo4j-core/query.rb +88 -40
- data/lib/neo4j-core/query_clauses.rb +67 -67
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-embedded/embedded_label.rb +16 -14
- data/lib/neo4j-embedded/embedded_node.rb +115 -113
- data/lib/neo4j-embedded/embedded_relationship.rb +53 -51
- data/lib/neo4j-embedded/embedded_session.rb +5 -14
- data/lib/neo4j-embedded/label.rb +2 -1
- data/lib/neo4j-server/cypher_label.rb +8 -7
- data/lib/neo4j-server/cypher_relationship.rb +1 -1
- data/lib/neo4j-server/cypher_response.rb +3 -2
- data/lib/neo4j-server/cypher_transaction.rb +1 -6
- data/lib/neo4j-server/resource.rb +1 -1
- data/lib/neo4j/core/cypher_session.rb +28 -0
- data/lib/neo4j/core/cypher_session/adaptors.rb +108 -0
- data/lib/neo4j/core/cypher_session/adaptors/embedded.rb +81 -0
- data/lib/neo4j/core/cypher_session/adaptors/http.rb +159 -0
- data/lib/neo4j/core/cypher_session/responses.rb +27 -0
- data/lib/neo4j/core/cypher_session/responses/embedded.rb +77 -0
- data/lib/neo4j/core/cypher_session/responses/http.rb +104 -0
- data/lib/neo4j/core/cypher_session/result.rb +39 -0
- data/lib/neo4j/core/instrumentable.rb +36 -0
- data/lib/neo4j/core/node.rb +28 -0
- data/lib/neo4j/core/path.rb +15 -0
- data/lib/neo4j/core/relationship.rb +25 -0
- data/lib/neo4j/core/wrappable.rb +35 -0
- data/lib/neo4j/label.rb +7 -0
- data/lib/neo4j/session.rb +3 -3
- data/lib/neo4j/transaction.rb +1 -24
- data/neo4j-core.gemspec +2 -2
- metadata +22 -9
data/lib/neo4j-core/version.rb
CHANGED
@@ -15,29 +15,28 @@ module Neo4j
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def find_nodes(key = nil, value = nil)
|
18
|
-
iterator =
|
18
|
+
iterator = if key
|
19
|
+
@session.graph_db.find_nodes_by_label_and_property(as_java, key, value).iterator
|
20
|
+
else
|
21
|
+
ggo = Java::OrgNeo4jTooling::GlobalGraphOperations.at(@session.graph_db)
|
22
|
+
ggo.getAllNodesWithLabel(as_java).iterator
|
23
|
+
end
|
24
|
+
|
19
25
|
iterator.to_a.map(&:wrapper)
|
20
26
|
ensure
|
21
27
|
iterator && iterator.close
|
22
28
|
end
|
23
29
|
tx_methods :find_nodes
|
24
30
|
|
25
|
-
def _find_nodes(key = nil, value = nil)
|
26
|
-
if key
|
27
|
-
@session.graph_db.find_nodes_by_label_and_property(as_java, key, value).iterator
|
28
|
-
else
|
29
|
-
ggo = Java::OrgNeo4jTooling::GlobalGraphOperations.at(@session.graph_db)
|
30
|
-
ggo.getAllNodesWithLabel(as_java).iterator
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
31
|
def as_java
|
35
32
|
self.class.as_java(@name.to_s)
|
36
33
|
end
|
37
34
|
|
38
|
-
def create_index(
|
39
|
-
|
35
|
+
def create_index(property, options = {}, session = Neo4j::Session.current)
|
36
|
+
validate_index_options!(options)
|
37
|
+
index_creator = session.graph_db.schema.index_for(as_java)
|
40
38
|
# we can also use the PropertyConstraintCreator here
|
39
|
+
properties = property.is_a?(Array) ? property : [property]
|
41
40
|
properties.inject(index_creator) { |creator, key| creator.on(key.to_s) }.create
|
42
41
|
end
|
43
42
|
tx_methods :create_index
|
@@ -62,8 +61,10 @@ module Neo4j
|
|
62
61
|
tx_methods :uniqueness_constraints
|
63
62
|
|
64
63
|
|
65
|
-
def drop_index(
|
66
|
-
|
64
|
+
def drop_index(property, options = {}, session = Neo4j::Session.current)
|
65
|
+
validate_index_options!(options)
|
66
|
+
properties = property.is_a?(Array) ? property : [property]
|
67
|
+
session.graph_db.schema.indexes(as_java).each do |index_def|
|
67
68
|
# at least one match, TODO
|
68
69
|
keys = index_def.property_keys.map(&:to_sym)
|
69
70
|
index_def.drop if (properties - keys).count < properties.count
|
@@ -75,6 +76,7 @@ module Neo4j
|
|
75
76
|
def as_java(labels)
|
76
77
|
if labels.is_a?(Array)
|
77
78
|
return nil if labels.empty?
|
79
|
+
|
78
80
|
labels.inject([]) { |result, label| result << JAVA_CLASS.label(label.to_s) }.to_java(JAVA_CLASS)
|
79
81
|
else
|
80
82
|
JAVA_CLASS.label(labels.to_s)
|
@@ -49,152 +49,154 @@ module Neo4j
|
|
49
49
|
|
50
50
|
class EmbeddedNode < Neo4j::Node
|
51
51
|
class << self
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
52
|
+
if !Neo4j::Core::Config.using_new_session?
|
53
|
+
# This method is used to extend a Java Neo4j class so that it includes the same mixins as this class.
|
54
|
+
Java::OrgNeo4jKernelImplCore::NodeProxy.class_eval do
|
55
|
+
include Neo4j::Embedded::Property
|
56
|
+
include Neo4j::EntityEquality
|
57
|
+
include Neo4j::Core::ActiveEntity
|
58
|
+
extend Neo4j::Core::TxMethods
|
59
|
+
|
60
|
+
def inspect
|
61
|
+
"EmbeddedNode neo_id: #{neo_id}"
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
def exist?
|
65
|
+
!!graph_database.get_node_by_id(neo_id)
|
66
|
+
rescue Java::OrgNeo4jGraphdb.NotFoundException
|
67
|
+
false
|
68
|
+
end
|
69
|
+
tx_methods :exist?
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
def labels
|
72
|
+
_labels.iterator.map { |x| x.name.to_sym }
|
73
|
+
end
|
74
|
+
tx_methods :labels
|
74
75
|
|
75
|
-
|
76
|
+
alias_method :_labels, :getLabels
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
def _java_label(label_name)
|
79
|
+
Java::OrgNeo4jGraphdb.DynamicLabel.label(label_name)
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
def _add_label(*label_name)
|
83
|
+
label_name.each do |name|
|
84
|
+
addLabel(_java_label(name))
|
85
|
+
end
|
84
86
|
end
|
85
|
-
end
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
alias_method :add_label, :_add_label
|
89
|
+
tx_methods :add_label
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
def _remove_label(*label_name)
|
92
|
+
label_name.each do |name|
|
93
|
+
removeLabel(_java_label(name))
|
94
|
+
end
|
93
95
|
end
|
94
|
-
end
|
95
96
|
|
96
|
-
|
97
|
-
|
97
|
+
alias_method :remove_label, :_remove_label
|
98
|
+
tx_methods :remove_label
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
def set_label(*label_names)
|
101
|
+
label_as_symbols = label_names.map(&:to_sym)
|
102
|
+
to_keep = labels & label_as_symbols
|
103
|
+
to_remove = labels - to_keep
|
104
|
+
_remove_label(*to_remove)
|
105
|
+
to_add = label_as_symbols - to_keep
|
106
|
+
_add_label(*to_add)
|
107
|
+
end
|
108
|
+
tx_methods :set_label
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
110
|
+
def del
|
111
|
+
_rels.each(&:del)
|
112
|
+
delete
|
113
|
+
nil
|
114
|
+
end
|
115
|
+
tx_methods :del
|
116
|
+
tx_methods :delete
|
116
117
|
|
117
|
-
|
118
|
-
|
118
|
+
alias_method :destroy, :del
|
119
|
+
tx_methods :destroy
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
121
|
+
def create_rel(type, other_node, props = nil)
|
122
|
+
rel = create_relationship_to(other_node.neo4j_obj, ToJava.type_to_java(type))
|
123
|
+
props.each_pair { |k, v| rel[k] = v } if props
|
124
|
+
rel
|
125
|
+
end
|
126
|
+
tx_methods :create_rel
|
126
127
|
|
127
128
|
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
def rels(match = {})
|
130
|
+
RelsIterator.new(self, match)
|
131
|
+
end
|
131
132
|
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
def nodes(match = {})
|
134
|
+
NodesIterator.new(self, match)
|
135
|
+
end
|
135
136
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
def node(match = {})
|
138
|
+
rel = _rel(match)
|
139
|
+
rel && rel.other_node(self).wrapper
|
140
|
+
end
|
141
|
+
tx_methods :node
|
141
142
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
143
|
+
def rel?(match = {})
|
144
|
+
_rels(match).has_next
|
145
|
+
end
|
146
|
+
tx_methods :rel?
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
def rel(match = {})
|
149
|
+
_rel(match)
|
150
|
+
end
|
151
|
+
tx_methods :rel
|
151
152
|
|
152
|
-
|
153
|
-
|
153
|
+
def _rel(match = {})
|
154
|
+
dir, rel_type, between_id = _parse_match(match)
|
154
155
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
156
|
+
rel = if rel_type
|
157
|
+
get_single_relationship(rel_type, dir)
|
158
|
+
else
|
159
|
+
_get_single_relationship_by_dir(dir)
|
160
|
+
end
|
160
161
|
|
161
|
-
|
162
|
-
|
162
|
+
rel if !(rel && between_id) || rel.other_node(self).neo_id == between_id
|
163
|
+
end
|
163
164
|
|
164
|
-
|
165
|
-
|
165
|
+
def _get_single_relationship_by_dir(dir)
|
166
|
+
iter = get_relationships(dir).iterator
|
166
167
|
|
167
|
-
|
168
|
+
return nil if not iter.has_next
|
168
169
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
170
|
+
first = iter.next
|
171
|
+
fail "Expected to only find one relationship from node #{neo_id} matching #{match.inspect}" if iter.has_next
|
172
|
+
first
|
173
|
+
end
|
173
174
|
|
174
|
-
|
175
|
-
|
175
|
+
def _rels(match = {})
|
176
|
+
dir, rel_type, between_id = _parse_match(match)
|
176
177
|
|
177
|
-
|
178
|
-
|
178
|
+
args = rel_type ? [rel_type, dir] : [dir]
|
179
|
+
rels = get_relationships(*args).iterator
|
179
180
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
181
|
+
if between_id
|
182
|
+
rels.find_all { |r| r.end_node.neo_id == between_id || r.start_node.neo_id == between_id }
|
183
|
+
else
|
184
|
+
rels
|
185
|
+
end
|
184
186
|
end
|
185
|
-
end
|
186
187
|
|
187
|
-
|
188
|
-
|
188
|
+
def _parse_match(match)
|
189
|
+
::Neo4j::Node.validate_match!(match)
|
189
190
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
191
|
+
[
|
192
|
+
ToJava.dir_to_java(match[:dir] || :both),
|
193
|
+
ToJava.type_to_java(match[:type]),
|
194
|
+
match[:between] && match[:between].neo_id
|
195
|
+
]
|
196
|
+
end
|
196
197
|
|
197
|
-
|
198
|
+
include Neo4j::Node::Wrapper
|
199
|
+
end
|
198
200
|
end
|
199
201
|
end
|
200
202
|
end
|
@@ -2,69 +2,71 @@ module Neo4j
|
|
2
2
|
module Embedded
|
3
3
|
class EmbeddedRelationship
|
4
4
|
class << self
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
if !Neo4j::Core::Config.using_new_session?
|
6
|
+
Java::OrgNeo4jKernelImplCore::RelationshipProxy.class_eval do
|
7
|
+
include Neo4j::Embedded::Property
|
8
|
+
include Neo4j::EntityEquality
|
9
|
+
include Neo4j::Relationship::Wrapper
|
10
|
+
include Neo4j::Core::ActiveEntity
|
11
|
+
extend Neo4j::Core::TxMethods
|
11
12
|
|
12
|
-
|
13
|
+
alias_method :_other_node, :getOtherNode
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def exist?
|
16
|
+
!!graph_database.get_relationship_by_id(neo_id)
|
17
|
+
rescue Java::OrgNeo4jGraphdb.NotFoundException
|
18
|
+
false
|
19
|
+
end
|
20
|
+
tx_methods :exist?
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def inspect
|
23
|
+
"EmbeddedRelationship neo_id: #{neo_id}"
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def start_node
|
27
|
+
_start_node.wrapper
|
28
|
+
end
|
29
|
+
tx_methods :start_node
|
30
|
+
alias_method :_start_node_id, :start_node
|
31
|
+
tx_methods :_start_node_id
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def _start_node
|
34
|
+
getStartNode
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def rel_type
|
38
|
+
@_rel_type ||= _rel_type
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def _rel_type
|
42
|
+
getType.name.to_sym
|
43
|
+
end
|
44
|
+
tx_methods :rel_type
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def del
|
47
|
+
delete
|
48
|
+
end
|
49
|
+
tx_methods :del
|
50
|
+
tx_methods :delete
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
alias_method :destroy, :del
|
53
|
+
tx_methods :destroy
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
def other_node(n)
|
56
|
+
_other_node(n.neo4j_obj).wrapper
|
57
|
+
end
|
58
|
+
tx_methods :other_node
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
def end_node
|
61
|
+
_end_node.wrapper
|
62
|
+
end
|
63
|
+
tx_methods :end_node
|
64
|
+
alias_method :_end_node_id, :end_node
|
65
|
+
tx_methods :_end_node_id
|
65
66
|
|
66
|
-
|
67
|
-
|
67
|
+
def _end_node
|
68
|
+
getEndNode
|
69
|
+
end
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|