#806 - Deprecate OnQueryOnly.CLOSE ...

This commit is contained in:
Robin Bygrave
2016-08-04 23:02:26 +12:00
parent 08e46d6bf3
commit e30ad80f5f
4 changed files with 7 additions and 70 deletions
@@ -33,12 +33,6 @@ public class DatabasePlatform {
*/
ROLLBACK,
/**
* Just close the transaction. Valid at READ_COMMITTED isolation and preferred on some Databases
* as a performance optimisation.
*/
CLOSE,
/**
* Commit the transaction
*/
@@ -44,11 +44,7 @@ public class ExplicitTransactionManager extends TransactionManager {
return DatabasePlatform.OnQueryOnly.valueOf(systemPropertyValue.trim().toUpperCase());
}
if (DatabasePlatform.OnQueryOnly.CLOSE.equals(dbPlatformOnQueryOnly)) {
// Not using OnQueryOnly.CLOSE with ExplicitJdbcTransaction
return DatabasePlatform.OnQueryOnly.COMMIT;
}
// default to commit if not defined on the platform
return dbPlatformOnQueryOnly == null ? DatabasePlatform.OnQueryOnly.COMMIT : dbPlatformOnQueryOnly;
// default to rollback if not defined on the platform
return dbPlatformOnQueryOnly == null ? DatabasePlatform.OnQueryOnly.ROLLBACK : dbPlatformOnQueryOnly;
}
}
@@ -860,26 +860,14 @@ public class JdbcTransaction implements SpiTransaction {
}
/**
* Rollback, Commit or Close for query only transaction.
* <p>
* For a transaction that was used for queries only we can choose to either
* rollback or just close the connection for performance.
* </p>
* Rollback or Commit for query only transaction.
*/
protected void connectionEndForQueryOnly() {
try {
switch (onQueryOnly) {
case ROLLBACK:
performRollback();
break;
case COMMIT:
performCommit();
break;
case CLOSE:
// valid at READ COMMITTED Isolation
break;
default:
performRollback();
if (onQueryOnly == OnQueryOnly.COMMIT) {
performCommit();
} else {
performRollback();
}
} catch (SQLException e) {
logger.error("Error when ending a query only transaction via " + onQueryOnly, e);
@@ -192,51 +192,10 @@ public class TransactionManager {
return OnQueryOnly.valueOf(systemPropertyValue.trim().toUpperCase());
}
if (OnQueryOnly.CLOSE.equals(dbPlatformOnQueryOnly)) {
// check for read committed isolation level
if (!isReadCommittedIsolation(ds)) {
logger.warn("Ignoring DatabasePlatform.OnQueryOnly.CLOSE as the transaction Isolation Level is not READ_COMMITTED");
// we will just use ROLLBACK and ignore the desired optimisation
return OnQueryOnly.ROLLBACK;
} else {
// will use the OnQueryOnly.CLOSE optimisation
return OnQueryOnly.CLOSE;
}
}
// default to rollback if not defined on the platform
return dbPlatformOnQueryOnly == null ? OnQueryOnly.ROLLBACK : dbPlatformOnQueryOnly;
}
/**
* Return true if the isolation level is read committed.
*/
protected boolean isReadCommittedIsolation(DataSource ds) {
if (DbOffline.isSet()) {
return true;
}
Connection c = null;
try {
c = ds.getConnection();
int isolationLevel = c.getTransactionIsolation();
return (isolationLevel == Connection.TRANSACTION_READ_COMMITTED);
} catch (SQLException ex) {
String m = "Errored trying to determine the default Isolation Level";
throw new PersistenceException(m, ex);
} finally {
try {
if (c != null) {
c.close();
}
} catch (SQLException ex) {
logger.error("closing connection", ex);
}
}
}
public String getServerName() {
return serverName;
}