@Internal public interface SynchronousTransactionState extends TransactionState
TransactionSynchronizationManager to allow not thread-local state.| 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.
|
boolean isSynchronizationActive()
registerSynchronization(io.micronaut.transaction.support.TransactionSynchronization)void initSynchronization()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if synchronization is already activevoid registerSynchronization(@NonNull
TransactionSynchronization synchronization)
Note that synchronizations can implement the
Ordered interface.
They will be executed in an order according to their order value (if any).
synchronization - the synchronization object to registerjava.lang.IllegalStateException - if transaction synchronization is not activeOrdered@NonNull java.util.List<TransactionSynchronization> getSynchronizations() throws java.lang.IllegalStateException
java.lang.IllegalStateException - if synchronization is not activeTransactionSynchronizationvoid clearSynchronization()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if synchronization is not activevoid setTransactionName(@Nullable
java.lang.String name)
name - the name of the transaction, or null to reset itTransactionDefinition.getName()@Nullable java.lang.String getTransactionName()
null 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.TransactionDefinition.getName()void setTransactionReadOnly(boolean readOnly)
readOnly - true to mark the current transaction
as read-only; false to reset such a read-only markerTransactionDefinition.isReadOnly()boolean isTransactionReadOnly()
Note 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.
TransactionDefinition.isReadOnly(),
TransactionSynchronization.beforeCommit(boolean)void setTransactionIsolationLevel(@Nullable
TransactionDefinition.Isolation isolationLevel)
isolationLevel - 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()@Nullable TransactionDefinition.Isolation getTransactionIsolationLevel()
null 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()void setActualTransactionActive(boolean active)
active - true to mark the current state as being associated
with an actual transaction; false to reset that markerboolean isActualTransactionActive()
To 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).
isSynchronizationActive()void clear()