neo4j-core 3.0.0.rc.1 → 3.0.0.rc.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neo4j-core.rb +0 -3
- data/lib/neo4j-core/version.rb +1 -1
- data/neo4j-core.gemspec +2 -5
- metadata +60 -68
- data/lib/neo4j-core.rb~ +0 -26
- data/lib/neo4j-core/version.rb~ +0 -5
- data/lib/neo4j-embedded/cypher_response.rb~ +0 -85
- data/lib/neo4j-embedded/embedded_node.rb~ +0 -201
- data/lib/neo4j-embedded/embedded_relationship.rb~ +0 -62
- data/lib/neo4j-embedded/embedded_session.rb~ +0 -145
- data/lib/neo4j-server/cypher_response.rb~ +0 -155
- data/lib/neo4j/session.rb~ +0 -202
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f4e034ba33270fdcb1cb5b5535d039fd9efde54
|
4
|
+
data.tar.gz: 532daaec0377fe3e610b2d76acd2b69a8f3c96e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 733e818958cc4ae6ad35d5a8c6a6d9a86e7d12c8117f35734c15520974cabb40deff43b25761d971fe78e19aa5b742b7105b463d5d584d91027a3bccd1f076fc
|
7
|
+
data.tar.gz: 1d72fb9147c87fe03b6c9bc82aff383dad9fce34213da4020f5a7afbb840241e48006a16fb6d667725ba3c7a139fc80b396e671dfe6750d6ebaf9da512fbd83c
|
data/lib/neo4j-core.rb
CHANGED
data/lib/neo4j-core/version.rb
CHANGED
data/neo4j-core.gemspec
CHANGED
@@ -30,15 +30,12 @@ It comes included with the Apache Lucene document database.
|
|
30
30
|
|
31
31
|
# Not released yet
|
32
32
|
s.add_dependency("httparty")
|
33
|
+
s.add_dependency("json")
|
33
34
|
s.add_dependency("os") # for Rake task
|
34
35
|
s.add_dependency("zip") # for Rake task
|
35
36
|
s.add_dependency("activesupport") # For ActiveSupport::Notifications
|
36
37
|
|
37
|
-
if RUBY_PLATFORM
|
38
|
-
s.add_dependency("json")
|
38
|
+
if RUBY_PLATFORM == 'java'
|
39
39
|
s.add_dependency("neo4j-community", '~> 2.1.1')
|
40
|
-
else
|
41
|
-
s.add_dependency("oj")
|
42
|
-
s.add_dependency("oj_mimic_json")
|
43
40
|
end
|
44
41
|
end
|
metadata
CHANGED
@@ -1,99 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4j-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.rc.
|
4
|
+
version: 3.0.0.rc.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Ronge
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
15
|
version_requirements: !ruby/object:Gem::Requirement
|
23
16
|
requirements:
|
24
|
-
- -
|
17
|
+
- - '>='
|
25
18
|
- !ruby/object:Gem::Version
|
26
19
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: os
|
29
20
|
requirement: !ruby/object:Gem::Requirement
|
30
21
|
requirements:
|
31
|
-
- -
|
22
|
+
- - '>='
|
32
23
|
- !ruby/object:Gem::Version
|
33
24
|
version: '0'
|
34
|
-
type: :runtime
|
35
25
|
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
36
29
|
version_requirements: !ruby/object:Gem::Requirement
|
37
30
|
requirements:
|
38
|
-
- -
|
31
|
+
- - '>='
|
39
32
|
- !ruby/object:Gem::Version
|
40
33
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: zip
|
43
34
|
requirement: !ruby/object:Gem::Requirement
|
44
35
|
requirements:
|
45
|
-
- -
|
36
|
+
- - '>='
|
46
37
|
- !ruby/object:Gem::Version
|
47
38
|
version: '0'
|
48
|
-
type: :runtime
|
49
39
|
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: os
|
50
43
|
version_requirements: !ruby/object:Gem::Requirement
|
51
44
|
requirements:
|
52
|
-
- -
|
45
|
+
- - '>='
|
53
46
|
- !ruby/object:Gem::Version
|
54
47
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activesupport
|
57
48
|
requirement: !ruby/object:Gem::Requirement
|
58
49
|
requirements:
|
59
|
-
- -
|
50
|
+
- - '>='
|
60
51
|
- !ruby/object:Gem::Version
|
61
52
|
version: '0'
|
62
|
-
type: :runtime
|
63
53
|
prerelease: false
|
54
|
+
type: :runtime
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: zip
|
64
57
|
version_requirements: !ruby/object:Gem::Requirement
|
65
58
|
requirements:
|
66
|
-
- -
|
59
|
+
- - '>='
|
67
60
|
- !ruby/object:Gem::Version
|
68
61
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: oj
|
71
62
|
requirement: !ruby/object:Gem::Requirement
|
72
63
|
requirements:
|
73
|
-
- -
|
64
|
+
- - '>='
|
74
65
|
- !ruby/object:Gem::Version
|
75
66
|
version: '0'
|
76
|
-
type: :runtime
|
77
67
|
prerelease: false
|
68
|
+
type: :runtime
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
78
71
|
version_requirements: !ruby/object:Gem::Requirement
|
79
72
|
requirements:
|
80
|
-
- -
|
73
|
+
- - '>='
|
81
74
|
- !ruby/object:Gem::Version
|
82
75
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: oj_mimic_json
|
85
76
|
requirement: !ruby/object:Gem::Requirement
|
86
77
|
requirements:
|
87
|
-
- -
|
78
|
+
- - '>='
|
88
79
|
- !ruby/object:Gem::Version
|
89
80
|
version: '0'
|
90
|
-
type: :runtime
|
91
81
|
prerelease: false
|
82
|
+
type: :runtime
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: neo4j-community
|
92
85
|
version_requirements: !ruby/object:Gem::Requirement
|
93
86
|
requirements:
|
94
|
-
- -
|
87
|
+
- - ~>
|
95
88
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
89
|
+
version: 2.1.1
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.1.1
|
95
|
+
prerelease: false
|
96
|
+
type: :runtime
|
97
97
|
description: |
|
98
98
|
You can think of Neo4j as a high-performance graph engine with all the features of a mature and robust database.
|
99
99
|
The programmer works with an object-oriented, flexible network structure rather than with strict and static tables
|
@@ -105,10 +105,19 @@ extensions: []
|
|
105
105
|
extra_rdoc_files:
|
106
106
|
- README.md
|
107
107
|
files:
|
108
|
-
- Gemfile
|
109
|
-
- README.md
|
110
108
|
- lib/neo4j-core.rb
|
111
|
-
- lib/neo4j-
|
109
|
+
- lib/neo4j-embedded.rb
|
110
|
+
- lib/neo4j-server.rb
|
111
|
+
- lib/neo4j/entity_equality.rb
|
112
|
+
- lib/neo4j/label.rb
|
113
|
+
- lib/neo4j/node.rb
|
114
|
+
- lib/neo4j/property_container.rb
|
115
|
+
- lib/neo4j/property_validator.rb
|
116
|
+
- lib/neo4j/relationship.rb
|
117
|
+
- lib/neo4j/session.rb
|
118
|
+
- lib/neo4j/transaction.rb
|
119
|
+
- lib/neo4j/tasks/config_server.rb
|
120
|
+
- lib/neo4j/tasks/neo4j_server.rb
|
112
121
|
- lib/neo4j-core/active_entity.rb
|
113
122
|
- lib/neo4j-core/cypher_translator.rb
|
114
123
|
- lib/neo4j-core/hash_with_indifferent_access.rb
|
@@ -117,74 +126,57 @@ files:
|
|
117
126
|
- lib/neo4j-core/query.rb
|
118
127
|
- lib/neo4j-core/query_clauses.rb
|
119
128
|
- lib/neo4j-core/version.rb
|
120
|
-
- lib/neo4j-core/version.rb~
|
121
|
-
- lib/neo4j-embedded.rb
|
122
129
|
- lib/neo4j-embedded/cypher_response.rb
|
123
|
-
- lib/neo4j-embedded/cypher_response.rb~
|
124
130
|
- lib/neo4j-embedded/embedded_database.rb
|
125
131
|
- lib/neo4j-embedded/embedded_impermanent_session.rb
|
126
132
|
- lib/neo4j-embedded/embedded_label.rb
|
127
133
|
- lib/neo4j-embedded/embedded_node.rb
|
128
|
-
- lib/neo4j-embedded/embedded_node.rb~
|
129
134
|
- lib/neo4j-embedded/embedded_relationship.rb
|
130
|
-
- lib/neo4j-embedded/embedded_relationship.rb~
|
131
135
|
- lib/neo4j-embedded/embedded_session.rb
|
132
|
-
- lib/neo4j-embedded/embedded_session.rb~
|
133
136
|
- lib/neo4j-embedded/embedded_transaction.rb
|
134
137
|
- lib/neo4j-embedded/property.rb
|
135
138
|
- lib/neo4j-embedded/to_java.rb
|
136
|
-
- lib/neo4j-server.rb
|
137
139
|
- lib/neo4j-server/cypher_label.rb
|
138
140
|
- lib/neo4j-server/cypher_node.rb
|
139
141
|
- lib/neo4j-server/cypher_node_uncommited.rb
|
140
142
|
- lib/neo4j-server/cypher_relationship.rb
|
141
143
|
- lib/neo4j-server/cypher_response.rb
|
142
|
-
- lib/neo4j-server/cypher_response.rb~
|
143
144
|
- lib/neo4j-server/cypher_session.rb
|
144
145
|
- lib/neo4j-server/cypher_transaction.rb
|
145
146
|
- lib/neo4j-server/neo4j_server_endpoint.rb
|
146
147
|
- lib/neo4j-server/resource.rb
|
147
|
-
-
|
148
|
-
-
|
149
|
-
- lib/neo4j/node.rb
|
150
|
-
- lib/neo4j/property_container.rb
|
151
|
-
- lib/neo4j/property_validator.rb
|
152
|
-
- lib/neo4j/relationship.rb
|
153
|
-
- lib/neo4j/session.rb
|
154
|
-
- lib/neo4j/session.rb~
|
155
|
-
- lib/neo4j/tasks/config_server.rb
|
156
|
-
- lib/neo4j/tasks/neo4j_server.rb
|
157
|
-
- lib/neo4j/transaction.rb
|
148
|
+
- README.md
|
149
|
+
- Gemfile
|
158
150
|
- neo4j-core.gemspec
|
159
151
|
homepage: http://github.com/andreasronge/neo4j-core/tree
|
160
152
|
licenses:
|
161
153
|
- MIT
|
162
154
|
metadata: {}
|
163
|
-
post_install_message:
|
155
|
+
post_install_message:
|
164
156
|
rdoc_options:
|
165
|
-
-
|
166
|
-
-
|
157
|
+
- --quiet
|
158
|
+
- --title
|
167
159
|
- Neo4j::Core
|
168
|
-
-
|
169
|
-
-
|
160
|
+
- --line-numbers
|
161
|
+
- --main
|
170
162
|
- README.rdoc
|
171
|
-
-
|
163
|
+
- --inline-source
|
172
164
|
require_paths:
|
173
165
|
- lib
|
174
166
|
required_ruby_version: !ruby/object:Gem::Requirement
|
175
167
|
requirements:
|
176
|
-
- -
|
168
|
+
- - '>='
|
177
169
|
- !ruby/object:Gem::Version
|
178
170
|
version: 1.8.7
|
179
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
172
|
requirements:
|
181
|
-
- -
|
173
|
+
- - '>'
|
182
174
|
- !ruby/object:Gem::Version
|
183
175
|
version: 1.3.1
|
184
176
|
requirements: []
|
185
177
|
rubyforge_project: neo4j-core
|
186
|
-
rubygems_version: 2.
|
187
|
-
signing_key:
|
178
|
+
rubygems_version: 2.1.9
|
179
|
+
signing_key:
|
188
180
|
specification_version: 4
|
189
181
|
summary: A graph database for Ruby
|
190
182
|
test_files: []
|
data/lib/neo4j-core.rb~
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
require 'neo4j/property_validator'
|
5
|
-
require 'neo4j/property_container'
|
6
|
-
require 'neo4j-core/helpers'
|
7
|
-
require 'neo4j-core/cypher_translator'
|
8
|
-
require 'neo4j-core/query'
|
9
|
-
|
10
|
-
require 'neo4j/entity_equality'
|
11
|
-
require 'neo4j/node'
|
12
|
-
require 'neo4j/label'
|
13
|
-
require 'neo4j/session'
|
14
|
-
|
15
|
-
require 'neo4j/relationship'
|
16
|
-
require 'neo4j/transaction'
|
17
|
-
|
18
|
-
require 'neo4j-server'
|
19
|
-
|
20
|
-
if RUBY_PLATFORM == 'java'
|
21
|
-
require 'neo4j-embedded'
|
22
|
-
else
|
23
|
-
# just for the tests
|
24
|
-
module Neo4j::Embedded
|
25
|
-
end
|
26
|
-
end
|
data/lib/neo4j-core/version.rb~
DELETED
@@ -1,85 +0,0 @@
|
|
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
|
-
|
@@ -1,201 +0,0 @@
|
|
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
|
@@ -1,62 +0,0 @@
|
|
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
|
@@ -1,145 +0,0 @@
|
|
1
|
-
# Plugin
|
2
|
-
|
3
|
-
Neo4j::Session.register_db(:embedded_db) do |*args|
|
4
|
-
Neo4j::Embedded::EmbeddedSession.new(*args)
|
5
|
-
end
|
6
|
-
|
7
|
-
|
8
|
-
module Neo4j::Embedded
|
9
|
-
class EmbeddedSession < Neo4j::Session
|
10
|
-
|
11
|
-
class Error < StandardError
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :graph_db, :db_location
|
15
|
-
extend Forwardable
|
16
|
-
extend Neo4j::Core::TxMethods
|
17
|
-
def_delegator :@graph_db, :begin_tx
|
18
|
-
|
19
|
-
|
20
|
-
def initialize(db_location, config={})
|
21
|
-
@db_location = db_location
|
22
|
-
@auto_commit = !!config[:auto_commit]
|
23
|
-
Neo4j::Session.register(self)
|
24
|
-
@query_builder = Neo4j::Core::QueryBuilder.new
|
25
|
-
end
|
26
|
-
|
27
|
-
def start
|
28
|
-
raise Error.new("Embedded Neo4j db is already running") if running?
|
29
|
-
puts "Start embedded Neo4j db at #{db_location}"
|
30
|
-
factory = Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory.new
|
31
|
-
@graph_db = factory.newEmbeddedDatabase(db_location)
|
32
|
-
Neo4j::Session._notify_listeners(:session_available, self)
|
33
|
-
end
|
34
|
-
|
35
|
-
def factory_class
|
36
|
-
Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory
|
37
|
-
Java::OrgNeo4jTest::ImpermanentGraphDatabase
|
38
|
-
end
|
39
|
-
|
40
|
-
def close
|
41
|
-
super
|
42
|
-
shutdown
|
43
|
-
end
|
44
|
-
|
45
|
-
def shutdown
|
46
|
-
graph_db && graph_db.shutdown
|
47
|
-
@graph_db = nil
|
48
|
-
end
|
49
|
-
|
50
|
-
def running?
|
51
|
-
!!graph_db
|
52
|
-
end
|
53
|
-
|
54
|
-
def create_label(name)
|
55
|
-
EmbeddedLabel.new(self, name)
|
56
|
-
end
|
57
|
-
|
58
|
-
def load_node(neo_id)
|
59
|
-
_load_node(neo_id)
|
60
|
-
end
|
61
|
-
tx_methods :load_node
|
62
|
-
|
63
|
-
# Same as load but does not return the node as a wrapped Ruby object.
|
64
|
-
#
|
65
|
-
def _load_node(neo_id)
|
66
|
-
return nil if neo_id.nil?
|
67
|
-
@graph_db.get_node_by_id(neo_id.to_i)
|
68
|
-
rescue Java::OrgNeo4jGraphdb.NotFoundException
|
69
|
-
nil
|
70
|
-
end
|
71
|
-
|
72
|
-
def load_relationship(neo_id)
|
73
|
-
_load_relationship(neo_id)
|
74
|
-
end
|
75
|
-
tx_methods :load_relationship
|
76
|
-
|
77
|
-
def _load_relationship(neo_id)
|
78
|
-
return nil if neo_id.nil?
|
79
|
-
@graph_db.get_relationship_by_id(neo_id.to_i)
|
80
|
-
rescue Java::OrgNeo4jGraphdb.NotFoundException
|
81
|
-
nil
|
82
|
-
end
|
83
|
-
|
84
|
-
def query(*params)
|
85
|
-
query_hash = @query_builder.to_query_hash(params, :to_node)
|
86
|
-
cypher = @query_builder.to_cypher(query_hash)
|
87
|
-
|
88
|
-
result = _query(cypher, query_hash[:params])
|
89
|
-
if result.respond_to?(:error?) && result.error?
|
90
|
-
raise Neo4j::Session::CypherError.new(result.error_msg, result.error_code, result.error_status)
|
91
|
-
end
|
92
|
-
|
93
|
-
map_return_procs = @query_builder.to_map_return_procs(query_hash)
|
94
|
-
ResultWrapper.new(result, map_return_procs, cypher)
|
95
|
-
end
|
96
|
-
|
97
|
-
def find_all_nodes(label)
|
98
|
-
EmbeddedLabel.new(self, label).find_nodes
|
99
|
-
end
|
100
|
-
|
101
|
-
def find_nodes(label, key, value)
|
102
|
-
EmbeddedLabel.new(self, label).find_nodes(key,value)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Performs a cypher query with given string.
|
106
|
-
# Remember that you should close the resource iterator.
|
107
|
-
# @param [String] q the cypher query as a String
|
108
|
-
# @return (see #query)
|
109
|
-
def _query(q, params={})
|
110
|
-
engine = Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db)
|
111
|
-
engine.execute(q, Neo4j::Core::HashWithIndifferentAccess.new(params))
|
112
|
-
rescue Exception => e
|
113
|
-
raise Neo4j::Session::CypherError.new(e.message, e.class, 'cypher error')
|
114
|
-
end
|
115
|
-
|
116
|
-
def query_default_return(as)
|
117
|
-
" RETURN #{as}"
|
118
|
-
end
|
119
|
-
|
120
|
-
def _query_or_fail(q)
|
121
|
-
engine = Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db)
|
122
|
-
engine.execute(q)
|
123
|
-
end
|
124
|
-
|
125
|
-
def search_result_to_enumerable(result)
|
126
|
-
result.map {|column| column['n'].wrapper}
|
127
|
-
end
|
128
|
-
|
129
|
-
def create_node(properties = nil, labels=[])
|
130
|
-
if labels.empty?
|
131
|
-
_java_node = graph_db.create_node
|
132
|
-
else
|
133
|
-
labels = EmbeddedLabel.as_java(labels)
|
134
|
-
_java_node = graph_db.create_node(labels)
|
135
|
-
end
|
136
|
-
properties.each_pair { |k, v| _java_node[k]=v } if properties
|
137
|
-
_java_node
|
138
|
-
end
|
139
|
-
tx_methods :create_node
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
module Neo4j::Server
|
2
|
-
class CypherResponse
|
3
|
-
attr_reader :data, :columns, :error_msg, :error_status, :error_code, :response
|
4
|
-
|
5
|
-
class ResponseError < StandardError
|
6
|
-
attr_reader :status, :code
|
7
|
-
|
8
|
-
def initialize(msg, status, code)
|
9
|
-
super(msg)
|
10
|
-
@status = status
|
11
|
-
@code = code
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
class HashEnumeration
|
17
|
-
include Enumerable
|
18
|
-
extend Forwardable
|
19
|
-
def_delegator :@response, :error_msg
|
20
|
-
def_delegator :@response, :error_status
|
21
|
-
def_delegator :@response, :error_code
|
22
|
-
def_delegator :@response, :data
|
23
|
-
def_delegator :@response, :columns
|
24
|
-
|
25
|
-
def initialize(response, map_return_procs, query)
|
26
|
-
@response = response
|
27
|
-
@map_return_procs = map_return_procs
|
28
|
-
@query = query
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
@query
|
33
|
-
end
|
34
|
-
|
35
|
-
puts "RELOADED"
|
36
|
-
def inspect
|
37
|
-
#"Enumerable query: '#{@query}' map_return: [#{@map_return_procs.keys.join(', ')}]"
|
38
|
-
"Enumerable query: '#{@query}' map_return: [#{@map_return_procs.keys.inspect}]"
|
39
|
-
end
|
40
|
-
|
41
|
-
def each_no_mapping
|
42
|
-
data.each do |row|
|
43
|
-
hash = {}
|
44
|
-
row.each_with_index do |row, i|
|
45
|
-
key = columns[i].to_sym
|
46
|
-
hash[key] = row
|
47
|
-
end
|
48
|
-
yield hash
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def each_multi_column_mapping
|
53
|
-
data.each do |row|
|
54
|
-
hash = {}
|
55
|
-
row.each_with_index do |row, i|
|
56
|
-
key = columns[i].to_sym
|
57
|
-
proc = @map_return_procs[key]
|
58
|
-
hash[key] = proc ? proc.call(row) : row
|
59
|
-
end
|
60
|
-
yield hash
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def each_single_column_mapping
|
65
|
-
data.each do |row|
|
66
|
-
result = @map_return_procs.call(row.first)
|
67
|
-
yield result
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def each(&block)
|
72
|
-
case @map_return_procs
|
73
|
-
when NilClass then each_no_mapping &block
|
74
|
-
when Hash then each_multi_column_mapping &block
|
75
|
-
else each_single_column_mapping &block
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def to_hash_enumeration(map_return_procs={}, cypher='')
|
81
|
-
HashEnumeration.new(self, map_return_procs, cypher)
|
82
|
-
end
|
83
|
-
|
84
|
-
def initialize(response, uncommited = false)
|
85
|
-
@response = response
|
86
|
-
@uncommited = uncommited
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
def first_data
|
91
|
-
if uncommited?
|
92
|
-
@data.first['row'].first
|
93
|
-
else
|
94
|
-
@data[0][0]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def error?
|
99
|
-
!!@error
|
100
|
-
end
|
101
|
-
|
102
|
-
def uncommited?
|
103
|
-
@uncommited
|
104
|
-
end
|
105
|
-
|
106
|
-
def raise_unless_response_code(code)
|
107
|
-
raise "Response code #{response.code}, expected #{code} for #{response.request.path}, #{response.body}" unless response.code == code
|
108
|
-
end
|
109
|
-
|
110
|
-
def set_data(data, columns)
|
111
|
-
@data = data
|
112
|
-
@columns = columns
|
113
|
-
self
|
114
|
-
end
|
115
|
-
|
116
|
-
def set_error(error_msg, error_status, error_core)
|
117
|
-
@error = true
|
118
|
-
@error_msg = error_msg
|
119
|
-
@error_status = error_status
|
120
|
-
@error_code = error_core
|
121
|
-
self
|
122
|
-
end
|
123
|
-
|
124
|
-
def raise_error
|
125
|
-
raise "Tried to raise error without an error" unless @error
|
126
|
-
raise ResponseError.new(@error_msg, @error_status, @error_code)
|
127
|
-
end
|
128
|
-
|
129
|
-
def self.create_with_no_tx(response)
|
130
|
-
case response.code
|
131
|
-
when 200
|
132
|
-
CypherResponse.new(response).set_data(response['data'], response['columns'])
|
133
|
-
when 400
|
134
|
-
CypherResponse.new(response).set_error(response['message'], response['exception'], response['fullname'])
|
135
|
-
else
|
136
|
-
raise "Unknown response code #{response.code} for #{response.request.path.to_s}"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def self.create_with_tx(response)
|
141
|
-
raise "Unknown response code #{response.code} for #{response.request.path.to_s}" unless response.code == 200
|
142
|
-
|
143
|
-
first_result = response['results'][0]
|
144
|
-
cr = CypherResponse.new(response, true)
|
145
|
-
|
146
|
-
if (response['errors'].empty?)
|
147
|
-
cr.set_data(first_result['data'], first_result['columns'])
|
148
|
-
else
|
149
|
-
first_error = response['errors'].first
|
150
|
-
cr.set_error(first_error['message'], first_error['status'], first_error['code'])
|
151
|
-
end
|
152
|
-
cr
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
data/lib/neo4j/session.rb~
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
class Session
|
3
|
-
|
4
|
-
@@current_session = nil
|
5
|
-
@@all_sessions = {}
|
6
|
-
@@factories = {}
|
7
|
-
|
8
|
-
# @abstract
|
9
|
-
def close
|
10
|
-
self.class.unregister(self)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Only for embedded database
|
14
|
-
# @abstract
|
15
|
-
def start
|
16
|
-
raise "not impl."
|
17
|
-
end
|
18
|
-
|
19
|
-
# Only for embedded database
|
20
|
-
# @abstract
|
21
|
-
def shutdown
|
22
|
-
raise "not impl."
|
23
|
-
end
|
24
|
-
|
25
|
-
# Only for embedded database
|
26
|
-
# @abstract
|
27
|
-
def running
|
28
|
-
raise "not impl."
|
29
|
-
end
|
30
|
-
|
31
|
-
def auto_commit?
|
32
|
-
true # TODO
|
33
|
-
end
|
34
|
-
|
35
|
-
# @abstract
|
36
|
-
def begin_tx
|
37
|
-
raise "not impl."
|
38
|
-
end
|
39
|
-
|
40
|
-
class CypherError < StandardError
|
41
|
-
attr_reader :error_msg, :error_status, :error_code
|
42
|
-
def initialize(error_msg, error_code, error_status)
|
43
|
-
super(error_msg)
|
44
|
-
@error_msg = error_msg
|
45
|
-
@error_status = error_status
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Executes a Cypher Query.
|
50
|
-
# Returns an enumerable of hash values where each hash corresponds to a row unless +return+ or +map_return+
|
51
|
-
# is not an array. The search result can be mapped to Neo4j::Node or Neo4j::Relationship is your own Ruby wrapper class
|
52
|
-
# by specifying a map_return parameter.
|
53
|
-
#
|
54
|
-
# @param [Hash, String] q the cypher query, as a pure string query or a hash which will generate a cypher string.
|
55
|
-
# @option q [Hash] :params cypher parameters
|
56
|
-
# @option q [Symbol,Hash] :label the label to match. You can specify several labels by using a hash of variable names and labels.
|
57
|
-
# @option q [Symbol] :conditions key and value of properties which the label nodes must match
|
58
|
-
# @option q [Hash] :conditions key and value of properties which the label nodes must match
|
59
|
-
# @option q [String, Array] :match the cypher match clause
|
60
|
-
# @option q [String, Array] :where the cypher where clause
|
61
|
-
# @option q [String, Array, Symbol] :return the cypher where clause
|
62
|
-
# @option q [String, Hash, Symbol] :map_return mapping of the returned values, e.g. :id_to_node, :id_to_rel, or :value
|
63
|
-
# @option q [Hash<Symbol, Proc>] :map_return_procs custom mapping functions of :map_return types
|
64
|
-
# @option q [String,Symbol,Array<Hash>] :order the order
|
65
|
-
# @option q [Fixnum] :limit enables the return of only subsets of the total result.
|
66
|
-
# @option q [Fixnum] :skip enables the return of only subsets of the total result.
|
67
|
-
# @return [Enumerable] the result, an enumerable of Neo4j::Node objects unless a pure cypher string is given or return/map_returns is specified, see examples.
|
68
|
-
# @raise CypherError if invalid cypher
|
69
|
-
# @example Cypher String and parameters
|
70
|
-
# Neo4j::Session.query("START n=node({p}) RETURN ID(n)", params: {p: 42})
|
71
|
-
#
|
72
|
-
# @example label
|
73
|
-
# # If there is no :return parameter it will try to return Neo4j::Node objects
|
74
|
-
# # Default parameter is :n in the generated cypher
|
75
|
-
# Neo4j::Session.query(label: :person) # => MATCH (n:`person`) RETURN ID(n) # or RETURN n for embedded
|
76
|
-
#
|
77
|
-
# @example to_s
|
78
|
-
# # What Cypher is returned ? check with to_s
|
79
|
-
# Neo4j::Session.query(label: :person).to_s # =>
|
80
|
-
#
|
81
|
-
# @example return
|
82
|
-
# Neo4j::Session.query(label: :person, return: :age) # returns age properties
|
83
|
-
# Neo4j::Session.query(label: :person, return: [:name, :age]) # returns a hash of name and age properties
|
84
|
-
# Neo4j::Session.query(label: :person, return: 'count(n) AS c')
|
85
|
-
#
|
86
|
-
# @example map_return - an Enumerable of names (String)
|
87
|
-
# Neo4j::Session.query("START n=node(42) RETURN n.name", map_return: :value)
|
88
|
-
#
|
89
|
-
# @example map_return - Enumerable of an Hash with name property, Neo4j::Relationship and Neo4j::Node as values
|
90
|
-
# Neo4j::Session.query("START n=node(42) MATCH n-[r]->[x] RETURN n.name as N, ID(r) as R, ID(x) as X",
|
91
|
-
# map_return: {N: :value, R: :id_to_rel, X: :id_to_node})
|
92
|
-
#
|
93
|
-
# @example map_return, only for embedded_db, to_rel, and to_node allows direct mapping to Neo4j::Node and Neo4j::Relationship without ID(n)
|
94
|
-
# Neo4j::Session.query("START n=node(42) MATCH n-[r]->[x] RETURN n.name as N, r, x", map_return: {N: :value, r: :to_rel, x: :to_node})
|
95
|
-
#
|
96
|
-
# @example map_return_procs, custom mapping function
|
97
|
-
# Neo4j::Session.query(label: :person, map_return: :age_times_two, map_return_procs: {age_times_two: ->(row){(row[:age] || 0) * 2}})
|
98
|
-
#
|
99
|
-
# @example match
|
100
|
-
# Neo4j::Session.query(label: :person, match: 'n--m')
|
101
|
-
#
|
102
|
-
# @example where
|
103
|
-
# Neo4j::Session.query(label: :person, where: 'n.age > 40')
|
104
|
-
# Neo4j::Session.query(label: :person, where: 'n.age > {age}', params: {age: 40})
|
105
|
-
#
|
106
|
-
# @example condition
|
107
|
-
# Neo4j::Session.query(label: :person, conditions: {age: 42})
|
108
|
-
# Neo4j::Session.query(label: :person, conditions: {name: /foo?bar.*/})
|
109
|
-
#
|
110
|
-
# @see http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html The Cypher Query Language Documentation
|
111
|
-
# @note Returns a read-once only forward iterable for the embedded database.
|
112
|
-
#
|
113
|
-
def query(q)
|
114
|
-
raise 'not implemented, abstract'
|
115
|
-
end
|
116
|
-
|
117
|
-
# Same as #query but does not accept an DSL and returns the raw result from the database.
|
118
|
-
# Notice, it might return different values depending on which database is used, embedded or server.
|
119
|
-
# @abstract
|
120
|
-
def _query(*params)
|
121
|
-
raise 'not implemented'
|
122
|
-
end
|
123
|
-
|
124
|
-
class << self
|
125
|
-
# Creates a new session to Neo4j
|
126
|
-
# @see also Neo4j::Server::CypherSession#open for :server_db params
|
127
|
-
# @param db_type the type of database, e.g. :embedded_db, or :server_db
|
128
|
-
def open(db_type=:server_db, *params)
|
129
|
-
register(create_session(db_type, params))
|
130
|
-
end
|
131
|
-
|
132
|
-
def open_named(db_type, name, default = nil, *params)
|
133
|
-
raise "Multiple sessions is currently only supported for Neo4j Server connections." unless db_type == :server_db
|
134
|
-
register(create_session(db_type, params), name, default)
|
135
|
-
end
|
136
|
-
|
137
|
-
def create_session(db_type, params = {})
|
138
|
-
unless (@@factories[db_type])
|
139
|
-
raise "Can't connect to database '#{db_type}', available #{@@factories.keys.join(',')}"
|
140
|
-
end
|
141
|
-
@@factories[db_type].call(*params)
|
142
|
-
end
|
143
|
-
|
144
|
-
def current
|
145
|
-
@@current_session
|
146
|
-
end
|
147
|
-
|
148
|
-
# @see Neo4j::Session#query
|
149
|
-
def query(*params)
|
150
|
-
current.query(*params)
|
151
|
-
end
|
152
|
-
|
153
|
-
def named(name)
|
154
|
-
@@all_sessions[name] || raise("No session named #{name}.")
|
155
|
-
end
|
156
|
-
|
157
|
-
def set_current(session)
|
158
|
-
@@current_session = session
|
159
|
-
end
|
160
|
-
|
161
|
-
def add_listener(&listener)
|
162
|
-
self._listeners << listener
|
163
|
-
end
|
164
|
-
|
165
|
-
def _listeners
|
166
|
-
@@listeners ||= []
|
167
|
-
@@listeners
|
168
|
-
end
|
169
|
-
|
170
|
-
def _notify_listeners(event, data)
|
171
|
-
_listeners.each {|li| li.call(event, data)}
|
172
|
-
end
|
173
|
-
|
174
|
-
def register(session, name = nil, default = nil)
|
175
|
-
if default == true
|
176
|
-
set_current(session)
|
177
|
-
elsif default.nil?
|
178
|
-
set_current(session) unless @@current_session
|
179
|
-
end
|
180
|
-
@@all_sessions[name] = session if name
|
181
|
-
@@current_session
|
182
|
-
end
|
183
|
-
|
184
|
-
def unregister(session)
|
185
|
-
@@current_session = nil if @@current_session == session
|
186
|
-
end
|
187
|
-
|
188
|
-
def all_sessions
|
189
|
-
@@all_sessions
|
190
|
-
end
|
191
|
-
|
192
|
-
def inspect
|
193
|
-
"Neo4j::Session available: #{@@factories && @@factories.keys}"
|
194
|
-
end
|
195
|
-
|
196
|
-
def register_db(db, &session_factory)
|
197
|
-
puts "replace factory for #{db}" if @@factories[db]
|
198
|
-
@@factories[db] = session_factory
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|