mirror of https://github.com/apache/activemq.git
resolve https://issues.apache.org/activemq/browse/AMQ-2463 - new isolationlevel int property on JDBCPersistenceAdapter
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@829105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e384fb99ba
commit
00e2f511c3
|
@ -84,6 +84,7 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
|
||||||
private DatabaseLocker databaseLocker;
|
private DatabaseLocker databaseLocker;
|
||||||
private boolean createTablesOnStartup = true;
|
private boolean createTablesOnStartup = true;
|
||||||
private DataSource lockDataSource;
|
private DataSource lockDataSource;
|
||||||
|
private int transactionIsolation;
|
||||||
|
|
||||||
public JDBCPersistenceAdapter() {
|
public JDBCPersistenceAdapter() {
|
||||||
}
|
}
|
||||||
|
@ -390,7 +391,7 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
|
||||||
} else {
|
} else {
|
||||||
TransactionContext answer = (TransactionContext)context.getLongTermStoreContext();
|
TransactionContext answer = (TransactionContext)context.getLongTermStoreContext();
|
||||||
if (answer == null) {
|
if (answer == null) {
|
||||||
answer = new TransactionContext(getDataSource());
|
answer = getTransactionContext();
|
||||||
context.setLongTermStoreContext(answer);
|
context.setLongTermStoreContext(answer);
|
||||||
}
|
}
|
||||||
return answer;
|
return answer;
|
||||||
|
@ -398,7 +399,11 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransactionContext getTransactionContext() throws IOException {
|
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 {
|
public void beginTransaction(ConnectionContext context) throws IOException {
|
||||||
|
@ -565,11 +570,22 @@ public class JDBCPersistenceAdapter extends DataSourceSupport implements Persist
|
||||||
return lockAcquireSleepInterval;
|
return lockAcquireSleepInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker
|
* millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker
|
||||||
* not applied if DataBaseLocker is injected.
|
* not applied if DataBaseLocker is injected.
|
||||||
*/
|
*/
|
||||||
public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) {
|
public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) {
|
||||||
this.lockAcquireSleepInterval = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ public class TransactionContext {
|
||||||
private PreparedStatement addMessageStatement;
|
private PreparedStatement addMessageStatement;
|
||||||
private PreparedStatement removedMessageStatement;
|
private PreparedStatement removedMessageStatement;
|
||||||
private PreparedStatement updateLastAckStatement;
|
private PreparedStatement updateLastAckStatement;
|
||||||
|
// a cheap dirty level that we can live with
|
||||||
|
private int transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED;
|
||||||
|
|
||||||
public TransactionContext(DataSource dataSource) {
|
public TransactionContext(DataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
|
@ -62,7 +64,7 @@ public class TransactionContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
|
connection.setTransactionIsolation(transactionIsolation);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,4 +226,8 @@ public class TransactionContext {
|
||||||
this.removedMessageStatement = removedMessageStatement;
|
this.removedMessageStatement = removedMessageStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTransactionIsolation(int transactionIsolation) {
|
||||||
|
this.transactionIsolation = transactionIsolation;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue