neo4j-core 3.1.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +7 -12
- data/README.md +7 -7
- data/lib/neo4j-core.rb +3 -2
- data/lib/neo4j-core/active_entity.rb +8 -10
- data/lib/neo4j-core/cypher_translator.rb +61 -59
- data/lib/neo4j-core/hash_with_indifferent_access.rb +31 -22
- data/lib/neo4j-core/helpers.rb +15 -17
- data/lib/neo4j-core/label.rb +7 -6
- data/lib/neo4j-core/query.rb +271 -268
- data/lib/neo4j-core/query_clauses.rb +371 -355
- data/lib/neo4j-core/query_find_in_batches.rb +26 -26
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-embedded.rb +2 -2
- data/lib/neo4j-embedded/cypher_response.rb +40 -41
- data/lib/neo4j-embedded/embedded_database.rb +21 -22
- data/lib/neo4j-embedded/embedded_ha_session.rb +13 -11
- data/lib/neo4j-embedded/embedded_impermanent_session.rb +9 -8
- data/lib/neo4j-embedded/embedded_label.rb +64 -70
- data/lib/neo4j-embedded/embedded_node.rb +68 -73
- data/lib/neo4j-embedded/embedded_relationship.rb +6 -13
- data/lib/neo4j-embedded/embedded_session.rb +128 -132
- data/lib/neo4j-embedded/embedded_transaction.rb +34 -33
- data/lib/neo4j-embedded/property.rb +84 -77
- data/lib/neo4j-embedded/to_java.rb +24 -23
- data/lib/neo4j-server.rb +1 -1
- data/lib/neo4j-server/cypher_authentication.rb +105 -103
- data/lib/neo4j-server/cypher_label.rb +25 -23
- data/lib/neo4j-server/cypher_node.rb +180 -177
- data/lib/neo4j-server/cypher_node_uncommited.rb +11 -9
- data/lib/neo4j-server/cypher_relationship.rb +101 -102
- data/lib/neo4j-server/cypher_response.rb +171 -170
- data/lib/neo4j-server/cypher_session.rb +209 -205
- data/lib/neo4j-server/cypher_transaction.rb +66 -48
- data/lib/neo4j-server/resource.rb +17 -22
- data/lib/neo4j/entity_equality.rb +3 -4
- data/lib/neo4j/label.rb +13 -16
- data/lib/neo4j/node.rb +30 -34
- data/lib/neo4j/property_container.rb +3 -3
- data/lib/neo4j/property_validator.rb +4 -5
- data/lib/neo4j/relationship.rb +17 -22
- data/lib/neo4j/session.rb +19 -21
- data/lib/neo4j/tasks/config_server.rb +2 -3
- data/lib/neo4j/tasks/neo4j_server.rake +82 -74
- data/lib/neo4j/transaction.rb +23 -22
- data/neo4j-core.gemspec +21 -16
- metadata +72 -2
@@ -1,41 +1,41 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module
|
1
|
+
module Neo4j
|
2
|
+
module Core
|
3
|
+
module QueryFindInBatches
|
4
|
+
def find_in_batches(node_var, prop_var, options = {})
|
5
|
+
invalid_keys = options.keys.map(&:to_sym) - [:batch_size]
|
6
|
+
fail ArgumentError, "Invalid keys: #{invalid_keys.join(', ')}" if not invalid_keys.empty?
|
3
7
|
|
4
|
-
|
5
|
-
invalid_keys = options.keys.map(&:to_sym) - [:batch_size]
|
6
|
-
raise ArgumentError, "Invalid keys: #{invalid_keys.join(', ')}" if not invalid_keys.empty?
|
8
|
+
batch_size = options.delete(:batch_size) || 1000
|
7
9
|
|
8
|
-
|
10
|
+
query = reorder(node_var => prop_var).limit(batch_size)
|
9
11
|
|
10
|
-
|
12
|
+
records = query.to_a
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
primary_key_offset = begin
|
17
|
-
records.last.send(node_var).send(prop_var)
|
18
|
-
rescue NoMethodError
|
19
|
-
begin
|
20
|
-
records.last.send(node_var)[prop_var.to_sym]
|
14
|
+
while records.any?
|
15
|
+
records_size = records.size
|
16
|
+
primary_key_offset = begin
|
17
|
+
records.last.send(node_var).send(prop_var)
|
21
18
|
rescue NoMethodError
|
22
|
-
|
19
|
+
begin
|
20
|
+
records.last.send(node_var)[prop_var.to_sym]
|
21
|
+
rescue NoMethodError
|
22
|
+
records.last.send("#{node_var}.#{prop_var}") # In case we're explicitly returning it
|
23
|
+
end
|
23
24
|
end
|
24
|
-
end
|
25
25
|
|
26
|
-
|
26
|
+
yield records
|
27
27
|
|
28
|
-
|
28
|
+
break if records_size < batch_size
|
29
29
|
|
30
|
-
|
30
|
+
records = query.where("#{node_var}.#{prop_var} > {primary_key_offset}").params(primary_key_offset: primary_key_offset).to_a
|
31
|
+
end
|
31
32
|
end
|
32
|
-
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def find_each(*args)
|
35
|
+
find_in_batches(*args) do |batch|
|
36
|
+
batch.each { |result| yield result }
|
37
|
+
end
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
|
-
|
data/lib/neo4j-core/version.rb
CHANGED
data/lib/neo4j-embedded.rb
CHANGED
@@ -11,5 +11,5 @@ require 'neo4j-embedded/embedded_label'
|
|
11
11
|
require 'neo4j-embedded/embedded_transaction'
|
12
12
|
require 'neo4j-embedded/cypher_response'
|
13
13
|
|
14
|
-
# TODO replace this with https://github.com/intridea/hashie gem
|
15
|
-
require 'neo4j-core/hash_with_indifferent_access'
|
14
|
+
# TODO: replace this with https://github.com/intridea/hashie gem
|
15
|
+
require 'neo4j-core/hash_with_indifferent_access'
|
@@ -1,53 +1,52 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
include Enumerable
|
1
|
+
module Neo4j
|
2
|
+
module Embedded
|
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
|
13
11
|
|
14
|
-
|
15
|
-
attr_reader :source
|
12
|
+
include Enumerable
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
@struct = Struct.new(*source.columns.to_a.map(&:to_sym))
|
20
|
-
@unread = true
|
21
|
-
@query = query
|
22
|
-
end
|
14
|
+
# @return the original result from the Neo4j Cypher Engine, once forward read only !
|
15
|
+
attr_reader :source
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
def initialize(source, query)
|
18
|
+
@source = source
|
19
|
+
@struct = Struct.new(*source.columns.to_a.map(&:to_sym))
|
20
|
+
@unread = true
|
21
|
+
@query = query
|
22
|
+
end
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def to_s
|
25
|
+
@query
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
28
|
+
def inspect
|
29
|
+
"Enumerable query: '#{@query}'"
|
30
|
+
end
|
36
31
|
|
37
|
-
|
38
|
-
|
32
|
+
# @return [Array<Symbol>] the columns in the query result
|
33
|
+
def columns
|
34
|
+
@source.columns.map(&:to_sym)
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
def each
|
38
|
+
fail ResultsAlreadyConsumedException unless @unread
|
39
|
+
|
40
|
+
if block_given?
|
41
|
+
@source.each do |row|
|
42
|
+
yield(row.each_with_object(@struct.new) do |(column, value), result|
|
43
|
+
result[column.to_sym] = (value.respond_to?(:wrapper) ? value.wrapper : value)
|
44
|
+
end)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
Enumerator.new(self)
|
45
48
|
end
|
46
|
-
else
|
47
|
-
Enumerator.new(self)
|
48
49
|
end
|
49
50
|
end
|
50
|
-
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
@@ -1,29 +1,28 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Neo4j
|
2
|
+
module Embedded
|
3
|
+
class EmbeddedDatabase
|
4
|
+
class Error < StandardError
|
5
|
+
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
class << self
|
8
|
+
def connect(db_location, config = {})
|
9
|
+
if Neo4j::Session.current.respond_to?(:db_location) && Neo4j::Session.current.db_location == db_location
|
10
|
+
return Neo4j::Session.current
|
11
|
+
else
|
12
|
+
EmbeddedSession.new(db_location, config)
|
13
|
+
end
|
13
14
|
end
|
14
|
-
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def create_db(db_location)
|
17
|
+
puts "Start embedded Neo4j db at #{db_location}"
|
18
|
+
factory = Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory.new
|
19
|
+
factory.newEmbeddedDatabase(db_location)
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def factory_class
|
23
|
+
Java::OrgNeo4jTest::ImpermanentGraphDatabase
|
24
|
+
end
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
28
27
|
end
|
29
|
-
end
|
28
|
+
end
|
@@ -4,18 +4,20 @@ Neo4j::Session.register_db(:ha_db) do |*args|
|
|
4
4
|
Neo4j::Embedded::EmbeddedHaSession.new(*args)
|
5
5
|
end
|
6
6
|
|
7
|
-
module Neo4j
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
module Neo4j
|
8
|
+
module Embedded
|
9
|
+
class EmbeddedHaSession < EmbeddedSession
|
10
|
+
def start
|
11
|
+
fail Error, 'Embedded HA Neo4j db is already running' if running?
|
12
|
+
puts "Start embedded HA Neo4j db at #{db_location}"
|
13
|
+
factory = Java::OrgNeo4jGraphdbFactory::HighlyAvailableGraphDatabaseFactory.new
|
14
|
+
db_service = factory.newHighlyAvailableDatabaseBuilder(db_location)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
fail Error, 'Need properties file for HA configuration' unless properties_file
|
17
|
+
db_service.loadPropertiesFromFile(properties_file)
|
18
|
+
@graph_db = db_service.newGraphDatabase
|
19
|
+
Neo4j::Session._notify_listeners(:session_available, self)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -4,14 +4,15 @@ Neo4j::Session.register_db(:impermanent_db) do |*args|
|
|
4
4
|
Neo4j::Embedded::EmbeddedImpermanentSession.new(*args)
|
5
5
|
end
|
6
6
|
|
7
|
-
module Neo4j
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
module Neo4j
|
8
|
+
module Embedded
|
9
|
+
class EmbeddedImpermanentSession < EmbeddedSession
|
10
|
+
def start
|
11
|
+
fail Error, 'Embedded Neo4j db is already running' if running?
|
12
|
+
# puts "Start test impermanent embedded Neo4j db at #{db_location}"
|
13
|
+
@graph_db = Java::OrgNeo4jTest::TestGraphDatabaseFactory.new.newImpermanentDatabase
|
14
|
+
Neo4j::Session._notify_listeners(:session_available, self)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
|
@@ -1,92 +1,86 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Neo4j
|
2
|
+
module Embedded
|
3
|
+
class EmbeddedLabel < Neo4j::Label
|
4
|
+
extend Neo4j::Core::TxMethods
|
5
|
+
attr_reader :name
|
6
|
+
JAVA_CLASS = Java::OrgNeo4jGraphdb::DynamicLabel
|
7
|
+
|
8
|
+
def initialize(session, name)
|
9
|
+
@name = name.to_sym
|
10
|
+
@session = session
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def to_s
|
14
|
+
@name
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
iterator
|
19
|
-
iterator.to_a.map{|n| n.wrapper}
|
17
|
+
def find_nodes(key = nil, value = nil)
|
18
|
+
iterator = _find_nodes(key, value)
|
19
|
+
iterator.to_a.map(&:wrapper)
|
20
20
|
ensure
|
21
21
|
iterator && iterator.close
|
22
22
|
end
|
23
|
-
|
24
|
-
tx_methods :find_nodes
|
23
|
+
tx_methods :find_nodes
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
self.class.as_java(@name.to_s)
|
38
|
-
end
|
34
|
+
def as_java
|
35
|
+
self.class.as_java(@name.to_s)
|
36
|
+
end
|
39
37
|
|
40
|
-
|
38
|
+
def create_index(*properties)
|
41
39
|
index_creator = @session.graph_db.schema.index_for(as_java)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
# we can also use the PropertyConstraintCreator here
|
41
|
+
properties.inject(index_creator) { |creator, key| creator.on(key.to_s) }.create
|
42
|
+
end
|
43
|
+
tx_methods :create_index
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
def indexes
|
46
|
+
{
|
49
47
|
property_keys: @session.graph_db.schema.indexes(as_java).map do |index_def|
|
50
|
-
index_def.property_keys.map
|
48
|
+
index_def.property_keys.map(&:to_sym)
|
51
49
|
end
|
52
|
-
|
53
|
-
end
|
54
|
-
tx_methods :indexes
|
55
|
-
|
56
|
-
def uniqueness_constraints()
|
57
|
-
{
|
58
|
-
property_keys: @session.graph_db.schema.constraints(as_java).select do |index_def|
|
59
|
-
index_def.is_a?(Java::OrgNeo4jKernelImplCoreapiSchema::PropertyUniqueConstraintDefinition)
|
60
|
-
end.map do |index_def|
|
61
|
-
index_def.property_keys.map{|x| x.to_sym}
|
62
|
-
end
|
63
|
-
}
|
64
|
-
end
|
65
|
-
tx_methods :uniqueness_constraints
|
66
|
-
|
67
|
-
|
68
|
-
def drop_index(*properties)
|
69
|
-
@session.graph_db.schema.indexes(as_java).each do |index_def|
|
70
|
-
# at least one match, TODO
|
71
|
-
keys = index_def.property_keys.map{|x| x.to_sym}
|
72
|
-
index_def.drop if (properties - keys).count < properties.count
|
50
|
+
}
|
73
51
|
end
|
52
|
+
tx_methods :indexes
|
74
53
|
|
75
|
-
|
76
|
-
|
54
|
+
def uniqueness_constraints
|
55
|
+
definitions = @session.graph_db.schema.constraints(as_java).select do |index_def|
|
56
|
+
index_def.is_a?(Java::OrgNeo4jKernelImplCoreapiSchema::PropertyUniqueConstraintDefinition)
|
57
|
+
end
|
58
|
+
{
|
59
|
+
property_keys: definitions.map { |index_def| index_def.property_keys.map(&:to_sym) }
|
60
|
+
}
|
61
|
+
end
|
62
|
+
tx_methods :uniqueness_constraints
|
77
63
|
|
78
|
-
class << self
|
79
64
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
65
|
+
def drop_index(*properties)
|
66
|
+
@session.graph_db.schema.indexes(as_java).each do |index_def|
|
67
|
+
# at least one match, TODO
|
68
|
+
keys = index_def.property_keys.map(&:to_sym)
|
69
|
+
index_def.drop if (properties - keys).count < properties.count
|
70
|
+
end
|
71
|
+
end
|
72
|
+
tx_methods :drop_index
|
73
|
+
|
74
|
+
class << self
|
75
|
+
def as_java(labels)
|
76
|
+
if labels.is_a?(Array)
|
77
|
+
return nil if labels.empty?
|
78
|
+
labels.inject([]) { |result, label| result << JAVA_CLASS.label(label.to_s) }.to_java(JAVA_CLASS)
|
79
|
+
else
|
80
|
+
JAVA_CLASS.label(labels.to_s)
|
81
|
+
end
|
86
82
|
end
|
87
83
|
end
|
88
84
|
end
|
89
85
|
end
|
90
|
-
|
91
86
|
end
|
92
|
-
|
@@ -1,57 +1,55 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Neo4j
|
2
|
+
module Embedded
|
3
|
+
class RelsIterator
|
4
|
+
include Enumerable
|
5
|
+
extend Neo4j::Core::TxMethods
|
6
|
+
|
7
|
+
def initialize(node, match)
|
8
|
+
@node = node
|
9
|
+
@match = match
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def inspect
|
13
|
+
'Enumerable<Neo4j::Relationship>'
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def each(&block)
|
17
|
+
@node._rels(@match).each { |r| block.call(r.wrapper) }
|
18
|
+
end
|
19
|
+
tx_methods :each
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def empty?
|
22
|
+
first.nil?
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
include Enumerable
|
28
|
-
extend Neo4j::Core::TxMethods
|
26
|
+
class NodesIterator
|
27
|
+
include Enumerable
|
28
|
+
extend Neo4j::Core::TxMethods
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def initialize(node, match)
|
31
|
+
@node = node
|
32
|
+
@match = match
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def inspect
|
36
|
+
'Enumerable<Neo4j::Node>'
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def each(&block)
|
40
|
+
@node._rels(@match).each { |r| block.call(r.other_node(@node)) }
|
41
|
+
end
|
42
|
+
tx_methods :each
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
def empty?
|
45
|
+
first.nil?
|
46
|
+
end
|
46
47
|
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# This method is used to extend a Java Neo4j class so that it includes the same mixins as this class.
|
53
|
-
def extend_java_class(java_clazz)
|
54
|
-
java_clazz.class_eval do
|
49
|
+
class EmbeddedNode
|
50
|
+
class << self
|
51
|
+
# This method is used to extend a Java Neo4j class so that it includes the same mixins as this class.
|
52
|
+
Java::OrgNeo4jKernelImplCore::NodeProxy.class_eval do
|
55
53
|
include Neo4j::Embedded::Property
|
56
54
|
include Neo4j::EntityEquality
|
57
55
|
include Neo4j::Core::ActiveEntity
|
@@ -69,7 +67,7 @@ module Neo4j::Embedded
|
|
69
67
|
tx_methods :exist?
|
70
68
|
|
71
69
|
def labels
|
72
|
-
_labels.iterator.map{|x| x.name.to_sym}
|
70
|
+
_labels.iterator.map { |x| x.name.to_sym }
|
73
71
|
end
|
74
72
|
tx_methods :labels
|
75
73
|
|
@@ -108,7 +106,7 @@ module Neo4j::Embedded
|
|
108
106
|
tx_methods :set_label
|
109
107
|
|
110
108
|
def del
|
111
|
-
_rels.each
|
109
|
+
_rels.each(&:del)
|
112
110
|
delete
|
113
111
|
nil
|
114
112
|
end
|
@@ -126,72 +124,72 @@ module Neo4j::Embedded
|
|
126
124
|
tx_methods :create_rel
|
127
125
|
|
128
126
|
|
129
|
-
def rels(match={})
|
127
|
+
def rels(match = {})
|
130
128
|
RelsIterator.new(self, match)
|
131
129
|
end
|
132
130
|
|
133
|
-
def nodes(match={})
|
131
|
+
def nodes(match = {})
|
134
132
|
NodesIterator.new(self, match)
|
135
133
|
end
|
136
134
|
|
137
|
-
def node(match={})
|
135
|
+
def node(match = {})
|
138
136
|
rel = _rel(match)
|
139
137
|
rel && rel.other_node(self).wrapper
|
140
138
|
end
|
141
139
|
tx_methods :node
|
142
140
|
|
143
|
-
def rel?(match={})
|
141
|
+
def rel?(match = {})
|
144
142
|
_rels(match).has_next
|
145
143
|
end
|
146
144
|
tx_methods :rel?
|
147
145
|
|
148
|
-
def rel(match={})
|
146
|
+
def rel(match = {})
|
149
147
|
_rel(match)
|
150
148
|
end
|
151
149
|
tx_methods :rel
|
152
150
|
|
153
|
-
def _rel(match={})
|
154
|
-
dir = match[:dir] || :both
|
151
|
+
def _rel(match = {})
|
152
|
+
dir = ToJava.dir_to_java(match[:dir] || :both)
|
155
153
|
rel_type = match[:type]
|
156
154
|
|
157
155
|
rel = if rel_type
|
158
|
-
|
156
|
+
get_single_relationship(ToJava.type_to_java(rel_type), dir)
|
159
157
|
else
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
158
|
+
iter = get_relationships(dir).iterator
|
159
|
+
|
160
|
+
if iter.has_next
|
161
|
+
first = iter.next
|
162
|
+
fail "Expected to only find one relationship from node #{neo_id} matching #{match.inspect}" if iter.has_next
|
163
|
+
first
|
164
|
+
end
|
165
|
+
end
|
167
166
|
|
168
167
|
between_id = match[:between] && match[:between].neo_id
|
169
168
|
|
170
|
-
if
|
171
|
-
rel.other_node(self).neo_id == between_id
|
169
|
+
if rel && between_id
|
170
|
+
rel if rel.other_node(self).neo_id == between_id
|
172
171
|
else
|
173
172
|
rel
|
174
173
|
end
|
175
174
|
end
|
176
175
|
|
177
|
-
def _rels(match={})
|
176
|
+
def _rels(match = {})
|
178
177
|
dir = match[:dir] || :both
|
179
178
|
rel_type = match[:type]
|
180
179
|
|
181
180
|
rels = if rel_type
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
181
|
+
get_relationships(ToJava.type_to_java(rel_type), ToJava.dir_to_java(dir)).iterator
|
182
|
+
else
|
183
|
+
get_relationships(ToJava.dir_to_java(dir)).iterator
|
184
|
+
end
|
186
185
|
|
187
186
|
between_id = match[:between] && match[:between].neo_id
|
188
187
|
|
189
|
-
if
|
190
|
-
rels.find_all{|r| r.end_node.neo_id == between_id || r.start_node.neo_id == between_id}
|
188
|
+
if between_id
|
189
|
+
rels.find_all { |r| r.end_node.neo_id == between_id || r.start_node.neo_id == between_id }
|
191
190
|
else
|
192
191
|
rels
|
193
192
|
end
|
194
|
-
|
195
193
|
end
|
196
194
|
|
197
195
|
def class
|
@@ -202,8 +200,5 @@ module Neo4j::Embedded
|
|
202
200
|
end
|
203
201
|
end
|
204
202
|
end
|
205
|
-
|
206
|
-
extend_java_class(Java::OrgNeo4jKernelImplCore::NodeProxy)
|
207
203
|
end
|
208
|
-
|
209
204
|
end
|