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
Support custom callback handlers #2448
Support custom callback handlers #2448
Conversation
65b67c9
to
3ec4299
Compare
* @throws X any exception thrown by the callback. | ||
* @see Jdbi#withHandle(HandleCallback) | ||
*/ | ||
<R, X extends Exception> R withHandle(Handle handle, |
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.
Adding the ability to decorate withHandle
seems fine.
One thought: as this is right now, the Handler
will remain in the stack trace, even if it does nothing.
An alternate implementation would be HandleCallback<R, X> decorate(HandleCallback<R, X> callback)
. Then, the default implementation would just return callback;
and the stack frame would not show up in debuggers or profilers when it does nothing.
What do you think? I am fine with this approach too if you don't like the suggestion. cc @hgschmie
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.
Yeah, that's better. I've pushed that change.
e241960
to
0af874c
Compare
Introduce new interface that is an analog of `TransactionHandler` but for all callbacks, not just transactions. This interface, `Handler` is used to invoke the callback passed to JDBI's `useHandle`, `withHandle`, `inTransaction` and `withTransaction`. This gives users a chance to global patch callbacks for all JDBI uses not just transactions.
0af874c
to
3e04d37
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Thank you!!! |
We'd appreciate a release when you can. Thank you in advance. |
@Randgalt , released in 3.40.0 |
Currently, it is very simple to add global custom handling for
transaction callbacks using JDBI's
TransactionHandler
.Specialized behavior can be added for an app's entire JDBI usage
without project devs needing to do anything special. This is very
useful when introducing protocols such as custom retry behavior,
custom connection management, etc.
Introduce new interface that is an analog of
TransactionHandler
but for all callbacks, not just transactions. This interface,
Handler
is used to invoke the callback passed to JDBI'suseHandle
,withHandle
,inTransaction
andwithTransaction
.This gives users a chance to global patch callbacks for all
JDBI uses not just transactions.