mirror of https://github.com/apache/activemq.git
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
This commit is contained in:
parent
229c634a83
commit
ddda4004b4
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue