HHH-10807 - Added isActive to Transaction and moved logic to TransactionDriver.

This commit is contained in:
Chris Cranford 2016-06-11 18:57:34 -05:00
parent a8bcedecbf
commit e7933ababb
4 changed files with 31 additions and 1 deletions

View File

@ -38,6 +38,16 @@ public interface Transaction extends EntityTransaction {
*/ */
TransactionStatus getStatus(); TransactionStatus getStatus();
/**
* Indicate whether a resource transaction is in progress.
*
* @param isMarkedRollbackConsideredActive whether to consider {@link TransactionStatus#MARKED_ROLLBACK} as active.
*
* @return boolean indicating whether transaction is in progress
* @throws HibernateException if an unexpected error condition is encountered.
*/
boolean isActive(boolean isMarkedRollbackConsideredActive);
/** /**
* Register a user synchronization callback for this transaction. * Register a user synchronization callback for this transaction.
* *

View File

@ -103,7 +103,16 @@ public class TransactionImpl implements TransactionImplementor {
@Override @Override
public boolean isActive() { public boolean isActive() {
return getStatus() == TransactionStatus.ACTIVE || getStatus() == TransactionStatus.MARKED_ROLLBACK; // old behavior considered TransactionStatus#MARKED_ROLLBACK as active
return isActive( true );
}
@Override
public boolean isActive(boolean isMarkedForRollbackConsideredActive) {
if ( transactionDriverControl == null ) {
transactionDriverControl = transactionCoordinator.getTransactionDriverControl();
}
return transactionDriverControl.isActive( isMarkedForRollbackConsideredActive );
} }
@Override @Override

View File

@ -121,6 +121,12 @@ public interface TransactionCoordinator {
void markRollbackOnly(); void markRollbackOnly();
default boolean isActive(boolean isMarkedRollbackConsideredActive) {
final TransactionStatus status = getStatus();
return TransactionStatus.ACTIVE == status
|| ( isMarkedRollbackConsideredActive && TransactionStatus.MARKED_ROLLBACK == status );
}
// todo : org.hibernate.Transaction will need access to register local Synchronizations. // todo : org.hibernate.Transaction will need access to register local Synchronizations.
// depending on how we integrate TransactionCoordinator/TransactionDriverControl with // depending on how we integrate TransactionCoordinator/TransactionDriverControl with
// org.hibernate.Transaction that might be best done by: // org.hibernate.Transaction that might be best done by:

View File

@ -191,6 +191,11 @@ public class BatchModeTransactionCoordinator implements TransactionCoordinator {
return false; return false;
} }
@Override
public boolean isActive(boolean isMarkedRollbackConsideredActive) {
return false;
}
@Override @Override
public TransactionStatus getStatus() { public TransactionStatus getStatus() {
return transactionDriver.getStatus(); return transactionDriver.getStatus();