#392 - Fix for AutoCommit mode ... fixing change from #204 ... such that AutoCommitJdbcTransaction works as expected

This commit is contained in:
Robin Bygrave
2015-08-20 22:38:53 +12:00
parent 84190f3c2a
commit 2caeb4fff1
4 changed files with 81 additions and 26 deletions
@@ -14,6 +14,11 @@ public class AutoCommitJdbcTransaction extends JdbcTransaction {
super(id, explicit, connection, manager);
}
@Override
protected void checkAutoCommit(Connection connection) throws SQLException {
// do nothing as autoCommit
}
@Override
protected void performRollback() throws SQLException {
// do nothing as autoCommit
@@ -157,18 +157,26 @@ public class JdbcTransaction implements SpiTransaction {
this.batchOnCascadeMode = manager == null ? PersistBatch.NONE : manager.getPersistBatchOnCascade();
this.onQueryOnly = manager == null ? OnQueryOnly.ROLLBACK : manager.getOnQueryOnly();
this.persistenceContext = new DefaultPersistenceContext();
if (connection != null) {
this.autoCommit = connection.getAutoCommit();
if (this.autoCommit) {
connection.setAutoCommit(false);
}
}
checkAutoCommit(connection);
} catch (Exception e) {
throw new PersistenceException(e);
}
}
/**
* Overridden in AutoCommitJdbcTransaction as that expects to run/operate with autocommit true.
*/
protected void checkAutoCommit(Connection connection) throws SQLException {
if (connection != null) {
this.autoCommit = connection.getAutoCommit();
if (this.autoCommit) {
connection.setAutoCommit(false);
}
}
}
private static String deriveLogPrefix(String id) {
StringBuilder sb = new StringBuilder();