Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

graben
Copy link
Contributor

@graben graben commented Apr 11, 2025

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.

Copy link
Contributor

🌟 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:

  • First-time contributors require MANUAL approval for the GitHub Actions to run

  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot.

  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.

  • Build and test logs are available in the Summary page. Only Apache Camel committers have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@@ -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) {
Copy link
Contributor

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?

Copy link
Contributor

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) ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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() ?

Copy link
Contributor

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 ...");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants