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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/neo4j/driver/exceptions/protocol_exception.rb +2 -2
  3. data/lib/neo4j/driver/internal/bolt_server_address.rb +6 -6
  4. data/lib/neo4j/driver/types/time.rb +4 -2
  5. data/ruby/neo4j/driver/config.rb +1 -1
  6. data/ruby/neo4j/driver/graph_database.rb +2 -2
  7. data/ruby/neo4j/driver/internal/async/inbound/inbound_message_dispatcher.rb +2 -3
  8. data/ruby/neo4j/driver/internal/async/network_session.rb +4 -3
  9. data/ruby/neo4j/driver/internal/async/pool/{netty_channel_tracker.rb → channel_tracker.rb} +6 -8
  10. data/ruby/neo4j/driver/internal/async/pool/connection_pool_impl.rb +3 -3
  11. data/ruby/neo4j/driver/internal/async/unmanaged_transaction.rb +18 -20
  12. data/ruby/neo4j/driver/internal/cluster/cluster_composition.rb +10 -20
  13. data/ruby/neo4j/driver/internal/cluster/cluster_composition_lookup_result.rb +2 -2
  14. data/ruby/neo4j/driver/internal/cluster/cluster_routing_table.rb +38 -55
  15. data/ruby/neo4j/driver/internal/cluster/identity_resolver.rb +1 -4
  16. data/ruby/neo4j/driver/internal/cluster/loadbalancing/least_connected_load_balancing_strategy.rb +6 -6
  17. data/ruby/neo4j/driver/internal/cluster/loadbalancing/load_balancer.rb +44 -80
  18. data/ruby/neo4j/driver/internal/cluster/multi_databases_routing_procedure_runner.rb +6 -9
  19. data/ruby/neo4j/driver/internal/cluster/rediscovery_impl.rb +65 -155
  20. data/ruby/neo4j/driver/internal/cluster/route_message_routing_procedure_runner.rb +2 -2
  21. data/ruby/neo4j/driver/internal/cluster/routing_procedure_cluster_composition_provider.rb +8 -12
  22. data/ruby/neo4j/driver/internal/cluster/routing_procedure_response.rb +19 -3
  23. data/ruby/neo4j/driver/internal/cluster/routing_table_handler_impl.rb +46 -67
  24. data/ruby/neo4j/driver/internal/cluster/routing_table_registry_impl.rb +42 -61
  25. data/ruby/neo4j/driver/internal/cluster/single_database_routing_procedure_runner.rb +15 -19
  26. data/ruby/neo4j/driver/internal/cursor/async_result_cursor_impl.rb +31 -19
  27. data/ruby/neo4j/driver/internal/cursor/disposable_async_result_cursor.rb +12 -15
  28. data/ruby/neo4j/driver/internal/database_name_util.rb +3 -3
  29. data/ruby/neo4j/driver/internal/default_bookmark_holder.rb +1 -7
  30. data/ruby/neo4j/driver/internal/direct_connection_provider.rb +1 -1
  31. data/ruby/neo4j/driver/internal/driver_factory.rb +4 -4
  32. data/ruby/neo4j/driver/internal/handlers/commit_tx_response_handler.rb +4 -4
  33. data/ruby/neo4j/driver/internal/handlers/legacy_pull_all_response_handler.rb +90 -51
  34. data/ruby/neo4j/driver/internal/handlers/pulln/auto_pull_response_handler.rb +33 -44
  35. data/ruby/neo4j/driver/internal/handlers/rollback_tx_response_handler.rb +7 -1
  36. data/ruby/neo4j/driver/internal/impersonation_util.rb +2 -2
  37. data/ruby/neo4j/driver/internal/internal_bookmark.rb +1 -1
  38. data/ruby/neo4j/driver/internal/internal_database_name.rb +3 -5
  39. data/ruby/neo4j/driver/internal/internal_result.rb +5 -5
  40. data/ruby/neo4j/driver/internal/internal_session.rb +1 -1
  41. data/ruby/neo4j/driver/internal/internal_transaction.rb +4 -4
  42. data/ruby/neo4j/driver/internal/messaging/bolt_protocol_version.rb +3 -1
  43. data/ruby/neo4j/driver/internal/messaging/encode/route_message_encoder.rb +8 -2
  44. data/ruby/neo4j/driver/internal/messaging/encode/route_v44_message_encoder.rb +8 -13
  45. data/ruby/neo4j/driver/internal/messaging/request/abstract_streaming_message.rb +4 -1
  46. data/ruby/neo4j/driver/internal/messaging/request/begin_message.rb +2 -3
  47. data/ruby/neo4j/driver/internal/messaging/request/multi_database_util.rb +2 -2
  48. data/ruby/neo4j/driver/internal/messaging/request/route_message.rb +5 -10
  49. data/ruby/neo4j/driver/internal/messaging/request/run_with_metadata_message.rb +5 -3
  50. data/ruby/neo4j/driver/internal/messaging/request/transaction_metadata_builder.rb +2 -2
  51. data/ruby/neo4j/driver/internal/messaging/v3/bolt_protocol_v3.rb +8 -4
  52. data/ruby/neo4j/driver/internal/messaging/v44/message_writer_v44.rb +1 -1
  53. data/ruby/neo4j/driver/internal/read_only_bookmark_holder.rb +13 -0
  54. data/ruby/neo4j/driver/internal/resolved_bolt_server_address.rb +35 -0
  55. data/ruby/neo4j/driver/internal/security/security_plan_impl.rb +14 -9
  56. data/ruby/neo4j/driver/internal/util/error_util.rb +1 -1
  57. data/ruby/neo4j/driver/internal/util/result_holder.rb +70 -0
  58. data/ruby/neo4j/driver/net/{server_address1.rb → server_address.rb} +2 -2
  59. data/ruby/neo4j/driver/query.rb +1 -1
  60. data/ruby/neo4j/driver/transaction_config.rb +5 -1
  61. data/ruby/neo4j/driver/values.rb +3 -3
  62. data/ruby/neo4j/driver/version.rb +1 -1
  63. metadata +16 -14
  64. data/ruby/neo4j/driver/internal/database_name.rb +0 -12
@@ -4,7 +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
- UNINITIALIZED_RECORDS = []
7
+ include Enumerable
8
8
  RECORD_BUFFER_LOW_WATERMARK = ENV['record_buffer_low_watermark']&.to_i || 300
9
9
  RECORD_BUFFER_HIGH_WATERMARK = ENV['record_buffer_high_watermark']&.to_i || 1000
10
10
 
@@ -14,7 +14,7 @@ module Neo4j::Driver
14
14
  @metadata_extractor = Internal::Validator.require_non_nil!(metadata_extractor)
15
15
  @connection = Internal::Validator.require_non_nil!(connection)
16
16
  @completion_listener = Internal::Validator.require_non_nil!(completion_listener)
17
- @records = UNINITIALIZED_RECORDS
17
+ @records = ::Async::Queue.new
18
18
  end
19
19
 
20
20
  def can_manage_auto_read?
@@ -39,7 +39,7 @@ module Neo4j::Driver
39
39
 
40
40
  failed_record_future = fail_record_future(error)
41
41
 
42
- if fail_record_future
42
+ if failed_record_future
43
43
  # error propagated through the record future
44
44
  complete_failure_future(nil)
45
45
  else
@@ -54,7 +54,7 @@ module Neo4j::Driver
54
54
  if @ignore_records
55
55
  complete_record_future(nil)
56
56
  else
57
- record = InternalRecord.new(run_response_handler.query_keys, fields)
57
+ record = InternalRecord.new(@run_response_handler.query_keys, fields)
58
58
  enqueue_record(record)
59
59
  complete_record_future(record)
60
60
  end
@@ -65,45 +65,74 @@ module Neo4j::Driver
65
65
  end
66
66
 
67
67
  def peek_async
68
- record = @records.first
68
+ while @records.empty? && !(@ignore_records || @finished)
69
+ @records.wait
70
+ end
71
+ record = @records.items.first
69
72
 
70
- if record.nil?
71
- return Util::Futures.failed_future(extract_failure) unless @failure.nil?
73
+ Util::ResultHolder.successful(record)
72
74
 
73
- return Util::Futures.completed_with_null if @ignore_records || @finished
75
+ # if record.nil?
76
+ # return Util::Futures.failed_future(extract_failure) unless @failure.nil?
74
77
 
75
- @record_future = java.util.concurrent.CompletableFuture.new if @record_future.nil?
78
+ # return Util::Futures.completed_with_null if @ignore_records || @finished
76
79
 
77
- @record_future
78
- else
79
- java.util.concurrent.CompletableFuture.completed_future(record)
80
- end
80
+ # @record_future = java.util.concurrent.CompletableFuture.new if @record_future.nil?
81
+
82
+ # @record_future
83
+ # else
84
+ # # java.util.concurrent.CompletableFuture.completed_future(record)
85
+ # record
86
+ # end
81
87
  end
82
88
 
83
89
  def next_async
84
- peek_async.then_apply(-> (_ignore) { dequeue_record })
90
+ # dequeue_record if peek_async
91
+ peek_async.then { |record| dequeue_record if record }
85
92
  end
86
93
 
87
94
  def consume_async
88
95
  @ignore_records = true
89
- @records.clear
96
+ @records.items.clear
90
97
 
91
- pull_all_failure_async.then_apply do |error|
92
- unless error.nil?
93
- raise Util::Futures.as_completion_exception, error
94
- end
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
95
104
 
96
- @summary
105
+ if @failure
106
+ Util::ResultHolder.failed(extract_failure)
107
+ else
108
+ Util::ResultHolder.successful(@summary)
97
109
  end
110
+
111
+ # pull_all_failure_async do |error|
112
+ # unless error.nil?
113
+ # raise Util::Futures.as_completion_exception, error
114
+ # end
115
+
116
+ # @summary
117
+ # end
98
118
  end
99
119
 
100
- def list_async(map_function)
101
- pull_all_failure_async.then_apply do |error|
102
- unless error.nil?
103
- raise Util::Futures.as_completion_exception, error
104
- 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
105
125
 
106
- 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 }
107
136
  end
108
137
  end
109
138
 
@@ -113,9 +142,11 @@ module Neo4j::Driver
113
142
 
114
143
  def pull_all_failure_async
115
144
  if !@failure.nil?
116
- 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)
117
147
  elsif @finished
118
- return Util::Futures.completed_with_null
148
+ return nil
149
+ # return Util::Futures.completed_with_null
119
150
  else
120
151
  if @failure_future.nil?
121
152
  # neither SUCCESS nor FAILURE message has arrived, register future to be notified when it arrives
@@ -139,7 +170,7 @@ module Neo4j::Driver
139
170
  # when failure is requested we have to buffer all remaining records and then return the error
140
171
  # do not disable auto-read in this case, otherwise records will not be consumed and trailing
141
172
  # SUCCESS or FAILURE message will not arrive as well, so callers will get stuck waiting for the error
142
- if !should_buffer_all_records && records.size > RECORD_BUFFER_HIGH_WATERMARK
173
+ if !should_buffer_all_records && @records.size > RECORD_BUFFER_HIGH_WATERMARK
143
174
  # more than high watermark records are already queued, tell connection to stop auto-reading from network
144
175
  # this is needed to deal with slow consumers, we do not want to buffer all records in memory if they are
145
176
  # fetched from network faster than consumed
@@ -148,7 +179,7 @@ module Neo4j::Driver
148
179
  end
149
180
 
150
181
  def dequeue_record
151
- record = @records.drop(1)
182
+ record = @records.dequeue
152
183
 
153
184
  if @records.size < RECORD_BUFFER_LOW_WATERMARK
154
185
  # less than low watermark records are now available in the buffer, tell connection to pre-fetch more
@@ -170,7 +201,7 @@ module Neo4j::Driver
170
201
  result << map_function.apply(record)
171
202
  end
172
203
 
173
- @records.clear
204
+ @records.items.clear
174
205
  result
175
206
  end
176
207
 
@@ -181,33 +212,41 @@ module Neo4j::Driver
181
212
  end
182
213
 
183
214
  def complete_record_future(record)
184
- unless @record_future.nil?
185
- future = @record_future
186
- @record_future = nil
187
- future.complete(record)
188
- 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
189
222
  end
190
223
 
191
224
  def fail_record_future(error)
192
- unless @record_future.nil?
193
- future = @record_future
225
+ # unless @record_future.nil?
226
+ # future = @record_future
227
+ # @record_future = nil
228
+ # future.complete_exceptionally(error)
229
+ # return true
230
+ # end
231
+
232
+ # false
233
+ @record_future&.fail(error)
234
+ ensure
194
235
  @record_future = nil
195
- future.complete_exceptionally(error)
196
- return true
197
- end
198
-
199
- false
200
236
  end
201
237
 
202
238
  def complete_failure_future(error)
203
- unless @failure_future.nil?
204
- future = @failure_future
205
- @failure_future = nil
206
- future.complete(error)
207
- return true
208
- end
209
-
210
- false
239
+ # unless @failure_future.nil?
240
+ # future = @failure_future
241
+ # @failure_future = nil
242
+ # future.complete(error)
243
+ # return true
244
+ # end
245
+
246
+ # false
247
+ @failure_future&.fail(error)
248
+ ensure
249
+ @failure_future = nil
211
250
  end
212
251
 
213
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)
@@ -14,8 +14,8 @@ module Neo4j::Driver
14
14
  private
15
15
 
16
16
  def self.supports_impersonation?(connection)
17
- connection.server_version.greater_than_or_equal(Util::ServerVersion::V4_4_0) &&
18
- connection.protocol.version.compare_to( Messaging::V44::BoltProtocolV44::VERSION ) >= 0
17
+ connection.server_version >= Util::ServerVersion::V4_4_0 &&
18
+ connection.protocol.version >= Messaging::V44::BoltProtocolV44::VERSION
19
19
  end
20
20
  end
21
21
  end
@@ -2,13 +2,13 @@ module Neo4j::Driver
2
2
  module Internal
3
3
  class InternalBookmark
4
4
  include Bookmark
5
- EMPTY = new
6
5
  attr :values
7
6
  delegate :hash, :empty?, to: :values
8
7
 
9
8
  private def initialize(*values)
10
9
  @values = values.to_set
11
10
  end
11
+ EMPTY = new.freeze
12
12
 
13
13
  def ==(other)
14
14
  equal?(other) || self.class == other.class && values == other.values
@@ -1,10 +1,8 @@
1
1
  module Neo4j::Driver
2
2
  module Internal
3
- class InternalDatabaseName < Struct.new(:database_name)
4
- alias description database_name
5
-
6
- def initialize(database_name)
7
- super(Validator.require_non_nil!(database_name))
3
+ class InternalDatabaseName < Struct.new(:database_name, :description)
4
+ def initialize(database_name: nil, description: database_name)
5
+ super(database_name, description)
8
6
  end
9
7
  end
10
8
  end
@@ -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
@@ -2,10 +2,12 @@ module Neo4j::Driver
2
2
  module Internal
3
3
  module Messaging
4
4
  class BoltProtocolVersion < Struct.new(:major_version, :minor_version)
5
+ include Comparable
6
+
5
7
  def self.from_raw_bytes(raw_version)
6
8
  major = raw_version & 0x000000FF
7
9
  minor = (raw_version >> 8) & 0x000000FF
8
- new(major,minor)
10
+ new(major, minor)
9
11
  end
10
12
 
11
13
  def to_int
@@ -8,8 +8,14 @@ module Neo4j::Driver
8
8
  Util::Preconditions.check_argument(message, Request::RouteMessage)
9
9
  packer.pack_struct_header(3, message.signature)
10
10
  packer.pack(message.routing_context)
11
- packer.pack(message.bookmark.present? ? Values.value(message.bookmark.values) : Values.value(java.util.Collections.empty_list))
12
- packer.pack(message.database_name)
11
+ packer.pack(message.bookmark&.values || [])
12
+ packer.pack(option(message))
13
+ end
14
+
15
+ private
16
+
17
+ def option(message)
18
+ message.database_name
13
19
  end
14
20
  end
15
21
  end
@@ -3,22 +3,17 @@ module Neo4j::Driver
3
3
  module Messaging
4
4
  module Encode
5
5
  # Encodes the ROUTE message to the stream
6
- class RouteV44MessageEncoder
7
- def encode(message, packer)
8
- Util::Preconditions.check_argument(message, Request::RouteMessage)
9
- packer.pack_struct_header(3, message.signature)
10
- packer.pack(message.routing_context)
11
- packer.pack(message.bookmark.present? ? Values.value(message.bookmark.values) : Values.value(java.util.Collections.empty_list))
6
+ class RouteV44MessageEncoder < RouteMessageEncoder
7
+ private
12
8
 
13
- if !message.impersonated_user.nil? && message.database_name.nil?
14
- params = java.util.Collections.singleton_map("imp_user", Values.value(message.impersonated_user))
15
- elsif !message.database_name.nil?
16
- params = java.util.Collections.singleton_map("db", Values.value(message.database_name))
9
+ def option(message)
10
+ if message.impersonated_user && !message.database_name
11
+ { imp_user: message.impersonated_user }
12
+ elsif message.database_name
13
+ { db: message.database_name }
17
14
  else
18
- params = java.util.Collections.empty_map
15
+ {}
19
16
  end
20
-
21
- packer.pack(params)
22
17
  end
23
18
  end
24
19
  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}"
@@ -7,9 +7,8 @@ module Neo4j::Driver
7
7
 
8
8
  def initialize(bookmark, config, database_name, mode, impersonated_user)
9
9
  super(Request::TransactionMetadataBuilder.build_metadata(
10
- tx_timeout: config[:timeout]&.then(&DurationNormalizer.method(:milliseconds)),
11
- tx_metadata: config[:metadata], database_name: database_name, mode: mode, bookmark: bookmark,
12
- impersonated_user: impersonated_user))
10
+ timeout: config[:timeout], tx_metadata: config[:metadata], database_name: database_name, mode: mode,
11
+ bookmark: bookmark, impersonated_user: impersonated_user))
13
12
  end
14
13
 
15
14
  def signature
@@ -10,12 +10,12 @@ module Neo4j::Driver
10
10
  end
11
11
  end
12
12
 
13
- def supports_multi_database(connection)
13
+ def supports_multi_database?(connection)
14
14
  connection.server_version >= Util::ServerVersion::V4_0_0 &&
15
15
  connection.protocol.version >= V4::BoltProtocolV4::VERSION
16
16
  end
17
17
 
18
- def supports_route_message(connection)
18
+ def supports_route_message?(connection)
19
19
  connection.protocol.version >= V43::BoltProtocolV43::VERSION
20
20
  end
21
21
  end
@@ -6,19 +6,14 @@ module Neo4j::Driver
6
6
  # instance can provide the wanted service.
7
7
  # <p>
8
8
  # This message is used to fetch this routing information.
9
+ #
10
+ # @param routingContext The routing context used to define the routing table. Multi-datacenter deployments is one of its use cases.
11
+ # @param bookmark The bookmark used when getting the routing table.
12
+ # @param databaseName The name of the database to get the routing table for.
13
+ # @param impersonatedUser The name of the impersonated user to get the routing table for, should be {@code null} for non-impersonated requests
9
14
  class RouteMessage < Struct.new(:routing_context, :bookmark, :database_name, :impersonated_user)
10
15
  SIGNATURE = 0x66
11
16
 
12
- # Constructor
13
-
14
- # @param routingContext The routing context used to define the routing table. Multi-datacenter deployments is one of its use cases.
15
- # @param bookmark The bookmark used when getting the routing table.
16
- # @param databaseName The name of the database to get the routing table for.
17
- # @param impersonatedUser The name of the impersonated user to get the routing table for, should be {@code null} for non-impersonated requests
18
- def initialize(routing_context, bookmark, database_name, impersonated_user)
19
- super(routing_context.freeze, bookmark, database_name, impersonated_user)
20
- end
21
-
22
17
  def signature
23
18
  SIGNATURE
24
19
  end
@@ -9,7 +9,7 @@ module Neo4j::Driver
9
9
  class << self
10
10
  def auto_commit_tx_run_message(query, config, database_name, mode, bookmark, impersonated_user)
11
11
  metadata = Request::TransactionMetadataBuilder.build_metadata(
12
- tx_timeout: config[:timeout], tx_metadata: config[:metadata], database_name: database_name, mode: mode,
12
+ timeout: config[:timeout], tx_metadata: config[:metadata], database_name: database_name, mode: mode,
13
13
  bookmark: bookmark, impersonated_user: impersonated_user)
14
14
  new(query.text, query.parameters, metadata)
15
15
  end
@@ -29,10 +29,12 @@ module Neo4j::Driver
29
29
  SIGNATURE
30
30
  end
31
31
 
32
- def eql?(other)
33
- super && query.eql?(other.query) && parameters.eql?(other.parameters)
32
+ def ==(other)
33
+ super && query == other.query && parameters == other.parameters
34
34
  end
35
35
 
36
+ alias eql? ==
37
+
36
38
  def hash
37
39
  [query, parameters, metadata].hash
38
40
  end