You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2009/10/23 17:51:49 UTC

svn commit: r829105 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc: JDBCPersistenceAdapter.java TransactionContext.java

Author: gtully
Date: Fri Oct 23 15:51:45 2009
New Revision: 829105

URL: http://svn.apache.org/viewvc?rev=829105&view=rev
Log:
resolve https://issues.apache.org/activemq/browse/AMQ-2463 - new isolationlevel int property on JDBCPersistenceAdapter

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=829105&r1=829104&r2=829105&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 Fri Oct 23 15:51:45 2009
@@ -84,6 +84,7 @@
     private DatabaseLocker databaseLocker;
     private boolean createTablesOnStartup = true;
     private DataSource lockDataSource;
+    private int transactionIsolation;
 
     public JDBCPersistenceAdapter() {
     }
@@ -390,7 +391,7 @@
         } else {
             TransactionContext answer = (TransactionContext)context.getLongTermStoreContext();
             if (answer == null) {
-                answer = new TransactionContext(getDataSource());
+                answer = getTransactionContext();
                 context.setLongTermStoreContext(answer);
             }
             return answer;
@@ -398,7 +399,11 @@
     }
 
     public TransactionContext getTransactionContext() throws IOException {
-        return new TransactionContext(getDataSource());
+        TransactionContext answer = new TransactionContext(getDataSource());
+        if (transactionIsolation > 0) {
+            answer.setTransactionIsolation(transactionIsolation);
+        }
+        return answer;
     }
 
     public void beginTransaction(ConnectionContext context) throws IOException {
@@ -565,11 +570,22 @@
         return lockAcquireSleepInterval;
     }
 
-    /*
+    /**
      * millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker
      * not applied if DataBaseLocker is injected.
      */
     public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) {
         this.lockAcquireSleepInterval = lockAcquireSleepInterval;
     }
+    
+    /**
+     * set the Transaction isolation level to something other that TRANSACTION_READ_UNCOMMITTED
+     * This allowable dirty isolation level may not be achievable in clustered DB environments
+     * so a more restrictive and expensive option may be needed like TRANSACTION_REPEATABE_READ
+     * see isolation level constants in {@link java.sql.Connection}
+     * @param transactionIsolation the isolation level to use
+     */
+    public void setTransactionIsolation(int transactionIsolation) {
+        this.transactionIsolation = transactionIsolation;
+    }
 }

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=829105&r1=829104&r2=829105&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 Fri Oct 23 15:51:45 2009
@@ -43,7 +43,9 @@
     private PreparedStatement addMessageStatement;
     private PreparedStatement removedMessageStatement;
     private PreparedStatement updateLastAckStatement;
-
+    // a cheap dirty level that we can live with    
+    private int transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED;
+    
     public TransactionContext(DataSource dataSource) {
         this.dataSource = dataSource;
     }
@@ -62,7 +64,7 @@
             }
 
             try {
-                connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+                connection.setTransactionIsolation(transactionIsolation);
             } catch (Throwable e) {
             }
         }
@@ -223,5 +225,9 @@
     public void setRemovedMessageStatement(PreparedStatement removedMessageStatement) {
         this.removedMessageStatement = removedMessageStatement;
     }
+    
+    public void setTransactionIsolation(int transactionIsolation) {
+        this.transactionIsolation = transactionIsolation;
+    }
 
 }