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

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
  SHA256:
3
- metadata.gz: a035a8385e54c70c851003ce4131072610617d515f118d2d4b03f6ada71de3a7
4
- data.tar.gz: bc8dfddb76165d4aea25d702e1d4bb1be5db3bb375d25f48fab39acb7f247c07
3
+ metadata.gz: d282964e01764e3a21d07c1e836567b3bc1f334e08d45b7392984db661faa14a
4
+ data.tar.gz: afc45978f3583f6f491c75c5f4f9da89099620d0be88c0367c8e9469554ecc20
5
5
  SHA512:
6
- metadata.gz: 17a1b5ada9f09120e7dda4316504d59fedf366696d27c26e87c5feeee381a876409a75eaa05cbc177af64415946af7ec8c1de7b4ed5e637ffc464a40c1fd4eea
7
- data.tar.gz: aa41d20c4794dac6841aa1bf70cb0c3e8573a658e74d8aa4e475f45a2a0a9072056633a83f8744251014ab5a805b6ec368f4a75b036316c2179bc1bcc1f8f8fa
6
+ metadata.gz: 0a40657edbf022793691d6926f93ae779d4b671878cdbd29538a0ff83bd82de1912210380715390219503a1fbfb3ada37ae70cce66e6184664b1a90fbff12f80
7
+ data.tar.gz: 4ae8f0cb141fc923df3fc8bfab0696adb979a40331e76a440096eb64b3d8060a2f70e49934ed6af06015f734cc1d4f85468b0118b3231db1df4369ff93c0fa63
@@ -26,12 +26,12 @@ module Neo4j::Driver
26
26
  )
27
27
  end
28
28
 
29
- def routing_driver(routing_uris, auth_toke, **config)
29
+ def routing_driver(routing_uris, auth_token, **config)
30
30
  assert_routing_uris(routing_uris)
31
31
  log = Config.new(**config)[:logger]
32
32
 
33
33
  routing_uris.each do |uri|
34
- driver = driver(uri, auth_toke, **config)
34
+ driver = driver(uri, auth_token, **config)
35
35
  begin
36
36
  return driver.tap(&:verify_connectivity)
37
37
  rescue Exceptions::ServiceUnavailableException => e
@@ -59,7 +59,8 @@ module Neo4j::Driver
59
59
  raise @current_error if Util::ErrorUtil.fatal?(@current_error) # TODO clarify
60
60
 
61
61
  if @current_error.is_a?(Exceptions::AuthorizationExpiredException)
62
- Connection::ChannelAttributes.authorization_state_listener(@channel).on_expired(@current_error, @channel)
62
+ # TODO: ??????
63
+ # Connection::ChannelAttributes.authorization_state_listener(@channel).on_expired(@current_error, @channel)
63
64
  else
64
65
  # write a RESET to "acknowledge" the failure
65
66
  enqueue(Handlers::ResetResponseHandler.new(self))
@@ -115,8 +116,6 @@ module Neo4j::Driver
115
116
  end
116
117
 
117
118
  def clear_current_error
118
- raise @current_error if @current_error
119
- ensure
120
119
  @current_error = nil
121
120
  end
122
121
 
@@ -52,28 +52,30 @@ module Neo4j::Driver
52
52
  def close_async(commit = false, complete_with_null_if_not_open = true)
53
53
  @lock.synchronize do
54
54
  if complete_with_null_if_not_open && !open?
55
- nil
55
+ Util::ResultHolder.successful(nil)
56
56
  elsif @state == State::COMMITTED
57
- raise Neo4j::Driver::Exceptions::ClientException, commit ? CANT_COMMIT_COMMITTED_MSG : CANT_ROLLBACK_COMMITTED_MSG
57
+ Util::ResultHolder.failed(Neo4j::Driver::Exceptions::ClientException.new(
58
+ commit ? CANT_COMMIT_COMMITTED_MSG : CANT_ROLLBACK_COMMITTED_MSG))
58
59
  elsif @state == State::ROLLED_BACK
59
- raise Neo4j::Driver::Exceptions::ClientException, commit ? CANT_COMMIT_ROLLED_BACK_MSG : CANT_ROLLBACK_ROLLED_BACK_MSG
60
+ Util::ResultHolder.failed(Neo4j::Driver::Exceptions::ClientException.new(
61
+ commit ? CANT_COMMIT_ROLLED_BACK_MSG : CANT_ROLLBACK_ROLLED_BACK_MSG))
60
62
  else
61
63
  if commit
62
64
  if @rollback_pending
63
- raise Neo4j::Driver::Exceptions::ClientException, CANT_COMMIT_ROLLING_BACK_MSG
65
+ Util::ResultHolder.failed(Neo4j::Driver::Exceptions::ClientException.new(CANT_COMMIT_ROLLING_BACK_MSG))
64
66
  elsif @commit_pending
65
67
  @commit_pending
66
68
  else
67
- @commit_pending = true
69
+ @commit_pending = Util::ResultHolder.new
68
70
  nil
69
71
  end
70
72
  else
71
73
  if @commit_pending
72
- raise Neo4j::Driver::Exceptions::ClientException, CANT_ROLLBACK_COMMITTING_MSG
74
+ Util::ResultHolder.failed(Neo4j::Driver::Exceptions::ClientException.new(CANT_ROLLBACK_COMMITTING_MSG))
73
75
  elsif @rollback_pending
74
76
  @rollback_pending
75
77
  else
76
- @rollback_pending = true
78
+ @rollback_pending = Util::ResultHolder.new
77
79
  nil
78
80
  end
79
81
  end
@@ -83,22 +85,18 @@ module Neo4j::Driver
83
85
  if commit
84
86
  target_future = @commit_pending
85
87
  target_action = lambda { |throwable|
86
- do_commit_async(throwable)
87
- handle_commit_or_rollback(throwable)
88
+ do_commit_async(throwable).chain(&handle_commit_or_rollback(throwable))
88
89
  }
89
90
  else
90
91
  target_future = @rollback_pending
91
92
  target_action = lambda { |throwable|
92
- do_rollback_async
93
- handle_commit_or_rollback(throwable)
93
+ do_rollback_async.chain(&handle_commit_or_rollback(throwable))
94
94
  }
95
95
  end
96
96
 
97
97
  @result_cursors.retrieve_not_consumed_error.then(&target_action)
98
- handle_transaction_completion(commit, nil)
98
+ .side { |_, error| handle_transaction_completion(commit, error) }.copy_to(target_future)
99
99
  target_future
100
- rescue => throwable
101
- handle_transaction_completion(commit, throwable)
102
100
  end
103
101
  end
104
102
 
@@ -148,7 +146,7 @@ module Neo4j::Driver
148
146
  raise Neo4j::Driver::Exceptions::ClientException, 'Cannot run more queries in this transaction, it has been rolled back'
149
147
  when State::TERMINATED
150
148
  # TODO clunky positional arguments of Neo4jException#initialize, move to named parameters
151
- raise Neo4j::Driver::Exceptions::ClientException, 'Cannot run more queries in this transaction, it has either experienced an fatal error or was explicitly terminated'#, # TODO should be able to pass @cause_of_termination
149
+ raise Neo4j::Driver::Exceptions::ClientException, 'Cannot run more queries in this transaction, it has either experienced an fatal error or was explicitly terminated' #, # TODO should be able to pass @cause_of_termination
152
150
  end
153
151
  end
154
152
  end
@@ -175,23 +173,23 @@ module Neo4j::Driver
175
173
  end
176
174
 
177
175
  if exception
178
- Util::Futures.failed_future(exception)
176
+ Util::ResultHolder.failed(exception)
179
177
  else
180
- @protocol.commit_transaction(@connection, @bookmark_holder)
178
+ @protocol.commit_transaction(@connection).then(&@bookmark_holder.method(:bookmark=))
181
179
  end
182
180
  end
183
181
 
184
182
  def do_rollback_async
185
183
  if @lock.synchronize { @state } == State::TERMINATED
186
- Util::Futures.completed_with_null
184
+ Util::ResultHolder.successful(nil)
187
185
  else
188
186
  @protocol.rollback_transaction(@connection)
189
187
  end
190
188
  end
191
189
 
192
190
  def handle_commit_or_rollback(cursor_failure)
193
- lambda { |_fulfilled, _value, commit_or_rollback_error|
194
- combined_error = Util::Futures.combined_error(cursor_failure, commit_or_rollback_error)
191
+ lambda { |_value, commit_or_rollback_error|
192
+ combined_error = Util::Futures.combine_errors(cursor_failure, commit_or_rollback_error)
195
193
  raise combined_error if combined_error
196
194
  }
197
195
  end
@@ -105,8 +105,8 @@ module Neo4j::Driver
105
105
  addresses.map { |address| address == old_address ? new_address : address }.freeze
106
106
  end
107
107
 
108
- def new_with_reused_addresses(current_addresses, disused_addresses, new_addresses)
109
- (current_addresses + disused_addresses + new_addresses).freeze
108
+ def new_with_reused_addresses(*addresses)
109
+ addresses.map(&:to_set).reduce(&:+).freeze
110
110
  end
111
111
 
112
112
  def to_bolt_server_address(address)
@@ -16,9 +16,9 @@ module Neo4j::Driver
16
16
  delegate = connection(connection)
17
17
  procedure = procedure_query(connection.server_version, database_name)
18
18
  bookmark_holder = bookmark_holder(bookmark)
19
- records = run_procedure(delegate, procedure, bookmark_holder)
20
- release_connection(delegate)
21
- process_procedure_response(procedure, records, error)
19
+ run_procedure(delegate, procedure, bookmark_holder)
20
+ .side { release_connection(delegate) }
21
+ .chain { |records, error| process_procedure_response(procedure, records, error) }
22
22
  end
23
23
 
24
24
  private
@@ -32,7 +32,7 @@ module Neo4j::Driver
32
32
  raise Exceptions::FatalDiscoveryException, "Refreshing routing table for multi-databases is not supported in server version lower than 4.0. Current server version: #{server_version}. Database name: '#{database_name.description}'"
33
33
  end
34
34
 
35
- Query.new(GET_ROUTING_TABLE, Values.parameters(ROUTING_CONTEXT, @context.to_map))
35
+ Query.new(GET_ROUTING_TABLE, ROUTING_CONTEXT => @context.to_h)
36
36
  end
37
37
 
38
38
  def bookmark_holder(_ignored)
@@ -43,7 +43,7 @@ module Neo4j::Driver
43
43
  connection.protocol
44
44
  .run_in_auto_commit_transaction(connection, procedure, bookmark_holder, TransactionConfig.empty,
45
45
  Handlers::Pulln::FetchSizeUtil::UNLIMITED_FETCH_SIZE)
46
- .async_result.to_a
46
+ .async_result.then(&:to_a)
47
47
  end
48
48
 
49
49
  def release_connection(connection)
@@ -56,17 +56,15 @@ module Neo4j::Driver
56
56
  end
57
57
 
58
58
  def process_procedure_response(procedure, records, error)
59
- cause = Util::Futures.completion_exception_cause(error)
60
-
61
- return RoutingProcedureResponse.new(procedure, records) if cause.nil?
62
-
63
- handle_error(procedure, cause)
59
+ error ? handle_error(procedure, error) : RoutingProcedureResponse.new(procedure, records: records)
64
60
  end
65
61
 
66
62
  def handle_error(procedure, error)
67
- return RoutingProcedureResponse.new(procedure, records) if error.is_a? Exceptions::ClientException
68
-
69
- raise java.util.concurrent.CompletionException, error
63
+ if error.is_a? Exceptions::ClientException
64
+ RoutingProcedureResponse.new(procedure, error: error)
65
+ else
66
+ raise error
67
+ end
70
68
  end
71
69
  end
72
70
  end
@@ -15,20 +15,24 @@ module Neo4j::Driver
15
15
  end
16
16
 
17
17
  def single_async
18
- first_record = next_async
19
- unless first_record
20
- raise Exceptions::NoSuchRecordException, 'Cannot retrieve a single record, because this result is empty.'
21
- end
22
- if next_async
23
- raise Exceptions::NoSuchRecordException,
24
- 'Expected a result with a single record, but this result contains at least one more. Ensure your query returns only one record.'
18
+ next_async.compose do |first_record|
19
+ unless first_record
20
+ raise Exceptions::NoSuchRecordException, 'Cannot retrieve a single record, because this result is empty.'
21
+ end
22
+ next_async.then do |second_record|
23
+ if second_record
24
+ raise Exceptions::NoSuchRecordException,
25
+ 'Expected a result with a single record, but this result contains at least one more. Ensure your query returns only one record.'
26
+ end
27
+ first_record
28
+ end
25
29
  end
26
- first_record
27
30
  end
28
31
 
29
32
  def each(&action)
30
- internal_for_each_async(&action)
31
- consume_async
33
+ result_holder = Util::ResultHolder.new
34
+ internal_for_each_async(result_holder, &action)
35
+ result_holder.then { consume_async }
32
36
  end
33
37
 
34
38
  def to_async(&map_function)
@@ -37,7 +41,7 @@ module Neo4j::Driver
37
41
 
38
42
  def discard_all_failure_async
39
43
  # runError has priority over other errors and is expected to have been reported to user by now
40
- consume_async #.chain { |_fulfilled, _summary, error| @run_error ? nil : error }
44
+ consume_async.chain { |_summary, error| run_error ? nil : error }
41
45
  nil
42
46
  end
43
47
 
@@ -46,18 +50,25 @@ module Neo4j::Driver
46
50
  @pull_all_handler.pull_all_failure_async.then { |error| run_error ? nil : error }
47
51
  end
48
52
 
49
- private def internal_for_each_async
50
- while record = next_async
51
- begin
52
- yield record
53
- rescue
54
- nil
53
+ private def internal_for_each_async(result_holder, &action)
54
+ next_async.chain do |record, error|
55
+ if error
56
+ result_holder.fail(error)
57
+ elsif record
58
+ begin
59
+ yield record
60
+ rescue => action_error
61
+ result_holder.fail(action_error)
62
+ end
63
+ internal_for_each_async(result_holder, &action)
64
+ else
65
+ result_holder.succeed(nil)
55
66
  end
56
67
  end
57
68
  end
58
69
 
59
70
  def map_successful_run_completion_async
60
- run_error || self
71
+ run_error&.then(&Util::ResultHolder.method(:failed)) || Util::ResultHolder.successful(self)
61
72
  end
62
73
 
63
74
  def run_error
@@ -40,7 +40,7 @@ module Neo4j::Driver
40
40
  end
41
41
 
42
42
  private def assert_not_disposed
43
- raise Neo4j::Driver::Internal::Util.new_result_consumed_error if @disposed
43
+ raise Util::ErrorUtil.new_result_consumed_error if @disposed
44
44
  end
45
45
 
46
46
  def disposed?
@@ -48,7 +48,7 @@ module Neo4j::Driver
48
48
  end
49
49
 
50
50
  def map_successful_run_completion_async
51
- @delegate.map_successful_run_completion_async
51
+ @delegate.map_successful_run_completion_async.then { self }
52
52
  end
53
53
  end
54
54
  end
@@ -4,16 +4,16 @@ module Neo4j::Driver
4
4
  class CommitTxResponseHandler
5
5
  include Spi::ResponseHandler
6
6
 
7
- def initialize(completion_listener)
8
- @completion_listener = completion_listener
7
+ def initialize(result_holder)
8
+ @result_holder = result_holder
9
9
  end
10
10
 
11
11
  def on_success(metadata)
12
- @completion_listener.bookmark = metadata[:bookmark]&.then(&InternalBookmark.method(:parse))
12
+ @result_holder.succeed(metadata[:bookmark]&.then(&InternalBookmark.method(:parse)))
13
13
  end
14
14
 
15
15
  def on_failure(error)
16
- raise error
16
+ @result_holder.fail(error)
17
17
  end
18
18
 
19
19
  def on_record(fields)
@@ -4,6 +4,7 @@ module Neo4j::Driver
4
4
  # This is the Pull All response handler that handles pull all messages in Bolt v3 and previous protocol versions.
5
5
  class LegacyPullAllResponseHandler
6
6
  include Spi::ResponseHandler
7
+ include Enumerable
7
8
  RECORD_BUFFER_LOW_WATERMARK = ENV['record_buffer_low_watermark']&.to_i || 300
8
9
  RECORD_BUFFER_HIGH_WATERMARK = ENV['record_buffer_high_watermark']&.to_i || 1000
9
10
 
@@ -67,7 +68,9 @@ module Neo4j::Driver
67
68
  while @records.empty? && !(@ignore_records || @finished)
68
69
  @records.wait
69
70
  end
70
- @records.items.first
71
+ record = @records.items.first
72
+
73
+ Util::ResultHolder.successful(record)
71
74
 
72
75
  # if record.nil?
73
76
  # return Util::Futures.failed_future(extract_failure) unless @failure.nil?
@@ -84,17 +87,25 @@ module Neo4j::Driver
84
87
  end
85
88
 
86
89
  def next_async
87
- dequeue_record if peek_async
90
+ # dequeue_record if peek_async
91
+ peek_async.then { |record| dequeue_record if record }
88
92
  end
89
93
 
90
94
  def consume_async
91
95
  @ignore_records = true
92
96
  @records.items.clear
93
97
 
94
- if pull_all_failure_async.nil?
95
- @summary
98
+ # if pull_all_failure_async.nil?
99
+ # # @summary.then(&Util::ResultHolder.method(:successful))
100
+ # Util::ResultHolder.successful(@summary)
101
+ # else
102
+ # raise pull_all_failure_async
103
+ # end
104
+
105
+ if @failure
106
+ Util::ResultHolder.failed(extract_failure)
96
107
  else
97
- raise Util::Futures.as_completion_exception, pull_all_failure_async
108
+ Util::ResultHolder.successful(@summary)
98
109
  end
99
110
 
100
111
  # pull_all_failure_async do |error|
@@ -106,13 +117,22 @@ module Neo4j::Driver
106
117
  # end
107
118
  end
108
119
 
109
- def list_async(map_function)
110
- pull_all_failure_async.then_apply do |error|
111
- unless error.nil?
112
- raise Util::Futures.as_completion_exception, error
113
- end
120
+ # def list_async(map_function)
121
+ # pull_all_failure_async.then_apply do |error|
122
+ # unless error.nil?
123
+ # raise Util::Futures.as_completion_exception, error
124
+ # end
114
125
 
115
- records_as_list(map_function)
126
+ # records_as_list(map_function)
127
+ # end
128
+ # end
129
+
130
+ def each
131
+ pull_all_failure_async.then do
132
+ unless @finished
133
+ raise Exceptions::IllegalStateException, "Can't get records as list because SUCCESS or FAILURE did not arrive"
134
+ end
135
+ @records.each { |record| yield record }
116
136
  end
117
137
  end
118
138
 
@@ -122,7 +142,8 @@ module Neo4j::Driver
122
142
 
123
143
  def pull_all_failure_async
124
144
  if !@failure.nil?
125
- return java.util.concurrent.CompletableFuture.completed_future(extract_failure)
145
+ return Util::ResultHolder.failed(extract_failure)
146
+ # return java.util.concurrent.CompletableFuture.completed_future(extract_failure)
126
147
  elsif @finished
127
148
  return nil
128
149
  # return Util::Futures.completed_with_null
@@ -191,33 +212,41 @@ module Neo4j::Driver
191
212
  end
192
213
 
193
214
  def complete_record_future(record)
194
- unless @record_future.nil?
195
- future = @record_future
196
- @record_future = nil
197
- future.complete(record)
198
- end
215
+ # unless @record_future.nil?
216
+ # future = @record_future
217
+ # @record_future = nil
218
+ # future.complete(record)
219
+ # end
220
+ @record_future&.succeed(record)
221
+ @record_future = nil
199
222
  end
200
223
 
201
224
  def fail_record_future(error)
202
- unless @record_future.nil?
203
- future = @record_future
204
- @record_future = nil
205
- future.complete_exceptionally(error)
206
- return true
207
- end
225
+ # unless @record_future.nil?
226
+ # future = @record_future
227
+ # @record_future = nil
228
+ # future.complete_exceptionally(error)
229
+ # return true
230
+ # end
208
231
 
209
- false
232
+ # false
233
+ @record_future&.fail(error)
234
+ ensure
235
+ @record_future = nil
210
236
  end
211
237
 
212
238
  def complete_failure_future(error)
213
- unless @failure_future.nil?
214
- future = @failure_future
215
- @failure_future = nil
216
- future.complete(error)
217
- return true
218
- end
239
+ # unless @failure_future.nil?
240
+ # future = @failure_future
241
+ # @failure_future = nil
242
+ # future.complete(error)
243
+ # return true
244
+ # end
219
245
 
220
- false
246
+ # false
247
+ @failure_future&.fail(error)
248
+ ensure
249
+ @failure_future = nil
221
250
  end
222
251
 
223
252
  def extract_result_summary(metadata)
@@ -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,8 @@ 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
103
  request(FetchSizeUtil::UNLIMITED_FETCH_SIZE)
99
-
100
- @summary_future = java.util.concurrent.CompletableFuture.new if @summary_future.nil?
101
-
102
- @summary_future
104
+ @summary_future ||= Util::ResultHolder.new
103
105
  end
104
106
 
105
107
  def enqueue_record(record)
@@ -122,14 +124,6 @@ module Neo4j::Driver
122
124
  record
123
125
  end
124
126
 
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
127
  def extract_failure
134
128
  @failure or raise Exceptions::IllegalStateException, "Can't extract failure because it does not exist"
135
129
  ensure
@@ -137,39 +131,34 @@ module Neo4j::Driver
137
131
  end
138
132
 
139
133
  def complete_record_future(record)
140
- unless @record_future.nil?
141
- future = @record_future
142
- @record_future = nil
143
- future.complete(record)
144
- end
134
+ @record_future&.succeed(record)
135
+ @record_future = nil
145
136
  end
146
137
 
147
138
  def complete_summary_future(summary)
148
- unless @summary_future.nil?
149
- future = @summary_future
150
- @summary_future = nil
151
- future.complete(summary)
152
- end
139
+ @summary_future&.succeed(summary)
140
+ @summary_future = nil
153
141
  end
154
142
 
155
143
  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
144
+ @record_future&.fail(error)
145
+ ensure
146
+ @record_future = nil
147
+ end
162
148
 
163
- false
149
+ def fail_summary_future(error)
150
+ @summary_future&.fail(error)
151
+ ensure
152
+ @summary_future = nil
164
153
  end
165
154
 
166
155
  def completed_with_value_if_no_failure(value)
167
- @failure ? extract_failure : value
156
+ if @failure
157
+ Util::ResultHolder.failed(extract_failure)
158
+ else
159
+ Util::ResultHolder.successful(value)
160
+ end
168
161
  end
169
-
170
- # def request(size)
171
- # @auto_pull_enabled ? Async { super } : super
172
- # end
173
162
  end
174
163
  end
175
164
  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)
@@ -19,19 +19,19 @@ module Neo4j::Driver
19
19
  end
20
20
 
21
21
  def has_next?
22
- @cursor.peek_async
22
+ @cursor.peek_async.result!
23
23
  end
24
24
 
25
25
  def next
26
- @cursor.next_async || raise(Exceptions::NoSuchRecordException.no_more)
26
+ @cursor.next_async.result! || raise(Exceptions::NoSuchRecordException.no_more)
27
27
  end
28
28
 
29
29
  def single
30
- @cursor.single_async
30
+ @cursor.single_async.result!
31
31
  end
32
32
 
33
33
  def peek
34
- @cursor.peek_async or raise Exceptions::NoSuchRecordException.no_peek_past
34
+ @cursor.peek_async.result! or raise Exceptions::NoSuchRecordException.no_peek_past
35
35
  end
36
36
 
37
37
  def each
@@ -39,7 +39,7 @@ module Neo4j::Driver
39
39
  end
40
40
 
41
41
  def consume
42
- @cursor.consume_async
42
+ @cursor.consume_async.result!
43
43
  end
44
44
 
45
45
  def remove
@@ -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,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)
@@ -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
 
@@ -0,0 +1,70 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Util
4
+ class ResultHolder
5
+ def self.successful(result = nil)
6
+ new.tap { |holder| holder.succeed(result) }
7
+ end
8
+
9
+ def self.failed(error)
10
+ new.tap { |holder| holder.fail(error) }
11
+ end
12
+
13
+ def succeed(result = nil)
14
+ if @completed
15
+ false
16
+ else
17
+ @result = result
18
+ true
19
+ end
20
+ ensure
21
+ @completed = true
22
+ end
23
+
24
+ def fail(error)
25
+ if @completed
26
+ false
27
+ else
28
+ @error = error
29
+ true
30
+ end
31
+ ensure
32
+ @completed = true
33
+ end
34
+
35
+ def result!
36
+ raise @error if @error
37
+ @result
38
+ end
39
+
40
+ def then
41
+ @error ? self : ResultHolder.successful(yield(@result))
42
+ end
43
+
44
+ # &block returns a ResultHolder
45
+ def compose
46
+ @error ? self : yield(@result)
47
+ end
48
+
49
+ def chain
50
+ ResultHolder.successful(yield(@result, @error))
51
+ rescue => error
52
+ ResultHolder.failed(error)
53
+ end
54
+
55
+ def side
56
+ yield(@result, @error)
57
+ self
58
+ end
59
+
60
+ def copy_to(result_holder)
61
+ if @error
62
+ result_holder.fail(@error)
63
+ else
64
+ result_holder.succeed(@result)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Neo4j
4
4
  module Driver
5
- VERSION = '4.4.0.alpha.7'
5
+ VERSION = '4.4.0.alpha.8'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-ruby-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0.alpha.7
4
+ version: 4.4.0.alpha.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heinrich Klobuczek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-10 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -467,6 +467,7 @@ files:
467
467
  - ruby/neo4j/driver/internal/util/metadata_extractor.rb
468
468
  - ruby/neo4j/driver/internal/util/mutex.rb
469
469
  - ruby/neo4j/driver/internal/util/preconditions.rb
470
+ - ruby/neo4j/driver/internal/util/result_holder.rb
470
471
  - ruby/neo4j/driver/internal/util/server_version.rb
471
472
  - ruby/neo4j/driver/logging1.rb
472
473
  - ruby/neo4j/driver/net/server_address.rb