@Internal public final class DefaultSynchronousTransactionState extends java.lang.Object implements SynchronousTransactionState
SynchronousTransactionState.| Constructor and Description |
|---|
DefaultSynchronousTransactionState() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear the entire transaction synchronization state:
registered synchronizations as well as the various transaction characteristics.
|
void |
clearSynchronization()
Deactivate transaction synchronization for the current state.
|
java.util.List<TransactionSynchronization> |
getSynchronizations()
Return an unmodifiable snapshot list of all registered synchronizations
for the current state.
|
TransactionDefinition.Isolation |
getTransactionIsolationLevel()
Return the isolation level for the current transaction, if any.
|
java.lang.String |
getTransactionName()
Return the name of the current transaction, or
null if none set. |
void |
initSynchronization()
Activate transaction synchronization for the current state.
|
boolean |
isActualTransactionActive()
Return whether there currently is an actual transaction active.
|
boolean |
isSynchronizationActive()
Return if transaction synchronization is active for the current state.
|
boolean |
isTransactionReadOnly()
Return whether the current transaction is marked as read-only.
|
void |
registerSynchronization(TransactionSynchronization synchronization)
Register a new transaction synchronization for the current state.
|
void |
setActualTransactionActive(boolean active)
Expose whether there currently is an actual transaction active.
|
void |
setTransactionIsolationLevel(TransactionDefinition.Isolation isolationLevel)
Expose an isolation level for the current transaction.
|
void |
setTransactionName(java.lang.String name)
Expose the name of the current transaction, if any.
|
void |
setTransactionReadOnly(boolean readOnly)
Expose a read-only flag for the current transaction.
|
public boolean isSynchronizationActive()
SynchronousTransactionStateisSynchronizationActive in interface SynchronousTransactionStateSynchronousTransactionState.registerSynchronization(io.micronaut.transaction.support.TransactionSynchronization)public void initSynchronization()
throws java.lang.IllegalStateException
SynchronousTransactionStateinitSynchronization in interface SynchronousTransactionStatejava.lang.IllegalStateException - if synchronization is already activepublic void registerSynchronization(TransactionSynchronization synchronization)
SynchronousTransactionStateNote that synchronizations can implement the
Ordered interface.
They will be executed in an order according to their order value (if any).
registerSynchronization in interface SynchronousTransactionStatesynchronization - the synchronization object to registerOrderedpublic java.util.List<TransactionSynchronization> getSynchronizations() throws java.lang.IllegalStateException
SynchronousTransactionStategetSynchronizations in interface SynchronousTransactionStatejava.lang.IllegalStateException - if synchronization is not activeTransactionSynchronizationpublic void clearSynchronization()
throws java.lang.IllegalStateException
SynchronousTransactionStateclearSynchronization in interface SynchronousTransactionStatejava.lang.IllegalStateException - if synchronization is not activepublic void setTransactionName(java.lang.String name)
SynchronousTransactionStatesetTransactionName in interface SynchronousTransactionStatename - the name of the transaction, or null to reset itTransactionDefinition.getName()public java.lang.String getTransactionName()
SynchronousTransactionStatenull if none set.
To be called by resource management code for optimizations per use case,
for example to optimize fetch strategies for specific named transactions.getTransactionName in interface SynchronousTransactionStateTransactionDefinition.getName()public void setTransactionReadOnly(boolean readOnly)
SynchronousTransactionStatesetTransactionReadOnly in interface SynchronousTransactionStatereadOnly - true to mark the current transaction
as read-only; false to reset such a read-only markerTransactionDefinition.isReadOnly()public boolean isTransactionReadOnly()
SynchronousTransactionStateNote that transaction synchronizations receive the read-only flag
as argument for the beforeCommit callback, to be able
to suppress change detection on commit. The present method is meant
to be used for earlier read-only checks, for example to set the
flush mode of a Hibernate Session to "FlushMode.NEVER" upfront.
isTransactionReadOnly in interface SynchronousTransactionStateTransactionDefinition.isReadOnly(),
TransactionSynchronization.beforeCommit(boolean)public void setTransactionIsolationLevel(TransactionDefinition.Isolation isolationLevel)
SynchronousTransactionStatesetTransactionIsolationLevel in interface SynchronousTransactionStateisolationLevel - the isolation level to expose, according to the
JDBC Connection constants (equivalent to the corresponding
TransactionDefinition constants), or null to reset itConnection.TRANSACTION_READ_UNCOMMITTED,
Connection.TRANSACTION_READ_COMMITTED,
Connection.TRANSACTION_REPEATABLE_READ,
Connection.TRANSACTION_SERIALIZABLE,
TransactionDefinition.Isolation.READ_UNCOMMITTED,
TransactionDefinition.Isolation.READ_COMMITTED,
TransactionDefinition.Isolation.REPEATABLE_READ,
TransactionDefinition.Isolation.SERIALIZABLE,
TransactionDefinition.getIsolationLevel()public TransactionDefinition.Isolation getTransactionIsolationLevel()
SynchronousTransactionStategetTransactionIsolationLevel in interface SynchronousTransactionStatenull if noneConnection.TRANSACTION_READ_UNCOMMITTED,
Connection.TRANSACTION_READ_COMMITTED,
Connection.TRANSACTION_REPEATABLE_READ,
Connection.TRANSACTION_SERIALIZABLE,
TransactionDefinition.Isolation.READ_UNCOMMITTED,
TransactionDefinition.Isolation.READ_COMMITTED,
TransactionDefinition.Isolation.REPEATABLE_READ,
TransactionDefinition.Isolation.SERIALIZABLE,
TransactionDefinition.getIsolationLevel()public void setActualTransactionActive(boolean active)
SynchronousTransactionStatesetActualTransactionActive in interface SynchronousTransactionStateactive - true to mark the current state as being associated
with an actual transaction; false to reset that markerpublic boolean isActualTransactionActive()
SynchronousTransactionStateTo be called by resource management code that wants to discriminate between active transaction synchronization (with or without backing resource transaction; also on PROPAGATION_SUPPORTS) and an actual transaction being active (with backing resource transaction; on PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, etc).
isActualTransactionActive in interface SynchronousTransactionStateSynchronousTransactionState.isSynchronizationActive()public void clear()
SynchronousTransactionStateclear in interface SynchronousTransactionStateSynchronousTransactionState.clearSynchronization(),
SynchronousTransactionState.setTransactionName(java.lang.String),
SynchronousTransactionState.setTransactionReadOnly(boolean),
SynchronousTransactionState.setTransactionIsolationLevel(io.micronaut.transaction.TransactionDefinition.Isolation),
SynchronousTransactionState.setActualTransactionActive(boolean)