activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1395278 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc: JDBCPersistenceAdapter.java TransactionContext.java
Date Sun, 07 Oct 2012 11:56:08 GMT
Author: davsclaus
Date: Sun Oct  7 11:56:07 2012
New Revision: 1395278

URL: http://svn.apache.org/viewvc?rev=1395278&view=rev
Log:
AMQ-1492: Allow to configure whether changing auto commit is allowed on JDBC persistence adapter.
Some JDBC drivers dont allow changing that.

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java?rev=1395278&r1=1395277&r2=1395278&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/JDBCPersistenceAdapter.java
Sun Oct  7 11:56:07 2012
@@ -95,6 +95,7 @@ public class JDBCPersistenceAdapter exte
     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 exte
         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 {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java?rev=1395278&r1=1395277&r2=1395278&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/TransactionContext.java
Sun Oct  7 11:56:07 2012
@@ -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);



Mime
View raw message