-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Expose transaction timeout and metadata in the API #518
Conversation
dbc0e4c
to
910aff1
Compare
ed68e6c
to
7e0c16a
Compare
7e0c16a
to
86d9d36
Compare
This is the first draft of the API to allow transaction timeout and/or metadata be set for explicit and auto-commit transactions. Both settings can be specified in a `TransactionConfig` object which can be created like this: ``` TransactionConfig config = TransactionConfig.builder() .withTimeout(Duration.ofSeconds(5)) .withMetadata(Collections.singletonMap("key", "value")) .build(); ``` Explicit transactions can take config like this: ``` Transaction tx = session.beginTransaction(config); ``` and auto-commit transactions accept it in various overloads of `Session#run()` and `Session#runAsync()`: ``` session.run("CREATE ()", config); session.runAsync("RETURN $x", Collections.singletonMap("x", 1) config); ``` Transaction functions accept config like this: ``` session.readTransaction(tx -> {...}, config); session.writeTransactionAsync(tx -> {...}, config); ``` There also exists a possibility to specify default transaction configuration per driver. It can be configured in the driver's config: ``` Config driverConfig = Config.build() .withDefaultTransactionConfig(txConfig) .toConfig(); ``` More tests and javadocs will be added in subsequent commits.
It might be a nice thing to have but we are not yet sure about it. Should be easy to add later, if required.
c6282a1
to
b355c4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. Nice java doc
{ | ||
if ( config != null && !config.isEmpty() ) | ||
{ | ||
return txConfigNotSupported(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is amazing! Finally, we do not need to check with server version anymore!
*/ | ||
public class TransactionConfig | ||
{ | ||
private static final TransactionConfig EMPTY = builder().build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we now have this builder style, shall we also give Driver config a builder style?
So we deprecate the old method and then provides a new builder API. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to just change it in the next major release, tbh
otherTx.run( "MATCH (n:Node) SET n.prop = 1" ).consume(); | ||
|
||
TransactionConfig config = TransactionConfig.builder() | ||
.withTimeout( ofSeconds( 1 ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need 1s? Can we give it 1ms to speed up this test? This 1s might slow down my fancy new compute to run tests. (The minimal legal value server accept is 1ms)
Similar for the async one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to keep your computer cool
This is the first draft of the API to allow transaction timeout and/or metadata be set for explicit and auto-commit transactions. Both settings can be specified in a
TransactionConfig
object which can be created like this:Explicit transactions can take config like this:
and auto-commit transactions accept it in various overloads of
Session#run()
andSession#runAsync()
:Transaction functions accept config like this: