public class DefaultTransactionDefinition extends java.lang.Object implements TransactionDefinition, java.io.Serializable
TransactionDefinition
interface,
offering bean-style configuration and sensible default values
(PROPAGATION_REQUIRED, ISOLATION_DEFAULT, TIMEOUT_DEFAULT, readOnly=false).TransactionDefinition.Isolation, TransactionDefinition.Propagation
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PREFIX_ISOLATION
Prefix for the isolation constants defined in TransactionDefinition.
|
static java.lang.String |
PREFIX_PROPAGATION
Prefix for the propagation constants defined in TransactionDefinition.
|
static java.lang.String |
PREFIX_TIMEOUT
Prefix for transaction timeout values in description strings.
|
static java.lang.String |
READ_ONLY_MARKER
Marker for read-only transactions in description strings.
|
DEFAULT, READ_ONLY, TIMEOUT_DEFAULT
Constructor and Description |
---|
DefaultTransactionDefinition()
Create a new DefaultTransactionDefinition, with default settings.
|
DefaultTransactionDefinition(TransactionDefinition.Propagation propagationBehavior)
Create a new DefaultTransactionDefinition with the given
propagation behavior.
|
DefaultTransactionDefinition(TransactionDefinition other)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other)
This implementation compares the
toString() results. |
TransactionDefinition.Isolation |
getIsolationLevel()
Return the isolation level.
|
java.lang.String |
getName()
Return the name of this transaction.
|
TransactionDefinition.Propagation |
getPropagationBehavior()
Return the propagation behavior.
|
java.time.Duration |
getTimeout()
Return the transaction timeout.
|
int |
hashCode()
This implementation returns
toString() 's hash code. |
boolean |
isReadOnly()
Return whether to optimize as a read-only transaction.
|
void |
setIsolationLevel(TransactionDefinition.Isolation isolationLevel)
Set the isolation level.
|
void |
setName(java.lang.String name)
Set the name of this transaction.
|
void |
setPropagationBehavior(TransactionDefinition.Propagation propagationBehavior)
Set the propagation behavior.
|
void |
setReadOnly(boolean readOnly)
Set whether to optimize as read-only transaction.
|
void |
setTimeout(java.time.Duration timeout)
Set the timeout to apply, as number of seconds.
|
java.lang.String |
toString()
Return an identifying description for this transaction definition.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
of
public static final java.lang.String PREFIX_PROPAGATION
public static final java.lang.String PREFIX_ISOLATION
public static final java.lang.String PREFIX_TIMEOUT
public static final java.lang.String READ_ONLY_MARKER
public DefaultTransactionDefinition()
public DefaultTransactionDefinition(TransactionDefinition other)
other
- The other definitionsetPropagationBehavior(io.micronaut.transaction.TransactionDefinition.Propagation)
,
setIsolationLevel(io.micronaut.transaction.TransactionDefinition.Isolation)
,
setTimeout(java.time.Duration)
,
setReadOnly(boolean)
,
setName(java.lang.String)
public DefaultTransactionDefinition(@NonNull TransactionDefinition.Propagation propagationBehavior)
propagationBehavior
- one of the propagation constants in the
TransactionDefinition interfacesetIsolationLevel(io.micronaut.transaction.TransactionDefinition.Isolation)
,
setTimeout(java.time.Duration)
,
setReadOnly(boolean)
public final void setPropagationBehavior(@NonNull TransactionDefinition.Propagation propagationBehavior)
Exclusively designed for use with Propagation#REQUIRED
or
Propagation#REQUIRES_NEW
since it only applies to newly started
transactions. Consider switching the "validateExistingTransactions" flag to
"true" on your transaction manager if you'd like isolation level declarations
to get rejected when participating in an existing transaction with a different
isolation level.
Note that a transaction manager that does not support custom isolation levels
will throw an exception when given any other level than Isolation#DEFAULT
.
propagationBehavior
- The propagation behaviour to use.java.lang.IllegalArgumentException
- if the supplied value is not one of the
PROPAGATION_
constantsPropagation#REQUIRED
@NonNull public final TransactionDefinition.Propagation getPropagationBehavior()
TransactionDefinition
Must return one of the PROPAGATION_XXX
constants
defined on this interface
.
The default is TransactionDefinition.Propagation.REQUIRED
.
getPropagationBehavior
in interface TransactionDefinition
TransactionDefinition.Propagation.REQUIRED
public final void setIsolationLevel(@NonNull TransactionDefinition.Isolation isolationLevel)
Exclusively designed for use with Propagation#REQUIRED
or
Propagation#REQUIRES_NEW
since it only applies to newly started
transactions. Consider switching the "validateExistingTransactions" flag to
"true" on your transaction manager if you'd like isolation level declarations
to get rejected when participating in an existing transaction with a different
isolation level.
Note that a transaction manager that does not support custom isolation levels
will throw an exception when given any other level than Isolation#DEFAULT
.
isolationLevel
- The isolation leveljava.lang.IllegalArgumentException
- if the supplied value is not one of the
ISOLATION_
constantsIsolation#DEFAULT
@NonNull public final TransactionDefinition.Isolation getIsolationLevel()
TransactionDefinition
Must return one of the ISOLATION_XXX
constants defined on
this interface
. Those constants are designed
to match the values of the same constants on Connection
.
Exclusively designed for use with TransactionDefinition.Propagation.REQUIRED
or
TransactionDefinition.Propagation.REQUIRES_NEW
since it only applies to newly started
transactions. Consider switching the "validateExistingTransactions" flag to
"true" on your transaction manager if you'd like isolation level declarations
to get rejected when participating in an existing transaction with a different
isolation level.
The default is TransactionDefinition.Isolation.DEFAULT
. Note that a transaction manager
that does not support custom isolation levels will throw an exception when
given any other level than TransactionDefinition.Isolation.DEFAULT
.
getIsolationLevel
in interface TransactionDefinition
TransactionDefinition.Isolation.DEFAULT
public final void setTimeout(@NonNull java.time.Duration timeout)
Exclusively designed for use with TransactionDefinition.Propagation.REQUIRED
or
TransactionDefinition.Propagation.REQUIRES_NEW
since it only applies to newly started
transactions.
Note that a transaction manager that does not support timeouts will throw
an exception when given any other timeout than TransactionDefinition.TIMEOUT_DEFAULT
.
timeout
- The timeout to useTransactionDefinition.TIMEOUT_DEFAULT
@NonNull public final java.time.Duration getTimeout()
TransactionDefinition
Must return a number of seconds, or TransactionDefinition.TIMEOUT_DEFAULT
.
Exclusively designed for use with TransactionDefinition.Propagation.REQUIRED
or
TransactionDefinition.Propagation.REQUIRES_NEW
since it only applies to newly started
transactions.
Note that a transaction manager that does not support timeouts will throw
an exception when given any other timeout than TransactionDefinition.TIMEOUT_DEFAULT
.
The default is TransactionDefinition.TIMEOUT_DEFAULT
.
getTimeout
in interface TransactionDefinition
public final void setReadOnly(boolean readOnly)
The read-only flag applies to any transaction context, whether backed
by an actual resource transaction (TransactionDefinition.Propagation.REQUIRED
/
Propagation#REQUIRES_NEW
) or operating non-transactionally at
the resource level (Propagation#SUPPORTS
). In the latter case,
the flag will only apply to managed resources within the application,
such as a Hibernate Session
.
This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction.
readOnly
- Whether the transaction is read onlypublic final boolean isReadOnly()
TransactionDefinition
The read-only flag applies to any transaction context, whether backed
by an actual resource transaction (TransactionDefinition.Propagation.REQUIRED
/
TransactionDefinition.Propagation.REQUIRES_NEW
) or operating non-transactionally at
the resource level (TransactionDefinition.Propagation.SUPPORTS
). In the latter case,
the flag will only apply to managed resources within the application,
such as a Hibernate Session
.
This just serves as a hint for the actual transaction subsystem; it will not necessarily cause failure of write access attempts. A transaction manager which cannot interpret the read-only hint will not throw an exception when asked for a read-only transaction.
isReadOnly
in interface TransactionDefinition
true
if the transaction is to be optimized as read-only
(false
by default)TransactionSynchronization.beforeCommit(boolean)
,
TransactionSynchronizationManager.isCurrentTransactionReadOnly()
public final void setName(java.lang.String name)
This will be used as transaction name to be shown in a transaction monitor, if applicable (for example, WebLogic's).
name
- The name of the transaction@Nullable public final java.lang.String getName()
TransactionDefinition
null
.
This will be used as the transaction name to be shown in a transaction monitor, if applicable (for example, WebLogic's).
In case of Spring's declarative transactions, the exposed name will be
the fully-qualified class name + "." + method name
(by default).
getName
in interface TransactionDefinition
null
by default}TransactionSynchronizationManager.getCurrentTransactionName()
public boolean equals(@Nullable java.lang.Object other)
toString()
results.equals
in class java.lang.Object
toString()
public int hashCode()
toString()
's hash code.hashCode
in class java.lang.Object
toString()
public java.lang.String toString()
toString
in class java.lang.Object