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