Class DefaultSynchronousTransactionState
- java.lang.Object
-
- io.micronaut.transaction.support.DefaultSynchronousTransactionState
-
- All Implemented Interfaces:
SynchronousTransactionState,TransactionState
@Internal public final class DefaultSynchronousTransactionState extends java.lang.Object implements SynchronousTransactionState
Default implementation ofSynchronousTransactionState.- Since:
- 3.4.0
- Author:
- Denis Stepanov
-
-
Constructor Summary
Constructors Constructor Description DefaultSynchronousTransactionState()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear the entire transaction synchronization state: registered synchronizations as well as the various transaction characteristics.voidclearSynchronization()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.IsolationgetTransactionIsolationLevel()Return the isolation level for the current transaction, if any.java.lang.StringgetTransactionName()Return the name of the current transaction, ornullif none set.voidinitSynchronization()Activate transaction synchronization for the current state.booleanisActualTransactionActive()Return whether there currently is an actual transaction active.booleanisSynchronizationActive()Return if transaction synchronization is active for the current state.booleanisTransactionReadOnly()Return whether the current transaction is marked as read-only.voidregisterSynchronization(TransactionSynchronization synchronization)Register a new transaction synchronization for the current state.voidsetActualTransactionActive(boolean active)Expose whether there currently is an actual transaction active.voidsetTransactionIsolationLevel(TransactionDefinition.Isolation isolationLevel)Expose an isolation level for the current transaction.voidsetTransactionName(java.lang.String name)Expose the name of the current transaction, if any.voidsetTransactionReadOnly(boolean readOnly)Expose a read-only flag for the current transaction.
-
-
-
Method Detail
-
isSynchronizationActive
public boolean isSynchronizationActive()
Description copied from interface:SynchronousTransactionStateReturn if transaction synchronization is active for the current state. Can be called before register to avoid unnecessary instance creation.- Specified by:
isSynchronizationActivein interfaceSynchronousTransactionState- Returns:
- True if a synchronization is active
- See Also:
SynchronousTransactionState.registerSynchronization(io.micronaut.transaction.support.TransactionSynchronization)
-
initSynchronization
public void initSynchronization() throws java.lang.IllegalStateExceptionDescription copied from interface:SynchronousTransactionStateActivate transaction synchronization for the current state. Called by a transaction manager on transaction begin.- Specified by:
initSynchronizationin interfaceSynchronousTransactionState- Throws:
java.lang.IllegalStateException- if synchronization is already active
-
registerSynchronization
public void registerSynchronization(TransactionSynchronization synchronization)
Description copied from interface:SynchronousTransactionStateRegister a new transaction synchronization for the current state. Typically called by resource management code.Note that synchronizations can implement the
Orderedinterface. They will be executed in an order according to their order value (if any).- Specified by:
registerSynchronizationin interfaceSynchronousTransactionState- Parameters:
synchronization- the synchronization object to register- See Also:
Ordered
-
getSynchronizations
public java.util.List<TransactionSynchronization> getSynchronizations() throws java.lang.IllegalStateException
Description copied from interface:SynchronousTransactionStateReturn an unmodifiable snapshot list of all registered synchronizations for the current state.- Specified by:
getSynchronizationsin interfaceSynchronousTransactionState- Returns:
- unmodifiable List of TransactionSynchronization instances
- Throws:
java.lang.IllegalStateException- if synchronization is not active- See Also:
TransactionSynchronization
-
clearSynchronization
public void clearSynchronization() throws java.lang.IllegalStateExceptionDescription copied from interface:SynchronousTransactionStateDeactivate transaction synchronization for the current state. Called by the transaction manager on transaction cleanup.- Specified by:
clearSynchronizationin interfaceSynchronousTransactionState- Throws:
java.lang.IllegalStateException- if synchronization is not active
-
setTransactionName
public void setTransactionName(java.lang.String name)
Description copied from interface:SynchronousTransactionStateExpose the name of the current transaction, if any. Called by the transaction manager on transaction begin and on cleanup.- Specified by:
setTransactionNamein interfaceSynchronousTransactionState- Parameters:
name- the name of the transaction, ornullto reset it- See Also:
TransactionDefinition.getName()
-
getTransactionName
public java.lang.String getTransactionName()
Description copied from interface:SynchronousTransactionStateReturn the name of the current transaction, ornullif none set. To be called by resource management code for optimizations per use case, for example to optimize fetch strategies for specific named transactions.- Specified by:
getTransactionNamein interfaceSynchronousTransactionState- Returns:
- The current transaction name
- See Also:
TransactionDefinition.getName()
-
setTransactionReadOnly
public void setTransactionReadOnly(boolean readOnly)
Description copied from interface:SynchronousTransactionStateExpose a read-only flag for the current transaction. Called by the transaction manager on transaction begin and on cleanup.- Specified by:
setTransactionReadOnlyin interfaceSynchronousTransactionState- Parameters:
readOnly-trueto mark the current transaction as read-only;falseto reset such a read-only marker- See Also:
TransactionDefinition.isReadOnly()
-
isTransactionReadOnly
public boolean isTransactionReadOnly()
Description copied from interface:SynchronousTransactionStateReturn whether the current transaction is marked as read-only. To be called by resource management code when preparing a newly created resource (for example, a Hibernate Session).Note that transaction synchronizations receive the read-only flag as argument for the
beforeCommitcallback, 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.- Specified by:
isTransactionReadOnlyin interfaceSynchronousTransactionState- Returns:
- Whether the transaction is read only
- See Also:
TransactionDefinition.isReadOnly(),TransactionSynchronization.beforeCommit(boolean)
-
setTransactionIsolationLevel
public void setTransactionIsolationLevel(TransactionDefinition.Isolation isolationLevel)
Description copied from interface:SynchronousTransactionStateExpose an isolation level for the current transaction. Called by the transaction manager on transaction begin and on cleanup.- Specified by:
setTransactionIsolationLevelin interfaceSynchronousTransactionState- Parameters:
isolationLevel- the isolation level to expose, according to the JDBC Connection constants (equivalent to the corresponding TransactionDefinition constants), ornullto reset it- See Also:
Connection.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()
-
getTransactionIsolationLevel
public TransactionDefinition.Isolation getTransactionIsolationLevel()
Description copied from interface:SynchronousTransactionStateReturn the isolation level for the current transaction, if any. To be called by resource management code when preparing a newly created resource (for example, a JDBC Connection).- Specified by:
getTransactionIsolationLevelin interfaceSynchronousTransactionState- Returns:
- the currently exposed isolation level, according to the
JDBC Connection constants (equivalent to the corresponding
TransactionDefinition constants), or
nullif none - See Also:
Connection.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()
-
setActualTransactionActive
public void setActualTransactionActive(boolean active)
Description copied from interface:SynchronousTransactionStateExpose whether there currently is an actual transaction active. Called by the transaction manager on transaction begin and on cleanup.- Specified by:
setActualTransactionActivein interfaceSynchronousTransactionState- Parameters:
active-trueto mark the current state as being associated with an actual transaction;falseto reset that marker
-
isActualTransactionActive
public boolean isActualTransactionActive()
Description copied from interface:SynchronousTransactionStateReturn whether there currently is an actual transaction active. This indicates whether the current state is associated with an actual transaction rather than just with active transaction synchronization.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).
- Specified by:
isActualTransactionActivein interfaceSynchronousTransactionState- Returns:
- Whether a transaction is active
- See Also:
SynchronousTransactionState.isSynchronizationActive()
-
clear
public void clear()
Description copied from interface:SynchronousTransactionStateClear the entire transaction synchronization state: registered synchronizations as well as the various transaction characteristics.- Specified by:
clearin interfaceSynchronousTransactionState- See Also:
SynchronousTransactionState.clearSynchronization(),SynchronousTransactionState.setTransactionName(java.lang.String),SynchronousTransactionState.setTransactionReadOnly(boolean),SynchronousTransactionState.setTransactionIsolationLevel(io.micronaut.transaction.TransactionDefinition.Isolation),SynchronousTransactionState.setActualTransactionActive(boolean)
-
-