Skip to content

Session execute_read/write implementation #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions jruby/neo4j/driver/ext/internal_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ module InternalSession
# work around jruby issue https://github.com/jruby/jruby/issues/5603
Struct.new('Wrapper', :object)

%i[read write].each do |prefix|
define_method("#{prefix}_transaction") do |**config, &block|
check do
super(->(tx) { Struct::Wrapper.new(reverse_check { block.call(tx) }) }, to_java_config(Neo4j::Driver::TransactionConfig, **config)).object
# implementation of read_transaction, write_transaction, execute_read, execute_write
%i[read write].each do |mode|
["#{mode}_transaction", "execute_#{mode}"].each do |method_name|
define_method(method_name) do |**config, &block|
if method_name.include? 'transaction'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of backwards and sort of duplication.
I think in this case it would be better to have 2 separate method definitions. One with deprecation and another without.

Neo4j::Driver::Internal::Deprecator.log_warning(method_name, "execute_#{mode}".to_sym, '6.0')
end

check do
super(
->(tx) { Struct::Wrapper.new(reverse_check { block.call(tx) }) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if Struct::Wrapper is still required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, will check

to_java_config(Neo4j::Driver::TransactionConfig, **config)
).object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's increase our max line length to 160. That's what we have on all our projects.

end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract this to a separate private method. So the above logic can be simplified.

end
end
end
Expand Down
12 changes: 12 additions & 0 deletions lib/neo4j/driver/internal/deprecator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Neo4j
module Driver
module Internal
module Deprecator
def self.log_warning(old_method, new_method, version)
@deprecator ||= ActiveSupport::Deprecation.new(version, 'neo4j-ruby-driver')
@deprecator.deprecation_warning(old_method, new_method)
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/integration/bookmark_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe 'Bookmark' do
def create_node_in_tx(session)
session.write_transaction { |tx| tx.run('CREATE (a:Person)') }
session.execute_write { |tx| tx.run('CREATE (a:Person)') }
end

def preamble(session)
Expand Down Expand Up @@ -93,7 +93,7 @@ def expect_single_value(bookmark, value)
it 'fails on invalid bookmark using tx func' do
bookmark = Neo4j::Driver::Bookmark.from('hi, this is an invalid bookmark')
driver.session(bookmarks: bookmark) do |session|
expect { session.read_transaction { |tx| tx.run('RETURN 1').single } }
expect { session.execute_read { |tx| tx.run('RETURN 1').single } }
.to raise_error Neo4j::Driver::Exceptions::ClientException do |e|
expect(e.code).to eq 'Neo.ClientError.Transaction.InvalidBookmark'
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/causal_clustering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def new_session(mode)
create_driver(leader.routing_uri, routing_table_purge_delay: 3.minutes) do |driver|
database = 'neo4j'
driver.session(database: database) do |session|
session.read_transaction { |tx| tx.run('RETURN 1').consume }
session.execute_read { |tx| tx.run('RETURN 1').consume }
end
expect(driver.session_factory.connection_provider.routing_table_registry
.routing_table_handler(database).routing_table.routers.to_a.size).to eq 3
Expand All @@ -181,7 +181,7 @@ def new_session(mode)
leader.bolt_address,
] }) do |driver|
driver.session do |session|
expect(session.read_transaction { |tx| tx.run('RETURN 1').single.first }).to eq 1
expect(session.execute_read { |tx| tx.run('RETURN 1').single.first }).to eq 1
end
end
end
Expand Down
Loading
Loading