This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 039d316d8fb CAMEL-21845: camel-sql - Only commit/rollback if auto
commit has been true (#17734)
039d316d8fb is described below
commit 039d316d8fb67a99bd681b644f577022e0d32f2e
Author: Benjamin Graf <[email protected]>
AuthorDate: Fri Apr 18 20:15:44 2025 +0200
CAMEL-21845: camel-sql - Only commit/rollback if auto commit has been true
(#17734)
---
.../src/main/java/org/apache/camel/component/sql/SqlProducer.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
index 3a771c290a4..53c21d34285 100644
---
a/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
+++
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
@@ -159,7 +159,7 @@ public class SqlProducer extends DefaultProducer {
boolean restoreAutoCommit = true;
if (batch) {
- if (manualCommit) {
+ if (!exchange.isTransacted() && manualCommit) {
// optimize batch by turning off auto-commit
restoreAutoCommit =
ps.getConnection().getAutoCommit();
ps.getConnection().setAutoCommit(false);
@@ -171,18 +171,18 @@ public class SqlProducer extends DefaultProducer {
total += count;
}
exchange.getIn().setHeader(SqlConstants.SQL_UPDATE_COUNT, total);
- if (manualCommit) {
+ if (!exchange.isTransacted() && manualCommit) {
// optimize batch by commit after done
ps.getConnection().commit();
}
} catch (Exception e) {
- if (manualCommit) {
+ if (!exchange.isTransacted() && manualCommit) {
// we failed so rollback
ps.getConnection().rollback();
}
throw e;
} finally {
- if (manualCommit && restoreAutoCommit) {
+ if (!exchange.isTransacted() && manualCommit &&
restoreAutoCommit) {
// restore auto commit on connection as it may
be used
// in another kind of query (connection
pooling)
ps.getConnection().setAutoCommit(true);