-
Notifications
You must be signed in to change notification settings - Fork 5k
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
CAMEL-21845: camel-sql - Only commit/rollback if auto commit has been true #17734
base: main
Are you sure you want to change the base?
Conversation
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🤖 CI automation will test this PR automatically. 🐫 Apache Camel Committers, please review the following items:
|
@@ -171,12 +171,12 @@ public Object doInPreparedStatement(PreparedStatement ps) throws SQLException { | |||
total += count; | |||
} | |||
exchange.getIn().setHeader(SqlConstants.SQL_UPDATE_COUNT, total); | |||
if (manualCommit) { | |||
if (manualCommit && !restoreAutoCommit) { |
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 wonder if there is any better way to check if we are running in a JTA transaction?
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.
IIRC
Commit or rollback should only be called if auto commit has not been set to false before.
So it should check with if (manualCommit && restoreAutoCommit)
?
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.
Ups, seems your right. I'll change it.
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 wonder if there is any better way to check if we are running in a JTA transaction?
You're right that there are better ways to identify JTA, but it's only one option why a connection has been set to auto commit before calling sql producer.
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.
@davsclaus can we use exchange.IsTransacted()
?
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 think it should be true
if sql
is using in a transacted()
like
from("direct:foo")
.transacted()
.to("sql:INSERT INTO ...");
Add-on to the optimization from CAMEL-21845. Commit or rollback should only be called if auto commit has not been set to false before. This might be intended to control the transaction for whatever reason! In cases of XA transactions, for example, calling commit or rollback would cause exceptions.