neo4j-core 5.1.14 → 6.0.0.alpha.1

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