Class AbstractTransactionStatus<T>
- java.lang.Object
-
- io.micronaut.transaction.support.AbstractTransactionStatus<T>
-
- Type Parameters:
T- The connection type
- All Implemented Interfaces:
SavepointManager,TransactionExecution,TransactionStatus<T>,java.io.Flushable
- Direct Known Subclasses:
DefaultTransactionStatus
public abstract class AbstractTransactionStatus<T> extends java.lang.Object implements TransactionStatus<T>
Abstract base implementation of theTransactionStatusinterface.Pre-implements the handling of local rollback-only and completed flags, and delegation to an underlying
SavepointManager. Also offers the option of a holding a savepoint within the transaction.Does not assume any specific internal transaction handling, such as an underlying transaction object, and no transaction synchronization mechanism.
- Since:
- 1.2.3
- Author:
- Juergen Hoeller
- See Also:
setRollbackOnly(),isRollbackOnly(),setCompleted(),isCompleted(),getSavepointManager(),DefaultTransactionStatus
-
-
Constructor Summary
Constructors Constructor Description AbstractTransactionStatus()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateAndHoldSavepoint()Create a savepoint and hold it for the transaction.java.lang.ObjectcreateSavepoint()This implementation delegates to a SavepointManager for the underlying transaction, if possible.voidflush()This implementations is empty, considering flush as a no-op.protected java.lang.ObjectgetSavepoint()protected SavepointManagergetSavepointManager()Return a SavepointManager for the underlying transaction, if possible.booleanhasSavepoint()Return whether this transaction internally carries a savepoint, that is, has been created as nested transaction based on a savepoint.booleanisCompleted()Return whether this transaction is completed, that is, whether it has already been committed or rolled back.booleanisGlobalRollbackOnly()Template method for determining the global rollback-only flag of the underlying transaction, if any.booleanisLocalRollbackOnly()Determine the rollback-only flag via checking this TransactionStatus.booleanisRollbackOnly()Determine the rollback-only flag via checking both the local rollback-only flag of this TransactionStatus and the global rollback-only flag of the underlying transaction, if any.voidreleaseHeldSavepoint()Release the savepoint that is held for the transaction.voidreleaseSavepoint(java.lang.Object savepoint)This implementation delegates to a SavepointManager for the underlying transaction, if possible.voidrollbackToHeldSavepoint()Roll back to the savepoint that is held for the transaction and release the savepoint right afterwards.voidrollbackToSavepoint(java.lang.Object savepoint)This implementation delegates to a SavepointManager for the underlying transaction, if possible.voidsetCompleted()Mark this transaction as completed, that is, committed or rolled back.voidsetRollbackOnly()Set the transaction rollback-only.protected voidsetSavepoint(java.lang.Object savepoint)Set a savepoint for this transaction.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.transaction.TransactionExecution
isNewTransaction
-
Methods inherited from interface io.micronaut.transaction.TransactionStatus
getConnection, getTransaction
-
-
-
-
Method Detail
-
setRollbackOnly
public void setRollbackOnly()
Description copied from interface:TransactionExecutionSet the transaction rollback-only. This instructs the transaction manager that the only possible outcome of the transaction may be a rollback, as alternative to throwing an exception which would in turn trigger a rollback.- Specified by:
setRollbackOnlyin interfaceTransactionExecution
-
isRollbackOnly
public boolean isRollbackOnly()
Determine the rollback-only flag via checking both the local rollback-only flag of this TransactionStatus and the global rollback-only flag of the underlying transaction, if any.- Specified by:
isRollbackOnlyin interfaceTransactionExecution- Returns:
- Whether the execution has been marked to rollback
- See Also:
isLocalRollbackOnly(),isGlobalRollbackOnly()
-
isLocalRollbackOnly
public boolean isLocalRollbackOnly()
Determine the rollback-only flag via checking this TransactionStatus.Will only return "true" if the application called
setRollbackOnlyon this TransactionStatus object.- Returns:
- Whether is local rollback
-
isGlobalRollbackOnly
public boolean isGlobalRollbackOnly()
Template method for determining the global rollback-only flag of the underlying transaction, if any.This implementation always returns
false.- Returns:
- Whether is global rollback
-
setCompleted
public void setCompleted()
Mark this transaction as completed, that is, committed or rolled back.
-
isCompleted
public boolean isCompleted()
Description copied from interface:TransactionExecutionReturn whether this transaction is completed, that is, whether it has already been committed or rolled back.- Specified by:
isCompletedin interfaceTransactionExecution- Returns:
- Whether the execution has completed
-
hasSavepoint
public boolean hasSavepoint()
Description copied from interface:TransactionStatusReturn whether this transaction internally carries a savepoint, that is, has been created as nested transaction based on a savepoint.This method is mainly here for diagnostic purposes, alongside
TransactionExecution.isNewTransaction(). For programmatic handling of custom savepoints, use the operations provided bySavepointManager.- Specified by:
hasSavepointin interfaceTransactionStatus<T>- Returns:
- Whether a save point is present
- See Also:
TransactionExecution.isNewTransaction(),SavepointManager.createSavepoint(),SavepointManager.rollbackToSavepoint(Object),SavepointManager.releaseSavepoint(Object)
-
setSavepoint
protected void setSavepoint(@Nullable java.lang.Object savepoint)Set a savepoint for this transaction. Useful for PROPAGATION_NESTED.- Parameters:
savepoint- The save point- See Also:
TransactionDefinition.Propagation.NESTED
-
getSavepoint
@Nullable protected java.lang.Object getSavepoint()
- Returns:
- Get the savepoint for this transaction, if any.
-
createAndHoldSavepoint
public void createAndHoldSavepoint() throws TransactionExceptionCreate a savepoint and hold it for the transaction.- Throws:
NestedTransactionNotSupportedException- if the underlying transaction does not support savepointsTransactionException- if an error occurs creating the save point
-
rollbackToHeldSavepoint
public void rollbackToHeldSavepoint() throws TransactionExceptionRoll back to the savepoint that is held for the transaction and release the savepoint right afterwards.- Throws:
TransactionException- if an error occurs rolling back to savepoint
-
releaseHeldSavepoint
public void releaseHeldSavepoint() throws TransactionExceptionRelease the savepoint that is held for the transaction.- Throws:
TransactionException- if an error occurs releasing the save point
-
createSavepoint
public java.lang.Object createSavepoint() throws TransactionExceptionThis implementation delegates to a SavepointManager for the underlying transaction, if possible.- Specified by:
createSavepointin interfaceSavepointManager- Returns:
- a savepoint object, to be passed into
SavepointManager.rollbackToSavepoint(java.lang.Object)orSavepointManager.releaseSavepoint(java.lang.Object) - Throws:
NestedTransactionNotSupportedException- if the underlying transaction does not support savepointsTransactionException- if the savepoint could not be created, for example because the transaction is not in an appropriate state- See Also:
getSavepointManager(),SavepointManager.createSavepoint()
-
rollbackToSavepoint
public void rollbackToSavepoint(java.lang.Object savepoint) throws TransactionExceptionThis implementation delegates to a SavepointManager for the underlying transaction, if possible.- Specified by:
rollbackToSavepointin interfaceSavepointManager- Parameters:
savepoint- the savepoint to roll back to- Throws:
NestedTransactionNotSupportedException- if the underlying transaction does not support savepointsTransactionException- if the rollback failed- See Also:
getSavepointManager(),SavepointManager.rollbackToSavepoint(Object)
-
releaseSavepoint
public void releaseSavepoint(java.lang.Object savepoint) throws TransactionExceptionThis implementation delegates to a SavepointManager for the underlying transaction, if possible.- Specified by:
releaseSavepointin interfaceSavepointManager- Parameters:
savepoint- the savepoint to release- Throws:
NestedTransactionNotSupportedException- if the underlying transaction does not support savepointsTransactionException- if the release failed- See Also:
getSavepointManager(),SavepointManager.releaseSavepoint(Object)
-
getSavepointManager
@NonNull protected SavepointManager getSavepointManager()
Return a SavepointManager for the underlying transaction, if possible.Default implementation always throws a NestedTransactionNotSupportedException.
- Returns:
- The save point manager
- Throws:
NestedTransactionNotSupportedException- if the underlying transaction does not support savepoints
-
flush
public void flush()
This implementations is empty, considering flush as a no-op.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin interfaceTransactionStatus<T>
-
-