[#3718] Exceptions on rollback hide the original exceptions causing the rollback

This commit is contained in:
Lukas Eder 2014-10-30 11:45:34 +01:00
parent ed2b7aabee
commit afa2dec2cd
2 changed files with 31 additions and 12 deletions

View File

@ -205,6 +205,7 @@ import org.jooq.exception.DataAccessException;
import org.jooq.exception.InvalidResultException;
import org.jooq.exception.SQLDialectNotSupportedException;
import org.jooq.impl.BatchCRUD.Action;
import org.jooq.tools.JooqLogger;
import org.jooq.tools.csv.CSVReader;
/**
@ -222,8 +223,10 @@ public class DefaultDSLContext implements DSLContext, Serializable {
/**
* Generated UID
*/
private static final long serialVersionUID = 2681360188806309513L;
private final Configuration configuration;
private static final long serialVersionUID = 2681360188806309513L;
private static final JooqLogger log = JooqLogger.getLogger(DefaultDSLContext.class);
private final Configuration configuration;
// -------------------------------------------------------------------------
// XXX Constructors
@ -332,7 +335,17 @@ public class DefaultDSLContext implements DSLContext, Serializable {
provider.commit(ctx);
}
catch (Exception cause) {
provider.rollback(ctx.cause(cause));
try {
provider.rollback(ctx.cause(cause));
}
catch (Exception suppress) {
try {
cause.addSuppressed(suppress);
}
catch (NoSuchMethodError logJDBC_4_0) {
log.error("Error when rolling back", suppress);
}
}
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;

View File

@ -177,19 +177,25 @@ public class DefaultTransactionProvider implements TransactionProvider {
connection = provider.acquire();
}
boolean autoCommit = autoCommit(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(configuration).setAutoCommit(!start);
// Transactions cannot run with autoCommit = true. Change the value for
// the duration of a transaction
if (autoCommit == true) {
connection(configuration).setAutoCommit(!start);
}
}
if (!start) {
provider.release(connection);
// [#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) {
provider.release(connection);
connection = null;
configuration.data().remove(DATA_DEFAULT_TRANSACTION_PROVIDER_CONNECTION);
connection = null;
configuration.data().remove(DATA_DEFAULT_TRANSACTION_PROVIDER_CONNECTION);
}
}
}
}