From ddda4004b4b06dd5ae3770d0ad464cbcf29a4232 Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Sun, 7 Oct 2012 11:56:07 +0000 Subject: [PATCH] AMQ-1492: Allow to configure whether changing auto commit is allowed on JDBC persistence adapter. Some JDBC drivers dont allow changing that. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1395278 13f79535-47bb-0310-9956-ffa450edef68 --- .../store/jdbc/JDBCPersistenceAdapter.java | 15 +++++++++++++++ .../activemq/store/jdbc/TransactionContext.java | 9 ++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java index 476573dba9..401118bae5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java @@ -95,6 +95,7 @@ public class JDBCPersistenceAdapter extends DataSourceServiceSupport implements private DataSource lockDataSource; private int transactionIsolation; private File directory; + private boolean changeAutoCommitAllowed = true; protected int maxProducersToAudit=1024; protected int maxAuditDepth=1000; @@ -520,6 +521,20 @@ public class JDBCPersistenceAdapter extends DataSourceServiceSupport implements this.cleanupPeriod = cleanupPeriod; } + public boolean isChangeAutoCommitAllowed() { + return changeAutoCommitAllowed; + } + + /** + * Whether the JDBC driver allows to set the auto commit. + * Some drivers does not allow changing the auto commit. The default value is true. + * + * @param changeAutoCommitAllowed true to change, false to not change. + */ + public void setChangeAutoCommitAllowed(boolean changeAutoCommitAllowed) { + this.changeAutoCommitAllowed = changeAutoCommitAllowed; + } + public void deleteAllMessages() throws IOException { TransactionContext c = getTransactionContext(); try { diff --git a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java index b8fbdf24d9..507437a8cc 100755 --- a/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java @@ -56,9 +56,12 @@ public class TransactionContext { if (connection == null) { try { connection = dataSource.getConnection(); - boolean autoCommit = !inTx; - if (connection.getAutoCommit() != autoCommit) { - connection.setAutoCommit(autoCommit); + if (persistenceAdapter.isChangeAutoCommitAllowed()) { + boolean autoCommit = !inTx; + if (connection.getAutoCommit() != autoCommit) { + LOG.trace("Setting auto commit to {} on connection {}", autoCommit, connection); + connection.setAutoCommit(autoCommit); + } } } catch (SQLException e) { JDBCPersistenceAdapter.log("Could not get JDBC connection: ", e);