neo4j-core 6.0.0.alpha.2 → 6.0.0.alpha.5

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: c1343fde92853fec5efe74f6e6bff1953e80d087
4
- data.tar.gz: 7ba6ae057e66b0da4f47510925fab98f9d92f4ce
3
+ metadata.gz: da1d3afa114538d40feb6d6765112f282c13ebee
4
+ data.tar.gz: fe9f7472deaddd1123e62ca73a02ed3ec70431b7
5
5
  SHA512:
6
- metadata.gz: eacf72160d677bd80141f8d399520adb7fca8ae5d650d5bc389dbd42b25eb2d61fc1e1f4fb9e02577e9f8a3e5000c6e93f7c80edf6cd3500618a84fed6bbdc68
7
- data.tar.gz: 81f69bd7122e7d1fbf7a26a432a6c179f2ba739f1ee0be127dec3dd6b62481019f0311afbc7c752578019deec03c1730b0434ffbc8e41df6d20be12b87c2517e
6
+ metadata.gz: 36fa2080886b9b51eb29ec518399153474e4f113c7530ff137a55453397d7c3ec1f3407178d1d3ff3d28b4aacf85c0ea5740f47e646d1945cce524233c48946d
7
+ data.tar.gz: 94a3b1aadca366cdf2485de538fe0b6fc95e570f811ee8415b4826a6e4ab17d0a896b46e99f8f4d4f1ef253dba8afba65d37d64606ee5c1c6bb2405262771c9b
data/Gemfile CHANGED
@@ -15,4 +15,5 @@ group 'test' do
15
15
  gem 'simplecov-html', require: false
16
16
  gem 'rspec', '~> 3.0'
17
17
  gem 'rspec-its'
18
+ gem 'dotenv'
18
19
  end
@@ -232,9 +232,13 @@ module Neo4j
232
232
  cypher = to_cypher
233
233
  pretty_cypher = to_cypher(pretty: true) if self.class.pretty_cypher
234
234
 
235
- @response = @session._query(cypher, merge_params, context: @options[:context], pretty_cypher: pretty_cypher)
235
+ @response = if @session.is_a?(::Neo4j::Core::CypherSession)
236
+ @session.query(self)
237
+ else
238
+ @session._query(cypher, merge_params, context: @options[:context], pretty_cypher: pretty_cypher)
239
+ end
236
240
 
237
- (!response.respond_to?(:error?) || !response.error?) ? response : response.raise_cypher_error
241
+ (!@response.respond_to?(:error?) || !response.error?) ? @response : @response.raise_cypher_error
238
242
  end
239
243
 
240
244
  def match_nodes(hash, optional_match = false)
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = '6.0.0.alpha.2'
3
+ VERSION = '6.0.0.alpha.5'
4
4
  end
5
5
  end
@@ -9,7 +9,6 @@ module Neo4j
9
9
  class EmbeddedImpermanentSession < EmbeddedSession
10
10
  def start
11
11
  fail Error, 'Embedded Neo4j db is already running' if running?
12
- puts 'Start test impermanent embedded Neo4j db'
13
12
  @graph_db = Java::OrgNeo4jTest::TestGraphDatabaseFactory.new.newImpermanentDatabase
14
13
  Neo4j::Session._notify_listeners(:session_available, self)
15
14
  end
@@ -73,12 +73,17 @@ module Neo4j
73
73
  cypher_response.set_data(first_result)
74
74
  else
75
75
  first_error = response.body[:errors].first
76
- mark_expired if first_error[:message].match(/Unrecognized transaction id/)
76
+ tx_cleanup!(first_error)
77
77
  cypher_response.set_error(first_error)
78
78
  end
79
79
  end
80
80
  end
81
81
 
82
+ def tx_cleanup!(first_error)
83
+ autoclosed!
84
+ mark_expired if first_error[:message].match(/Unrecognized transaction id/)
85
+ end
86
+
82
87
  def empty_response
83
88
  OpenStruct.new(status: 200, body: '')
84
89
  end
@@ -1,4 +1,3 @@
1
- require 'neo4j/core/cypher_session/adaptors/http'
2
1
 
3
2
  module Neo4j
4
3
  module Core
@@ -14,13 +13,19 @@ module Neo4j
14
13
  %w(
15
14
  query
16
15
  queries
16
+
17
17
  start_transaction
18
18
  end_transaction
19
+ transaction
20
+ transaction_started?
21
+
19
22
  version
20
- transactions
21
- ).each do |method|
22
- define_method(method) do |*args|
23
- @adaptor.send(method, *args)
23
+
24
+ indexes_for_label
25
+ uniqueness_constraints_for_label
26
+ ).each do |method, &_block|
27
+ define_method(method) do |*args, &block|
28
+ @adaptor.send(method, *args, &block)
24
29
  end
25
30
  end
26
31
  end
@@ -1,3 +1,4 @@
1
+ require 'neo4j/core/cypher_session'
1
2
  require 'neo4j/core/instrumentable'
2
3
 
3
4
  module Neo4j
@@ -42,10 +43,8 @@ module Neo4j
42
43
  end
43
44
  end
44
45
 
45
- def query(cypher, parameters = {})
46
- queries do
47
- append(cypher, parameters)
48
- end[0]
46
+ def query(*args)
47
+ queries { append(*args) }[0]
49
48
  end
50
49
 
51
50
  def queries(&block)
@@ -68,10 +67,24 @@ module Neo4j
68
67
  fail '#end_transaction not implemented!'
69
68
  end
70
69
 
70
+ def transaction_started?(*_args)
71
+ fail '#transaction_started? not implemented!'
72
+ end
73
+
71
74
  def version(*_args)
72
75
  fail '#version not implemented!'
73
76
  end
74
77
 
78
+ # Schema inspection methods
79
+ def indexes_for_label(*_args)
80
+ fail '#indexes_for_label not implemented!'
81
+ end
82
+
83
+ def uniqueness_constraints_for_label(*_args)
84
+ fail '#uniqueness_constraints_for_label not implemented!'
85
+ end
86
+
87
+
75
88
  # Uses #start_transaction and #end_transaction to allow
76
89
  # execution of queries within a block to be part of a
77
90
  # full transaction
@@ -80,7 +93,7 @@ module Neo4j
80
93
 
81
94
  yield
82
95
  ensure
83
- end_transaction
96
+ end_transaction if transaction_started?
84
97
  end
85
98
 
86
99
  EMPTY = ''
@@ -53,6 +53,10 @@ module Neo4j
53
53
  @transaction.close
54
54
  end
55
55
 
56
+ def transaction_started?
57
+ !!@transaction
58
+ end
59
+
56
60
  def version
57
61
  if defined?(::Neo4j::Community)
58
62
  ::Neo4j::Community::NEO_VERSION
@@ -34,7 +34,8 @@ module Neo4j
34
34
  # context option not implemented
35
35
  self.class.instrument_queries(queries)
36
36
 
37
- url = full_transaction_url
37
+ return unless url = full_transaction_url
38
+
38
39
  faraday_response = self.class.instrument_request(url, request_data) do
39
40
  @connection.post(url, request_data)
40
41
  end
@@ -64,14 +65,43 @@ module Neo4j
64
65
  @transaction_state = :close_requested
65
66
  query_set([])
66
67
  @transaction_state = nil
68
+ @transaction_id = nil
67
69
 
68
70
  true
69
71
  end
70
72
 
73
+ def transaction_started?
74
+ !!@transaction_id
75
+ end
76
+
71
77
  def version
72
78
  @version ||= @connection.get(db_data_url).body[:neo4j_version]
73
79
  end
74
80
 
81
+ # Schema inspection methods
82
+ def indexes_for_label(label)
83
+ url = db_data_url + "schema/index/#{label}"
84
+ response = @connection.get(url)
85
+
86
+ if response.body && response.body[0]
87
+ response.body[0][:property_keys].map(&:to_sym)
88
+ else
89
+ []
90
+ end
91
+ end
92
+
93
+ def uniqueness_constraints_for_label(label)
94
+ url = db_data_url + "schema/constraint/#{label}/uniqueness"
95
+ response = @connection.get(url)
96
+
97
+ if response.body && response.body[0]
98
+ response.body[0][:property_keys].map(&:to_sym)
99
+ else
100
+ []
101
+ end
102
+ end
103
+
104
+
75
105
  instrument(:request, 'neo4j.core.http.request', %w(url body)) do |_, start, finish, _id, payload|
76
106
  ms = (finish - start) * 1000
77
107
 
@@ -89,14 +119,12 @@ module Neo4j
89
119
  end
90
120
 
91
121
  def full_transaction_url
92
- path = case @transaction_state
93
- when nil then '/commit'
94
- when :open_requested then ''
95
- when :open then "/#{@transaction_id}"
96
- when :close_requested then "/#{@transaction_id}/commit"
97
- end
98
-
99
- db_data_url + 'transaction' + path
122
+ path = ''
123
+ path << "/#{@transaction_id}" if [:open, :close_requested].include?(@transaction_state)
124
+ path << '/commit' if [nil, :close_requested].include?(@transaction_state)
125
+ path = nil if @transaction_state == :close_requested && !@transaction_id
126
+
127
+ db_data_url + 'transaction' + path if path
100
128
  end
101
129
 
102
130
  def db_data_url
@@ -89,8 +89,12 @@ module Neo4j
89
89
  end
90
90
 
91
91
  def validate_faraday_response!(faraday_response)
92
- if error = faraday_response.body[:errors][0]
93
- fail CypherError, "#{ANSI::CYAN}#{error[:code]}#{ANSI::CLEAR}: #{error[:message]}"
92
+ if faraday_response.body.is_a?(Hash) && error = faraday_response.body[:errors][0]
93
+ error = <<-ERROR
94
+ Request to: #{ANSI::BOLD}#{faraday_response.env.url}#{ANSI::CLEAR}
95
+ #{ANSI::CYAN}#{error[:code]}#{ANSI::CLEAR}: #{error[:message]}
96
+ ERROR
97
+ fail CypherError, error
94
98
  end
95
99
 
96
100
  return if (200..299).include?(status = faraday_response.status)
@@ -11,7 +11,7 @@ module Neo4j
11
11
  def initialize(columns, rows)
12
12
  @columns = columns.map(&:to_sym)
13
13
  @rows = rows
14
- @struct_class = Struct.new(*@columns)
14
+ @struct_class = Struct.new(:index, *@columns)
15
15
  end
16
16
 
17
17
  include Enumerable
@@ -23,8 +23,8 @@ module Neo4j
23
23
  end
24
24
 
25
25
  def structs
26
- @structs ||= rows.map do |row|
27
- @struct_class.new(*row)
26
+ @structs ||= rows.each_with_index.map do |row, index|
27
+ @struct_class.new(index, *row)
28
28
  end
29
29
  end
30
30
 
@@ -8,6 +8,9 @@ module Neo4j
8
8
 
9
9
  include Wrappable
10
10
 
11
+ # Perhaps we should deprecate this?
12
+ alias_method :neo_id, :id
13
+
11
14
  def initialize(id, labels, properties = {})
12
15
  @id = id
13
16
  @labels = labels.map(&:to_sym) unless labels.nil?
@@ -21,6 +21,18 @@ module Neo4j
21
21
  end
22
22
  alias_method :failure?, :failed?
23
23
 
24
+ def autoclosed!
25
+ @autoclosed = true if transient_failures_autoclose?
26
+ end
27
+
28
+ def transient_failures_autoclose?
29
+ Neo4j::Session.current.version >= '2.2.6'
30
+ end
31
+
32
+ def autoclosed?
33
+ !!@autoclosed
34
+ end
35
+
24
36
  def mark_expired
25
37
  @expired = true
26
38
  end
@@ -61,7 +73,18 @@ module Neo4j
61
73
  return if @pushed_nested >= 0
62
74
  fail "Can't commit transaction, already committed" if @pushed_nested < -1
63
75
  Neo4j::Transaction.unregister(self)
64
- failed? ? delete : commit
76
+ post_close!
77
+ end
78
+
79
+ private
80
+
81
+ def post_close!
82
+ return if autoclosed?
83
+ if failed?
84
+ delete
85
+ else
86
+ commit
87
+ end
65
88
  end
66
89
  end
67
90
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.alpha.2
4
+ version: 6.0.0.alpha.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge, Chris Grigg, Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-17 00:00:00.000000000 Z
11
+ date: 2015-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -325,7 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
325
  version: 1.3.1
326
326
  requirements: []
327
327
  rubyforge_project:
328
- rubygems_version: 2.4.6
328
+ rubygems_version: 2.4.5.1
329
329
  signing_key:
330
330
  specification_version: 4
331
331
  summary: A basic library to work with the graph database Neo4j.