Reset global rollback-only status when rolling back to savepoint
Issue: SPR-6568
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,19 +31,18 @@ import org.springframework.transaction.TransactionUsageException;
|
||||
import org.springframework.transaction.support.SmartTransactionObject;
|
||||
|
||||
/**
|
||||
* Convenient base class for JDBC-aware transaction objects.
|
||||
* Can contain a {@link ConnectionHolder}, and implements the
|
||||
* {@link org.springframework.transaction.SavepointManager}
|
||||
* interface based on that ConnectionHolder.
|
||||
* Convenient base class for JDBC-aware transaction objects. Can contain a
|
||||
* {@link ConnectionHolder} with a JDBC {@code Connection}, and implements the
|
||||
* {@link SavepointManager} interface based on that {@code ConnectionHolder}.
|
||||
*
|
||||
* <p>Allows for programmatic management of JDBC 3.0
|
||||
* {@link java.sql.Savepoint Savepoints}. Spring's
|
||||
* {@link org.springframework.transaction.support.DefaultTransactionStatus}
|
||||
* will automatically delegate to this, as it autodetects transaction
|
||||
* objects that implement the SavepointManager interface.
|
||||
* <p>Allows for programmatic management of JDBC {@link java.sql.Savepoint Savepoints}.
|
||||
* Spring's {@link org.springframework.transaction.support.DefaultTransactionStatus}
|
||||
* automatically delegates to this, as it autodetects transaction objects which
|
||||
* implement the {@link SavepointManager} interface.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.1
|
||||
* @see DataSourceTransactionManager
|
||||
*/
|
||||
public abstract class JdbcTransactionObjectSupport implements SavepointManager, SmartTransactionObject {
|
||||
|
||||
@@ -107,6 +106,10 @@ public abstract class JdbcTransactionObjectSupport implements SavepointManager,
|
||||
throw new NestedTransactionNotSupportedException(
|
||||
"Cannot create a nested transaction because savepoints are not supported by your JDBC driver");
|
||||
}
|
||||
if (conHolder.isRollbackOnly()) {
|
||||
throw new CannotCreateTransactionException(
|
||||
"Cannot create savepoint for transaction which is already marked as rollback-only");
|
||||
}
|
||||
return conHolder.createSavepoint();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
@@ -123,6 +126,7 @@ public abstract class JdbcTransactionObjectSupport implements SavepointManager,
|
||||
ConnectionHolder conHolder = getConnectionHolderForSavepoint();
|
||||
try {
|
||||
conHolder.getConnection().rollback((Savepoint) savepoint);
|
||||
conHolder.resetRollbackOnly();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new TransactionSystemException("Could not roll back to JDBC savepoint", ex);
|
||||
@@ -151,7 +155,7 @@ public abstract class JdbcTransactionObjectSupport implements SavepointManager,
|
||||
}
|
||||
if (!hasConnectionHolder()) {
|
||||
throw new TransactionUsageException(
|
||||
"Cannot create nested transaction if not exposing a JDBC transaction");
|
||||
"Cannot create nested transaction when not exposing a JDBC transaction");
|
||||
}
|
||||
return getConnectionHolder();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user