neo4j-ruby-driver 4.4.0.alpha.7 → 4.4.0.alpha.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/ruby/neo4j/driver/graph_database.rb +2 -2
  3. data/ruby/neo4j/driver/internal/async/inbound/inbound_message_dispatcher.rb +2 -3
  4. data/ruby/neo4j/driver/internal/async/network_connection.rb +5 -6
  5. data/ruby/neo4j/driver/internal/async/network_session.rb +6 -9
  6. data/ruby/neo4j/driver/internal/async/unmanaged_transaction.rb +18 -20
  7. data/ruby/neo4j/driver/internal/cluster/cluster_routing_table.rb +2 -2
  8. data/ruby/neo4j/driver/internal/cluster/rediscovery_impl.rb +1 -2
  9. data/ruby/neo4j/driver/internal/cluster/single_database_routing_procedure_runner.rb +15 -16
  10. data/ruby/neo4j/driver/internal/cursor/async_result_cursor_impl.rb +29 -19
  11. data/ruby/neo4j/driver/internal/cursor/async_result_cursor_only_factory.rb +0 -4
  12. data/ruby/neo4j/driver/internal/cursor/disposable_async_result_cursor.rb +2 -2
  13. data/ruby/neo4j/driver/internal/cursor/result_cursor_factory_impl.rb +0 -5
  14. data/ruby/neo4j/driver/internal/handlers/commit_tx_response_handler.rb +4 -4
  15. data/ruby/neo4j/driver/internal/handlers/legacy_pull_all_response_handler.rb +23 -64
  16. data/ruby/neo4j/driver/internal/handlers/pulln/auto_pull_response_handler.rb +35 -45
  17. data/ruby/neo4j/driver/internal/handlers/pulln/basic_pull_response_handler.rb +28 -18
  18. data/ruby/neo4j/driver/internal/handlers/rollback_tx_response_handler.rb +7 -1
  19. data/ruby/neo4j/driver/internal/internal_driver.rb +0 -4
  20. data/ruby/neo4j/driver/internal/internal_result.rb +6 -17
  21. data/ruby/neo4j/driver/internal/internal_session.rb +1 -1
  22. data/ruby/neo4j/driver/internal/internal_transaction.rb +4 -4
  23. data/ruby/neo4j/driver/internal/messaging/abstract_message_writer.rb +1 -1
  24. data/ruby/neo4j/driver/internal/messaging/request/abstract_streaming_message.rb +4 -1
  25. data/ruby/neo4j/driver/internal/messaging/v3/bolt_protocol_v3.rb +7 -3
  26. data/ruby/neo4j/driver/internal/messaging/v3/message_writer_v3.rb +13 -13
  27. data/ruby/neo4j/driver/internal/messaging/v4/message_writer_v4.rb +4 -15
  28. data/ruby/neo4j/driver/internal/messaging/v43/message_writer_v43.rb +2 -16
  29. data/ruby/neo4j/driver/internal/messaging/v44/message_writer_v44.rb +2 -13
  30. data/ruby/neo4j/driver/internal/resolved_bolt_server_address.rb +1 -1
  31. data/ruby/neo4j/driver/internal/retry/exponential_backoff_retry_logic.rb +1 -1
  32. data/ruby/neo4j/driver/internal/util/metadata_extractor.rb +1 -3
  33. data/ruby/neo4j/driver/internal/util/result_holder.rb +72 -0
  34. data/ruby/neo4j/driver/version.rb +1 -1
  35. metadata +3 -3
  36. data/ruby/neo4j/driver/session_config.rb +0 -15
@@ -3,6 +3,7 @@ module Neo4j::Driver
3
3
  module Handlers
4
4
  module Pulln
5
5
  class AutoPullResponseHandler < BasicPullResponseHandler
6
+ include Enumerable
6
7
  delegate :signal, to: :@records
7
8
  LONG_MAX_VALUE = 2 ** 63 - 1
8
9
 
@@ -55,7 +56,7 @@ module Neo4j::Driver
55
56
 
56
57
  private def handle_failure(error)
57
58
  # error has not been propagated to the user, remember it
58
- unless fail_record_future(error) && fail_summary_future(error)
59
+ unless fail_record_future(error) || fail_summary_future(error)
59
60
  @failure = error
60
61
  end
61
62
  end
@@ -64,26 +65,31 @@ module Neo4j::Driver
64
65
  while @records.empty? && !done?
65
66
  @records.wait
66
67
  end
67
- @records.items.first
68
+ @records.items.first&.then(&Util::ResultHolder.method(:successful)) or
69
+ completed_with_value_if_no_failure(nil)
68
70
  end
69
71
 
70
72
  def next_async
71
- dequeue_record if peek_async
73
+ peek_async.then { |record| dequeue_record if record }
72
74
  end
73
75
 
74
76
  def consume_async
75
77
  @records.items.clear
76
- return completed_with_value_if_no_failure(@summary) if done?
77
- cancel
78
- @summary
78
+ cancel unless done?
79
+ completed_with_value_if_no_failure(@summary)
79
80
  end
80
81
 
81
- def list_async(&map_function)
82
- pull_all_async.then_apply(-> (summary) { records_as_list(&map_function) })
82
+ def each
83
+ pull_all_async.then do
84
+ unless done?
85
+ raise Exceptions::IllegalStateException, "Can't get records as list because SUCCESS or FAILURE did not arrive"
86
+ end
87
+ @records.each { |record| yield record }
88
+ end
83
89
  end
84
90
 
85
91
  def pull_all_failure_async
86
- pull_all_async
92
+ pull_all_async.chain { |_, error| error }
87
93
  end
88
94
 
89
95
  def pre_populate_records
@@ -94,12 +100,9 @@ module Neo4j::Driver
94
100
 
95
101
  def pull_all_async
96
102
  return completed_with_value_if_no_failure(@summary) if done?
97
-
98
- request(FetchSizeUtil::UNLIMITED_FETCH_SIZE)
99
-
100
- @summary_future = java.util.concurrent.CompletableFuture.new if @summary_future.nil?
101
-
102
- @summary_future
103
+ (@summary_future ||= Util::ResultHolder.new).tap do |_|
104
+ request(FetchSizeUtil::UNLIMITED_FETCH_SIZE)
105
+ end
103
106
  end
104
107
 
105
108
  def enqueue_record(record)
@@ -122,14 +125,6 @@ module Neo4j::Driver
122
125
  record
123
126
  end
124
127
 
125
- def records_as_list(&map_function)
126
- unless done?
127
- raise Exceptions::IllegalStateException, "Can't get records as list because SUCCESS or FAILURE did not arrive"
128
- end
129
-
130
- @records.each.map(&map_function)
131
- end
132
-
133
128
  def extract_failure
134
129
  @failure or raise Exceptions::IllegalStateException, "Can't extract failure because it does not exist"
135
130
  ensure
@@ -137,39 +132,34 @@ module Neo4j::Driver
137
132
  end
138
133
 
139
134
  def complete_record_future(record)
140
- unless @record_future.nil?
141
- future = @record_future
142
- @record_future = nil
143
- future.complete(record)
144
- end
135
+ @record_future&.succeed(record)
136
+ @record_future = nil
145
137
  end
146
138
 
147
139
  def complete_summary_future(summary)
148
- unless @summary_future.nil?
149
- future = @summary_future
150
- @summary_future = nil
151
- future.complete(summary)
152
- end
140
+ @summary_future&.succeed(summary)
141
+ @summary_future = nil
153
142
  end
154
143
 
155
144
  def fail_record_future(error)
156
- unless @record_future.nil?
157
- future = @record_future
158
- @record_future = nil
159
- future.complete(record)
160
- return true
161
- end
145
+ @record_future&.fail(error)
146
+ ensure
147
+ @record_future = nil
148
+ end
162
149
 
163
- false
150
+ def fail_summary_future(error)
151
+ @summary_future&.fail(error)
152
+ ensure
153
+ @summary_future = nil
164
154
  end
165
155
 
166
156
  def completed_with_value_if_no_failure(value)
167
- @failure ? extract_failure : value
157
+ if @failure
158
+ Util::ResultHolder.failed(extract_failure)
159
+ else
160
+ Util::ResultHolder.successful(value)
161
+ end
168
162
  end
169
-
170
- # def request(size)
171
- # @auto_pull_enabled ? Async { super } : super
172
- # end
173
163
  end
174
164
  end
175
165
  end
@@ -99,7 +99,7 @@ module Neo4j::Driver
99
99
  end
100
100
 
101
101
  def done?
102
- @state == State::SUCEEDED_STATE || @state == State::FAILURE_STATE
102
+ @state == State::SUCCEEDED_STATE || @state == State::FAILURE_STATE
103
103
  end
104
104
 
105
105
  private def extract_result_summary(**metadata)
@@ -147,7 +147,7 @@ module Neo4j::Driver
147
147
  end
148
148
 
149
149
  module State
150
- READY_STATE = Class.new do
150
+ class Ready
151
151
  def on_success(context, metadata)
152
152
  context.state = SUCCEEDED_STATE
153
153
  context.complete_with_success(metadata)
@@ -171,15 +171,17 @@ module Neo4j::Driver
171
171
  context.state = CANCELLED_STATE
172
172
  context.discard_all
173
173
  end
174
- end.new
174
+ end
175
+
176
+ READY_STATE = Ready.new
175
177
 
176
- STREAMING_STATE = Class.new do
178
+ class Streaming
177
179
  def on_success(context, metadata)
178
180
  if metadata[:has_more]
179
181
  context.state = READY_STATE
180
182
  context.success_has_more
181
183
  else
182
- context.state = SUCEEDED_STATE
184
+ context.state = SUCCEEDED_STATE
183
185
  context.complete_with_success(metadata)
184
186
  end
185
187
  end
@@ -202,15 +204,17 @@ module Neo4j::Driver
202
204
  def cancel(context)
203
205
  context.state = CANCELLED_STATE
204
206
  end
205
- end.new
207
+ end
208
+
209
+ STREAMING_STATE = Streaming.new
206
210
 
207
- CANCELLED_STATE = Class.new do
211
+ class Cancelled
208
212
  def on_success(context, metadata)
209
213
  if metadata[:has_more]
210
214
  context.state = CANCELLED_STATE
211
215
  context.discard_all
212
216
  else
213
- context.state = SUCEEDED_STATE
217
+ context.state = SUCCEEDED_STATE
214
218
  context.complete_with_success(metadata)
215
219
  end
216
220
  end
@@ -231,11 +235,13 @@ module Neo4j::Driver
231
235
  def cancel(context)
232
236
  context.state = CANCELLED_STATE
233
237
  end
234
- end.new
238
+ end
239
+
240
+ CANCELLED_STATE = Cancelled.new
235
241
 
236
- SUCEEDED_STATE = Class.new do
242
+ class Succeeded
237
243
  def on_success(context, metadata)
238
- context.state = SUCEEDED_STATE
244
+ context.state = SUCCEEDED_STATE
239
245
  context.complete_with_success(metadata)
240
246
  end
241
247
 
@@ -245,21 +251,23 @@ module Neo4j::Driver
245
251
  end
246
252
 
247
253
  def on_record(context, _fields)
248
- context.state = SUCEEDED_STATE
254
+ context.state = SUCCEEDED_STATE
249
255
  end
250
256
 
251
257
  def request(context, _n)
252
- context.state = SUCEEDED_STATE
258
+ context.state = SUCCEEDED_STATE
253
259
  end
254
260
 
255
261
  def cancel(context)
256
- context.state = SUCEEDED_STATE
262
+ context.state = SUCCEEDED_STATE
257
263
  end
258
- end.new
264
+ end
265
+
266
+ SUCCEEDED_STATE = Succeeded.new
259
267
 
260
- FAILURE_STATE = Class.new do
268
+ class Failed
261
269
  def on_success(context, metadata)
262
- context.state = SUCEEDED_STATE
270
+ context.state = SUCCEEDED_STATE
263
271
  context.complete_with_success(metadata)
264
272
  end
265
273
 
@@ -279,7 +287,9 @@ module Neo4j::Driver
279
287
  def cancel(context)
280
288
  context.state = FAILURE_STATE
281
289
  end
282
- end.new
290
+ end
291
+
292
+ FAILURE_STATE = Failed.new
283
293
  end
284
294
  end
285
295
  end
@@ -3,11 +3,17 @@ module Neo4j::Driver
3
3
  module Handlers
4
4
  class RollbackTxResponseHandler
5
5
  include Spi::ResponseHandler
6
+
7
+ def initialize(result_holder)
8
+ @result_holder = result_holder
9
+ end
10
+
6
11
  def on_success(_metadata)
12
+ @result_holder.succeed
7
13
  end
8
14
 
9
15
  def on_failure(error)
10
- raise error
16
+ @result_holder.fail(error)
11
17
  end
12
18
 
13
19
  def on_record(fields)
@@ -21,10 +21,6 @@ module Neo4j::Driver
21
21
  InternalSession.new(new_session(**session_config))
22
22
  end
23
23
 
24
- def rx_session(**session_config)
25
- InternalRxSession.new(new_session(**session_config))
26
- end
27
-
28
24
  def async_session(**session_config)
29
25
  InternalAsyncSession.new(new_session(**session_config))
30
26
  end
@@ -4,34 +4,27 @@ module Neo4j::Driver
4
4
  extend Synchronizable
5
5
  include Enumerable
6
6
  sync :keys, :has_next?, :next, :single, :peek, :consume
7
+ delegate :keys, to: :@cursor
7
8
 
8
9
  def initialize(connection, cursor)
9
10
  @connection = connection
10
11
  @cursor = cursor
11
12
  end
12
13
 
13
- def keys
14
- @keys ||=
15
- begin
16
- @cursor.peek_async
17
- @cursor.keys
18
- end
19
- end
20
-
21
14
  def has_next?
22
- @cursor.peek_async
15
+ @cursor.peek_async.result!
23
16
  end
24
17
 
25
18
  def next
26
- @cursor.next_async || raise(Exceptions::NoSuchRecordException.no_more)
19
+ @cursor.next_async.result! || raise(Exceptions::NoSuchRecordException.no_more)
27
20
  end
28
21
 
29
22
  def single
30
- @cursor.single_async
23
+ @cursor.single_async.result!
31
24
  end
32
25
 
33
26
  def peek
34
- @cursor.peek_async or raise Exceptions::NoSuchRecordException.no_peek_past
27
+ @cursor.peek_async.result! or raise Exceptions::NoSuchRecordException.no_peek_past
35
28
  end
36
29
 
37
30
  def each
@@ -39,7 +32,7 @@ module Neo4j::Driver
39
32
  end
40
33
 
41
34
  def consume
42
- @cursor.consume_async
35
+ @cursor.consume_async.result!
43
36
  end
44
37
 
45
38
  def remove
@@ -48,10 +41,6 @@ module Neo4j::Driver
48
41
 
49
42
  private
50
43
 
51
- def blocking_get(stage)
52
- Util::Futures.blocking_get(stage, &method(:terminate_connection_on_thread_interrupt))
53
- end
54
-
55
44
  def terminate_connection_on_thread_interrupt
56
45
  @connection.terminate_and_release('Thread interrupted while waiting for result to arrive')
57
46
  end
@@ -17,7 +17,7 @@ module Neo4j::Driver
17
17
  Validator.require_hash_parameters!(parameters)
18
18
  cursor = @session.run_async(Query.new(query, **parameters), **TransactionConfig.new(**config.compact)) do
19
19
  terminate_connection_on_thread_interrupt('Thread interrupted while running query in session')
20
- end
20
+ end.result!
21
21
 
22
22
  # query executed, it is safe to obtain a connection in a blocking way
23
23
  connection = @session.connection_async
@@ -10,28 +10,28 @@ module Neo4j::Driver
10
10
  end
11
11
 
12
12
  def commit
13
- @tx.commit_async
13
+ @tx.commit_async.result!
14
14
  # org.neo4j.driver.internal.util.Futures.blockingGet(@tx.commit_async) do
15
15
  # terminate_connection_on_thread_interrupt('Thread interrupted while committing the transaction')
16
16
  # end
17
17
  end
18
18
 
19
19
  def rollback
20
- @tx.rollback_async
20
+ @tx.rollback_async.result!
21
21
  # org.neo4j.driver.internal.util.Futures.blockingGet(@tx.rollback_async) do
22
22
  # terminate_connection_on_thread_interrupt('Thread interrupted while rolling back the transaction')
23
23
  # end
24
24
  end
25
25
 
26
26
  def close
27
- @tx.close_async
27
+ @tx.close_async.result!
28
28
  # org.neo4j.driver.internal.util.Futures.blockingGet(@tx.close_async) do
29
29
  # terminate_connection_on_thread_interrupt('Thread interrupted while closing the transaction')
30
30
  # end
31
31
  end
32
32
 
33
33
  def run(query, **parameters)
34
- cursor = @tx.run_async(Query.new(query, **parameters))
34
+ cursor = @tx.run_async(Query.new(query, **parameters)).result!
35
35
  # cursor = org.neo4j.driver.internal.util.Futures.blockingGet(@tx.run_async(to_statement(query, parameters))) do
36
36
  # terminate_connection_on_thread_interrupt('Thread interrupted while running query in transaction')
37
37
  # end
@@ -4,7 +4,7 @@ module Neo4j::Driver
4
4
  class AbstractMessageWriter
5
5
  def initialize(packer)
6
6
  @packer = Internal::Validator.require_non_nil!(packer)
7
- @encoders_by_message_signature = Internal::Validator.require_non_nil!(build_encoders)
7
+ @encoders_by_message_signature = Internal::Validator.require_non_nil!(build_encoders).transform_values(&:new)
8
8
  end
9
9
 
10
10
  def write(msg)
@@ -4,7 +4,10 @@ module Neo4j::Driver
4
4
  module Request
5
5
  class AbstractStreamingMessage < Struct.new(:n, :qid)
6
6
  STREAM_LIMIT_UNLIMITED = -1
7
- alias metadata to_h
7
+
8
+ def metadata
9
+ to_h.compact
10
+ end
8
11
 
9
12
  def to_s
10
13
  "#{name} #{metadata}"
@@ -36,12 +36,16 @@ module Neo4j::Driver
36
36
  connection.write_and_flush(begin_message, Handlers::BeginTxResponseHandler.new)
37
37
  end
38
38
 
39
- def commit_transaction(connection, bookmark_holder)
40
- connection.write_and_flush(Request::CommitMessage::COMMIT, Handlers::CommitTxResponseHandler.new(bookmark_holder))
39
+ def commit_transaction(connection)
40
+ Util::ResultHolder.new.tap do |result_holder|
41
+ connection.write_and_flush(Request::CommitMessage::COMMIT, Handlers::CommitTxResponseHandler.new(result_holder))
42
+ end
41
43
  end
42
44
 
43
45
  def rollback_transaction(connection)
44
- connection.write_and_flush(Request::RollbackMessage::ROLLBACK, Handlers::RollbackTxResponseHandler.new)
46
+ Util::ResultHolder.new.tap do |result_holder|
47
+ connection.write_and_flush(Request::RollbackMessage::ROLLBACK, Handlers::RollbackTxResponseHandler.new(result_holder))
48
+ end
45
49
  end
46
50
 
47
51
  def run_in_auto_commit_transaction(connection, query, bookmark_holder, config, fetch_size)
@@ -3,22 +3,22 @@ module Neo4j::Driver
3
3
  module Messaging
4
4
  module V3
5
5
  class MessageWriterV3 < AbstractMessageWriter
6
+ COMMON_ENCODERS = {
7
+ Request::HelloMessage::SIGNATURE => Encode::HelloMessageEncoder,
8
+ Request::GoodbyeMessage::SIGNATURE => Encode::GoodbyeMessageEncoder,
9
+ Request::RunWithMetadataMessage::SIGNATURE => Encode::RunWithMetadataMessageEncoder,
10
+ Request::BeginMessage::SIGNATURE => Encode::BeginMessageEncoder,
11
+ Request::CommitMessage::SIGNATURE => Encode::CommitMessageEncoder,
12
+ Request::RollbackMessage::SIGNATURE => Encode::RollbackMessageEncoder,
13
+ Request::ResetMessage::SIGNATURE => Encode::ResetMessageEncoder,
14
+ }
6
15
  private
7
16
 
8
17
  def build_encoders
9
- {
10
- Request::HelloMessage::SIGNATURE => Encode::HelloMessageEncoder.new,
11
- Request::GoodbyeMessage::SIGNATURE => Encode::GoodbyeMessageEncoder.new,
12
-
13
- Request::RunWithMetadataMessage::SIGNATURE => Encode::RunWithMetadataMessageEncoder.new,
14
- Request::DiscardAllMessage::SIGNATURE => Encode::DiscardAllMessageEncoder.new,
15
- Request::PullAllMessage::SIGNATURE => Encode::PullAllMessageEncoder.new,
16
-
17
- Request::BeginMessage::SIGNATURE => Encode::BeginMessageEncoder.new,
18
- Request::CommitMessage::SIGNATURE => Encode::CommitMessageEncoder.new,
19
- Request::RollbackMessage::SIGNATURE => Encode::RollbackMessageEncoder.new,
20
- Request::ResetMessage::SIGNATURE => Encode::ResetMessageEncoder.new,
21
- }
18
+ COMMON_ENCODERS.merge(
19
+ Request::DiscardAllMessage::SIGNATURE => Encode::DiscardAllMessageEncoder,
20
+ Request::PullAllMessage::SIGNATURE => Encode::PullAllMessageEncoder,
21
+ )
22
22
  end
23
23
  end
24
24
  end
@@ -2,24 +2,13 @@ module Neo4j::Driver
2
2
  module Internal
3
3
  module Messaging
4
4
  module V4
5
- class MessageWriterV4 < AbstractMessageWriter
5
+ class MessageWriterV4 < V3::MessageWriterV3
6
6
  private
7
7
 
8
8
  def build_encoders
9
- {
10
- Request::HelloMessage::SIGNATURE => Encode::HelloMessageEncoder.new,
11
- Request::GoodbyeMessage::SIGNATURE => Encode::GoodbyeMessageEncoder.new,
12
- Request::RunWithMetadataMessage::SIGNATURE => Encode::RunWithMetadataMessageEncoder.new,
13
-
14
- Request::DiscardAllMessage::SIGNATURE => Encode::DiscardAllMessageEncoder.new, # new
15
- Request::PullMessage::SIGNATURE => Encode::PullMessageEncoder.new, # new
16
-
17
- Request::BeginMessage::SIGNATURE => Encode::BeginMessageEncoder.new,
18
- Request::CommitMessage::SIGNATURE => Encode::CommitMessageEncoder.new,
19
- Request::RollbackMessage::SIGNATURE => Encode::RollbackMessageEncoder.new,
20
-
21
- Request::ResetMessage::SIGNATURE => Encode::ResetMessageEncoder.new,
22
- }
9
+ COMMON_ENCODERS.merge(
10
+ Request::DiscardMessage::SIGNATURE => Encode::DiscardMessageEncoder,
11
+ Request::PullMessage::SIGNATURE => Encode::PullMessageEncoder)
23
12
  end
24
13
  end
25
14
  end
@@ -7,25 +7,11 @@ module Neo4j::Driver
7
7
  # This version is able to encode all the versions existing on v4.2, but it encodes
8
8
 
9
9
  # new messages such as ROUTE
10
- class MessageWriterV43 < AbstractMessageWriter
10
+ class MessageWriterV43 < V4::MessageWriterV4
11
11
  private
12
12
 
13
13
  def build_encoders
14
- {
15
- Request::HelloMessage::SIGNATURE => Encode::HelloMessageEncoder.new,
16
- Request::GoodbyeMessage::SIGNATURE => Encode::GoodbyeMessageEncoder.new,
17
- Request::RunWithMetadataMessage::SIGNATURE => Encode::RunWithMetadataMessageEncoder.new,
18
- Request::RouteMessage::SIGNATURE => Encode::RouteMessageEncoder.new, # new
19
-
20
- Request::DiscardMessage::SIGNATURE => Encode::DiscardMessageEncoder.new,
21
- Request::PullMessage::SIGNATURE => Encode::PullMessageEncoder.new,
22
-
23
- Request::BeginMessage::SIGNATURE => Encode::BeginMessageEncoder.new,
24
- Request::CommitMessage::SIGNATURE => Encode::CommitMessageEncoder.new,
25
- Request::RollbackMessage::SIGNATURE => Encode::RollbackMessageEncoder.new,
26
-
27
- Request::ResetMessage::SIGNATURE => Encode::ResetMessageEncoder.new,
28
- }
14
+ super.merge(Request::RouteMessage::SIGNATURE => Encode::RouteMessageEncoder)
29
15
  end
30
16
  end
31
17
  end
@@ -2,22 +2,11 @@ module Neo4j::Driver
2
2
  module Internal
3
3
  module Messaging
4
4
  module V44
5
- class MessageWriterV44 < AbstractMessageWriter
5
+ class MessageWriterV44 < V4::MessageWriterV4
6
6
  private
7
7
 
8
8
  def build_encoders
9
- {
10
- Request::HelloMessage::SIGNATURE => Encode::HelloMessageEncoder.new,
11
- Request::GoodbyeMessage::SIGNATURE => Encode::GoodbyeMessageEncoder.new,
12
- Request::RunWithMetadataMessage::SIGNATURE => Encode::RunWithMetadataMessageEncoder.new,
13
- Request::RouteMessage::SIGNATURE => Encode::RouteV44MessageEncoder.new,
14
- Request::DiscardMessage::SIGNATURE => Encode::DiscardMessageEncoder.new,
15
- Request::PullMessage::SIGNATURE => Encode::PullMessageEncoder.new,
16
- Request::BeginMessage::SIGNATURE => Encode::BeginMessageEncoder.new,
17
- Request::CommitMessage::SIGNATURE => Encode::CommitMessageEncoder.new,
18
- Request::RollbackMessage::SIGNATURE => Encode::RollbackMessageEncoder.new,
19
- Request::ResetMessage::SIGNATURE => Encode::ResetMessageEncoder.new,
20
- }
9
+ super.merge(Request::RouteMessage::SIGNATURE => Encode::RouteV44MessageEncoder)
21
10
  end
22
11
  end
23
12
  end
@@ -22,7 +22,7 @@ module Neo4j::Driver
22
22
  @string_value
23
23
  end
24
24
 
25
- private def attributes
25
+ def attributes
26
26
  super + [@resolved_addresses]
27
27
  end
28
28
 
@@ -143,7 +143,7 @@ module Neo4j::Driver
143
143
  end
144
144
 
145
145
  def add_suppressed(error, suppressed_errors)
146
- suppressed_errors&.reject(&error.method(:equal?))&.each(&error.method(:add_suppressed))
146
+ suppressed_errors&.reject(&error.method(:equal?))&.each(&error.method(:add_suppressed)) if error.is_a? Exceptions::Neo4jException
147
147
  end
148
148
  end
149
149
  end
@@ -2,8 +2,6 @@ module Neo4j::Driver
2
2
  module Internal
3
3
  module Util
4
4
  class MetadataExtractor
5
- ABSENT_QUERY_ID = -1
6
-
7
5
  def initialize(result_available_after_metadata_key, result_consumed_after_metadata_key)
8
6
  @result_available_after_metadata_key = result_available_after_metadata_key
9
7
  @result_consumed_after_metadata_key = result_consumed_after_metadata_key
@@ -14,7 +12,7 @@ module Neo4j::Driver
14
12
  end
15
13
 
16
14
  def extract_query_id(metadata)
17
- metadata[:qid] || ABSENT_QUERY_ID
15
+ metadata[:qid]
18
16
  end
19
17
 
20
18
  def extract_result_available_after(metadata)
@@ -0,0 +1,72 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Util
4
+ class ResultHolder
5
+ attr :error
6
+
7
+ def self.successful(result = nil)
8
+ new.tap { |holder| holder.succeed(result) }
9
+ end
10
+
11
+ def self.failed(error)
12
+ new.tap { |holder| holder.fail(error) }
13
+ end
14
+
15
+ def succeed(result = nil)
16
+ if @completed
17
+ false
18
+ else
19
+ @result = result
20
+ true
21
+ end
22
+ ensure
23
+ @completed = true
24
+ end
25
+
26
+ def fail(error)
27
+ if @completed
28
+ false
29
+ else
30
+ @error = error
31
+ true
32
+ end
33
+ ensure
34
+ @completed = true
35
+ end
36
+
37
+ def result!
38
+ raise @error if @error
39
+ @result
40
+ end
41
+
42
+ def then
43
+ @error ? self : ResultHolder.successful(yield(@result))
44
+ end
45
+
46
+ # &block returns a ResultHolder
47
+ def compose
48
+ @error ? self : yield(@result)
49
+ end
50
+
51
+ def chain
52
+ ResultHolder.successful(yield(@result, @error))
53
+ rescue => error
54
+ ResultHolder.failed(error)
55
+ end
56
+
57
+ def side
58
+ yield(@result, @error)
59
+ self
60
+ end
61
+
62
+ def copy_to(result_holder)
63
+ if @error
64
+ result_holder.fail(@error)
65
+ else
66
+ result_holder.succeed(@result)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end