Class AbstractInternalTransaction<C>
- Type Parameters:
C
- The connection type
- All Implemented Interfaces:
InternalTransaction<C>
,SavepointManager
,TransactionExecution
,TransactionStatus<C>
,Flushable
- Direct Known Subclasses:
DefaultTransactionStatus
- Since:
- 4.0.0
- Author:
- Denis Stepanov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Create a new savepoint.void
flush()
Flush the underlying session to the datastore, if applicable: for example, all affected Hibernate/JPA sessions.boolean
Return whether this transaction internally carries a savepoint, that is, has been created as nested transaction based on a savepoint.boolean
Return whether this transaction is completed, that is, whether it has already been committed or rolled back.boolean
Template method for determining the global rollback-only flag of the underlying transaction, if any.boolean
Determine the rollback-only flag via checking this TransactionStatus.boolean
Return whether the transaction has been marked as rollback-only (either by the application or by the transaction infrastructure).void
registerSynchronization
(@NonNull TransactionSynchronization synchronization) Register a new transaction synchronization for the current state.void
void
releaseSavepoint
(Object savepoint) Explicitly release the given savepoint.void
rollbackToSavepoint
(Object savepoint) Roll back to the given savepoint.protected void
Set global rollback only.void
Set the transaction rollback-only.void
void
void
void
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.impl.InternalTransaction
resume, suspend
Methods inherited from interface io.micronaut.transaction.TransactionExecution
getTransactionDefinition, isNewTransaction
Methods inherited from interface io.micronaut.transaction.TransactionStatus
getConnection, getConnectionStatus, getTransaction
-
Constructor Details
-
AbstractInternalTransaction
public AbstractInternalTransaction()
-
-
Method Details
-
setGlobalRollbackOnly
protected void setGlobalRollbackOnly()Set global rollback only. -
setRollbackOnly
public void setRollbackOnly()Description copied from interface:TransactionExecution
Set 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:
setRollbackOnly
in interfaceTransactionExecution
-
isRollbackOnly
public boolean isRollbackOnly()Description copied from interface:TransactionExecution
Return whether the transaction has been marked as rollback-only (either by the application or by the transaction infrastructure).- Specified by:
isRollbackOnly
in interfaceTransactionExecution
- Returns:
- Whether the execution has been marked to rollback
-
isLocalRollbackOnly
public boolean isLocalRollbackOnly()Description copied from interface:InternalTransaction
Determine the rollback-only flag via checking this TransactionStatus.Will only return "true" if the application called
setRollbackOnly
on this TransactionStatus object.- Specified by:
isLocalRollbackOnly
in interfaceInternalTransaction<C>
- Returns:
- Whether is local rollback
-
isGlobalRollbackOnly
public boolean isGlobalRollbackOnly()Description copied from interface:InternalTransaction
Template method for determining the global rollback-only flag of the underlying transaction, if any.This implementation always returns
false
.- Specified by:
isGlobalRollbackOnly
in interfaceInternalTransaction<C>
- Returns:
- Whether is global rollback
-
isCompleted
public boolean isCompleted()Description copied from interface:TransactionExecution
Return whether this transaction is completed, that is, whether it has already been committed or rolled back.- Specified by:
isCompleted
in interfaceTransactionExecution
- Returns:
- Whether the execution has completed
-
hasSavepoint
public boolean hasSavepoint()Description copied from interface:TransactionStatus
Return 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:
hasSavepoint
in interfaceTransactionStatus<C>
- Returns:
- Whether a save point is present
- See Also:
-
releaseHeldSavepoint
- Specified by:
releaseHeldSavepoint
in interfaceInternalTransaction<C>
- Throws:
TransactionException
-
createSavepoint
Description copied from interface:SavepointManager
Create a new savepoint. You can roll back to a specific savepoint viarollbackToSavepoint
, and explicitly release a savepoint that you don't need anymore viareleaseSavepoint
.Note that most transaction managers will automatically release savepoints at transaction completion.
- Specified by:
createSavepoint
in 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:
-
rollbackToSavepoint
Description copied from interface:SavepointManager
Roll back to the given savepoint.The savepoint will not be automatically released afterwards. You may explicitly call
SavepointManager.releaseSavepoint(Object)
or rely on automatic release on transaction completion.- Specified by:
rollbackToSavepoint
in 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:
-
releaseSavepoint
Description copied from interface:SavepointManager
Explicitly release the given savepoint.Note that most transaction managers will automatically release savepoints on transaction completion.
Implementations should fail as silently as possible if proper resource cleanup will eventually happen at transaction completion.
- Specified by:
releaseSavepoint
in interfaceSavepointManager
- Parameters:
savepoint
- the savepoint to release- Throws:
NestedTransactionNotSupportedException
- if the underlying transaction does not support savepointsTransactionException
- if the release failed- See Also:
-
triggerBeforeCommit
public void triggerBeforeCommit()- Specified by:
triggerBeforeCommit
in interfaceInternalTransaction<C>
-
triggerAfterCommit
public void triggerAfterCommit()- Specified by:
triggerAfterCommit
in interfaceInternalTransaction<C>
-
triggerBeforeCompletion
public void triggerBeforeCompletion()- Specified by:
triggerBeforeCompletion
in interfaceInternalTransaction<C>
-
triggerAfterCompletion
- Specified by:
triggerAfterCompletion
in interfaceInternalTransaction<C>
-
cleanupAfterCompletion
public void cleanupAfterCompletion()- Specified by:
cleanupAfterCompletion
in interfaceInternalTransaction<C>
-
flush
public void flush()Description copied from interface:TransactionStatus
Flush the underlying session to the datastore, if applicable: for example, all affected Hibernate/JPA sessions.This is effectively just a hint and may be a no-op if the underlying transaction manager does not have a flush concept. A flush signal may get applied to the primary resource or to transaction synchronizations, depending on the underlying resource.
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfaceTransactionStatus<C>
-
registerSynchronization
Description copied from interface:TransactionStatus
Register a new transaction synchronization for the current state.Note that synchronizations can implement the
Ordered
interface. They will be executed in an order according to their order value (if any).- Specified by:
registerSynchronization
in interfaceTransactionStatus<C>
- Parameters:
synchronization
- the synchronization object to register
-