HHH-9945 - Allow Transaction to rollback if marked-for-rollback-only
This commit is contained in:
parent
f0f852f14f
commit
ee2099ff8a
|
@ -8,8 +8,6 @@ package org.hibernate.engine.transaction.internal;
|
||||||
|
|
||||||
import javax.transaction.Synchronization;
|
import javax.transaction.Synchronization;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.TransactionException;
|
import org.hibernate.TransactionException;
|
||||||
|
@ -17,6 +15,8 @@ import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.resource.transaction.TransactionCoordinator;
|
import org.hibernate.resource.transaction.TransactionCoordinator;
|
||||||
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import static org.hibernate.resource.transaction.TransactionCoordinator.TransactionDriver;
|
import static org.hibernate.resource.transaction.TransactionCoordinator.TransactionDriver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,8 +71,8 @@ public class TransactionImpl implements Transaction {
|
||||||
@Override
|
@Override
|
||||||
public void rollback() {
|
public void rollback() {
|
||||||
TransactionStatus status = transactionDriverControl.getStatus();
|
TransactionStatus status = transactionDriverControl.getStatus();
|
||||||
if ( status != TransactionStatus.ACTIVE && status != TransactionStatus.FAILED_COMMIT ) {
|
if ( !status.canRollback() ) {
|
||||||
throw new TransactionException( "Transaction not successfully started" );
|
throw new TransactionException( "Cannot rollback transaction in current status [" + status.name() + "]" );
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug( "rolling back" );
|
LOG.debug( "rolling back" );
|
||||||
|
|
|
@ -46,5 +46,26 @@ public enum TransactionStatus {
|
||||||
* Status code indicating a transaction that is in the process of
|
* Status code indicating a transaction that is in the process of
|
||||||
* rolling back.
|
* rolling back.
|
||||||
*/
|
*/
|
||||||
ROLLING_BACK
|
ROLLING_BACK;
|
||||||
|
|
||||||
|
public boolean isOneOf(TransactionStatus... statuses) {
|
||||||
|
for ( TransactionStatus status : statuses ) {
|
||||||
|
if ( this == status ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotOneOf(TransactionStatus... statuses) {
|
||||||
|
return !isOneOf( statuses );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canRollback() {
|
||||||
|
return isOneOf(
|
||||||
|
TransactionStatus.ACTIVE,
|
||||||
|
TransactionStatus.FAILED_COMMIT,
|
||||||
|
TransactionStatus.MARKED_ROLLBACK
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue