neo4j-core 3.0.0.alpha.18 → 3.0.0.alpha.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 189f7b0b7187d44d8f5825e6747c033bdba18380
4
- data.tar.gz: d6748e42f17f0cd18d20009378e2101164df7d5b
3
+ metadata.gz: 99c353a80ee0078fb684f74860c6b9adab86f81a
4
+ data.tar.gz: 5164eb9d290c70506f2e38c8e70952b59e058b0b
5
5
  SHA512:
6
- metadata.gz: b35a530b4637e5732589a0689a4125f5727b7ece75e4d2ba4c5efe45b1f4526a824bd3578a5510745c748b6a20a17dd563a96fbec2f3cfc6d49ad9bf0e4b8135
7
- data.tar.gz: 5127606c4d29c68fe05ad77f79f0614dd16aa3e4faad3c025c7c821a96c8e2f2e643dd6faf9301cf5515362f96619d56b969a639c78dc42e539996556e6476dc
6
+ metadata.gz: ff3c176237a7fe786532cee32b922fcf6e239c9493bf3a64b0da3adf38d4e73941948cad014bcb486aab6ddfb6ece763b11cc14e65e89b354504d520d9d513bf
7
+ data.tar.gz: c4a5a1e0b1597f5a0f12ad4a88d8b13f730429101552a778f99583efbe3eddabec83f6964fea15193084e1da7bbc5e7839a2e9e09df2539843bc3b9d017efcac
data/Gemfile CHANGED
@@ -9,12 +9,13 @@ gem 'zip'
9
9
 
10
10
  group 'development' do
11
11
  gem 'yard'
12
+ gem 'simplecov'
12
13
  # gem 'pry'
13
14
  end
14
15
 
15
16
  group 'test' do
16
17
  gem "rake", ">= 0.8.7"
17
- gem "rspec", "~> 2.8"
18
+ gem "rspec", "~> 3.0"
18
19
  gem 'rspec-its'
19
20
  end
20
21
 
data/README.md CHANGED
@@ -42,7 +42,7 @@ require 'neo4j/tasks/neo4j_server'
42
42
 
43
43
  Install and start neo4j by typing:
44
44
  ```
45
- rake neo4j:install[community-2.1.1]
45
+ rake neo4j:install[community-2.1.3]
46
46
  rake neo4j:start
47
47
  ```
48
48
 
@@ -61,6 +61,7 @@ No need to start the server since it is embedded.
61
61
  * [Neo4j::Relationship](http://www.rubydoc.info/github/andreasronge/neo4j-core/Neo4j/Relationship)
62
62
  * [Neo4j::Session](http://www.rubydoc.info/github/andreasronge/neo4j-core/Neo4j/Session)
63
63
  * [Neo4j::Label](http://www.rubydoc.info/github/andreasronge/neo4j-core/Neo4j/Label)
64
+ * [Neo4j::Transaction](http://www.rubydoc.info/github/andreasronge/neo4j-core/Neo4j/Transaction)
64
65
  * [Neo4j::Query](Neo4j/Query.html)
65
66
 
66
67
  See also [Neo4j Docs](http://docs.neo4j.org/)
@@ -155,7 +155,7 @@ module Neo4j::Core
155
155
  def each
156
156
  response = self.response
157
157
  if response.is_a?(Neo4j::Server::CypherResponse)
158
- self.response.to_node_enumeration
158
+ response.to_node_enumeration
159
159
  else
160
160
  Neo4j::Embedded::ResultWrapper.new(response, self.to_cypher)
161
161
  end.each {|object| yield object }
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = "3.0.0.alpha.18"
3
+ VERSION = "3.0.0.alpha.19"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ module Neo4j
2
+ module Core
3
+ VERSION = "3.0.0.alpha.16"
4
+ end
5
+ end
@@ -8,6 +8,7 @@ require 'neo4j-embedded/embedded_label'
8
8
  require 'neo4j-embedded/embedded_node'
9
9
  require 'neo4j-embedded/embedded_relationship'
10
10
  require 'neo4j-embedded/embedded_label'
11
+ require 'neo4j-embedded/embedded_transaction'
11
12
  require 'neo4j-embedded/cypher_response'
12
13
 
13
14
  # TODO replace this with https://github.com/intridea/hashie gem
@@ -0,0 +1,85 @@
1
+ module Neo4j::Embedded
2
+
3
+ # Wraps the Cypher query result.
4
+ # Loads the node and relationships wrapper if possible and use symbol as column keys.
5
+ # This is typically used in the native neo4j bindings since result does is not a Ruby enumerable with symbols as keys.
6
+ # @note The result is a once forward read only Enumerable, work if you need to read the result twice - use #to_a
7
+ #
8
+ class ResultWrapper
9
+ class ResultsAlreadyConsumedException < Exception;
10
+ end
11
+
12
+ include Enumerable
13
+
14
+ # @return the original result from the Neo4j Cypher Engine, once forward read only !
15
+ attr_reader :source
16
+
17
+ def initialize(source, map_return_procs, query)
18
+ @source = source
19
+ @unread = true
20
+ @map_return_procs = map_return_procs
21
+ @query = query
22
+ end
23
+
24
+ def to_s
25
+ @query
26
+ end
27
+
28
+ # @return [Array<Symbol>] the columns in the query result
29
+ def columns
30
+ @source.columns.map { |x| x.to_sym }
31
+ end
32
+
33
+ # for the Enumerable contract
34
+ def each(&block)
35
+ raise ResultsAlreadyConsumedException unless @unread
36
+
37
+ if (block)
38
+ case @map_return_procs
39
+ when NilClass then
40
+ each_no_mapping &block
41
+ when Hash then
42
+ each_multi_column_mapping &block
43
+ else
44
+ each_single_column_mapping &block
45
+ end
46
+ else
47
+ Enumerator.new(self)
48
+ end
49
+ end
50
+
51
+
52
+ private
53
+
54
+ def each_no_mapping
55
+ @source.each do |row|
56
+ hash = {}
57
+ row.each do |key, value|
58
+ out[key.to_sym] = value
59
+ end
60
+ yield hash
61
+ end
62
+ end
63
+
64
+ def each_multi_column_mapping
65
+ @source.each do |row|
66
+ hash = {}
67
+ row.each do |key, value|
68
+ k = key.to_sym
69
+ proc = @map_return_procs[k]
70
+ hash[k] = proc ? proc.call(value) : value
71
+ end
72
+ yield hash
73
+ end
74
+ end
75
+
76
+ def each_single_column_mapping
77
+ @source.each do |row|
78
+ result = @map_return_procs.call(row.values.first)
79
+ yield result
80
+ end
81
+ end
82
+
83
+ end
84
+ end
85
+
@@ -0,0 +1,201 @@
1
+ module Neo4j::Embedded
2
+ class RelsIterator
3
+ include Enumerable
4
+ extend Neo4j::Core::TxMethods
5
+
6
+ def initialize(node, match)
7
+ @node = node
8
+ @match = match
9
+ end
10
+
11
+ def inspect
12
+ "Enumerable<Neo4j::Relationship>"
13
+ end
14
+
15
+ def each(&block)
16
+ @node._rels(@match).each {|r| block.call(r.wrapper)}
17
+ end
18
+ tx_methods :each
19
+
20
+ def empty?
21
+ first == nil
22
+ end
23
+
24
+ end
25
+
26
+ class NodesIterator
27
+ include Enumerable
28
+ extend Neo4j::Core::TxMethods
29
+
30
+ def initialize(node, match)
31
+ @node = node
32
+ @match = match
33
+ end
34
+
35
+ def each(&block)
36
+ @node._rels(@match).each {|r| block.call(r.other_node(@node))}
37
+ end
38
+ tx_methods :each
39
+
40
+ def empty?
41
+ first == nil
42
+ end
43
+
44
+ end
45
+
46
+ class EmbeddedNode
47
+ class << self
48
+ # This method is used to extend a Java Neo4j class so that it includes the same mixins as this class.
49
+ def extend_java_class(java_clazz)
50
+ java_clazz.class_eval do
51
+ include Neo4j::Embedded::Property
52
+ include Neo4j::EntityEquality
53
+ extend Neo4j::Core::TxMethods
54
+
55
+ def inspect
56
+ "EmbeddedNode neo_id: #{neo_id}"
57
+ end
58
+
59
+ def exist?
60
+ !!graph_database.get_node_by_id(neo_id)
61
+ rescue Java::OrgNeo4jGraphdb.NotFoundException
62
+ nil
63
+ end
64
+ tx_methods :exist?
65
+
66
+ def labels
67
+ _labels.iterator.map{|x| x.name.to_sym}
68
+ end
69
+ tx_methods :labels
70
+
71
+ alias_method :_labels, :getLabels
72
+
73
+ def _java_label(label_name)
74
+ Java::OrgNeo4jGraphdb.DynamicLabel.label(label_name)
75
+ end
76
+
77
+
78
+ def _add_label(*label_name)
79
+ label_name.each do |name|
80
+ addLabel(_java_label(name))
81
+ end
82
+ end
83
+
84
+ alias_method :add_label, :_add_label
85
+ tx_methods :add_label
86
+
87
+ def _remove_label(*label_name)
88
+ label_name.each do |name|
89
+ removeLabel(_java_label(name))
90
+ end
91
+ end
92
+
93
+ alias_method :remove_label, :_remove_label
94
+ tx_methods :remove_label
95
+
96
+ def set_label(*label_names)
97
+ label_as_symbols = label_names.map(&:to_sym)
98
+ to_keep = labels & label_as_symbols
99
+ to_remove = labels - to_keep
100
+ _remove_label(*to_remove)
101
+ to_add = label_as_symbols - to_keep
102
+ _add_label(*to_add)
103
+ end
104
+ tx_methods :set_label
105
+
106
+ def del
107
+ _rels.each { |r| r.del }
108
+ delete
109
+ nil
110
+ end
111
+ tx_methods :del
112
+
113
+ def create_rel(type, other_node, props = nil)
114
+ rel = create_relationship_to(other_node.neo4j_obj, ToJava.type_to_java(type))
115
+ props.each_pair { |k, v| rel[k] = v } if props
116
+ rel
117
+ end
118
+ tx_methods :create_rel
119
+
120
+
121
+ def rels(match={})
122
+ RelsIterator.new(self, match)
123
+ end
124
+
125
+ def nodes(match={})
126
+ NodesIterator.new(self, match)
127
+ end
128
+
129
+ def node(match={})
130
+ rel = _rel(match)
131
+ rel && rel.other_node(self).wrapper
132
+ end
133
+ tx_methods :node
134
+
135
+ def rel?(match={})
136
+ _rels(match).has_next
137
+ end
138
+ tx_methods :rel?
139
+
140
+ def rel(match={})
141
+ _rel(match)
142
+ end
143
+ tx_methods :rel
144
+
145
+ def _rel(match={})
146
+ dir = match[:dir] || :both
147
+ rel_type = match[:type]
148
+
149
+ rel = if rel_type
150
+ get_single_relationship(ToJava.type_to_java(rel_type), ToJava.dir_to_java(dir))
151
+ else
152
+ iter = get_relationships(ToJava.dir_to_java(dir)).iterator
153
+ if (iter.has_next)
154
+ first = iter.next
155
+ raise "Expected to only find one relationship from node #{neo_id} matching #{match.inspect}" if iter.has_next
156
+ first
157
+ end
158
+ end
159
+
160
+ between_id = match[:between] && match[:between].neo_id
161
+
162
+ if (rel && between_id)
163
+ rel.other_node(self).neo_id == between_id ? rel : nil
164
+ else
165
+ rel
166
+ end
167
+ end
168
+
169
+ def _rels(match={})
170
+ dir = match[:dir] || :both
171
+ rel_type = match[:type]
172
+
173
+ rels = if rel_type
174
+ get_relationships(ToJava.type_to_java(rel_type), ToJava.dir_to_java(dir)).iterator
175
+ else
176
+ get_relationships(ToJava.dir_to_java(dir)).iterator
177
+ end
178
+
179
+ between_id = match[:between] && match[:between].neo_id
180
+
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
186
+
187
+ end
188
+
189
+ def class
190
+ Neo4j::Node
191
+ end
192
+
193
+ include Neo4j::Node::Wrapper
194
+ end
195
+ end
196
+ end
197
+
198
+ extend_java_class(Java::OrgNeo4jKernelImplCore::NodeProxy)
199
+ end
200
+
201
+ end
@@ -26,6 +26,8 @@ module Neo4j::Embedded
26
26
  _start_node.wrapper
27
27
  end
28
28
  tx_methods :start_node
29
+ alias_method :_start_node_id, :start_node
30
+ tx_methods :_start_node_id
29
31
 
30
32
  def _start_node
31
33
  getStartNode
@@ -54,6 +56,8 @@ module Neo4j::Embedded
54
56
  _end_node.wrapper
55
57
  end
56
58
  tx_methods :end_node
59
+ alias_method :_end_node_id, :end_node
60
+ tx_methods :_end_node_id
57
61
 
58
62
  def _end_node
59
63
  getEndNode
@@ -0,0 +1,62 @@
1
+ module Neo4j::Embedded
2
+ class EmbeddedRelationship
3
+ class << self
4
+ # This method is used to extend a Java Neo4j class so that it includes the same mixins as this class.
5
+ def extend_java_class(java_clazz)
6
+ java_clazz.class_eval do
7
+ include Neo4j::Embedded::Property
8
+ include Neo4j::EntityEquality
9
+ include Neo4j::Relationship::Wrapper
10
+ extend Neo4j::Core::TxMethods
11
+
12
+ alias_method :_other_node, :getOtherNode
13
+
14
+ def exist?
15
+ !!graph_database.get_relationship_by_id(neo_id)
16
+ rescue Java::OrgNeo4jGraphdb.NotFoundException
17
+ nil
18
+ end
19
+ tx_methods :exist?
20
+
21
+ def start_node
22
+ _start_node.wrapper
23
+ end
24
+ tx_methods :start_node
25
+
26
+ def _start_node
27
+ getStartNode
28
+ end
29
+
30
+ def rel_type
31
+ getType().name().to_sym
32
+ end
33
+
34
+ def del
35
+ delete
36
+ end
37
+ tx_methods :del
38
+
39
+ def other_node(n)
40
+ _other_node(n.neo4j_obj).wrapper
41
+ end
42
+ tx_methods :other_node
43
+
44
+ def end_node
45
+ _end_node.wrapper
46
+ end
47
+ tx_methods :end_node
48
+
49
+ def _end_node
50
+ getEndNode
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+
57
+ extend_java_class(Java::OrgNeo4jKernelImplCore::RelationshipProxy)
58
+
59
+ end
60
+
61
+
62
+ end