private final boolean autoCommit(Configuration configuration) { Boolean autoCommit = (Boolean) configuration.data(DATA_DEFAULT_TRANSACTION_PROVIDER_AUTOCOMMIT); if (autoCommit == null) { autoCommit = connection(configuration).getAutoCommit(); configuration.data(DATA_DEFAULT_TRANSACTION_PROVIDER_AUTOCOMMIT, autoCommit); } return autoCommit; }
private final Savepoint setSavepoint(Configuration configuration, boolean topLevel) { if (topLevel || !nested()) return IGNORED_SAVEPOINT; switch (configuration.family()) { case CUBRID: return UNSUPPORTED_SAVEPOINT; default: return connection(configuration).setSavepoint(); } }
@Override public final void rollback(TransactionContext ctx) { Deque<Savepoint> savepoints = savepoints(ctx.configuration()); Savepoint savepoint = null; // [#3537] If something went wrong with the savepoints per se if (!savepoints.isEmpty()) savepoint = savepoints.pop(); try { if (savepoint == null || savepoint == UNSUPPORTED_SAVEPOINT) { connection(ctx.configuration()).rollback(); } // [#3955] ROLLBACK is only effective if an exception reaches the // top-level transaction. else if (savepoint == IGNORED_SAVEPOINT) { if (savepoints.isEmpty()) connection(ctx.configuration()).rollback(); } else { connection(ctx.configuration()).rollback(savepoint); } } finally { if (savepoints.isEmpty()) brace(ctx.configuration(), false); } }
@Override public final void commit(TransactionContext ctx) { Deque<Savepoint> savepoints = savepoints(ctx.configuration()); Savepoint savepoint = savepoints.pop(); // [#3489] Explicitly release savepoints prior to commit if (savepoint != null && savepoint != UNSUPPORTED_SAVEPOINT && savepoint != IGNORED_SAVEPOINT) try { connection(ctx.configuration()).releaseSavepoint(savepoint); } // [#3537] Ignore those cases where the JDBC driver incompletely implements the API // See also http://stackoverflow.com/q/10667292/521799 catch (DataAccessException ignore) {} // This is the top-level transaction if (savepoints.isEmpty()) { connection(ctx.configuration()).commit(); brace(ctx.configuration(), false); } // Nested commits have no effect else { } }
/** * Ensure an <code>autoCommit</code> value on the connection, if it was set * to <code>true</code>, originally. */ private final void brace(Configuration configuration, boolean start) { DefaultConnectionProvider connection = connection(configuration); try { boolean autoCommit = autoCommit(configuration); // Transactions cannot run with autoCommit = true. Change the value for // the duration of a transaction if (autoCommit == true) connection.setAutoCommit(!start); } // [#3718] Chances are that the above JDBC interactions throw additional exceptions // try-finally will ensure that the ConnectionProvider.release() call is made finally { if (!start) { connectionProvider.release(connection.connection); configuration.data().remove(DATA_DEFAULT_TRANSACTION_PROVIDER_CONNECTION); } } }