Class DefaultTransactionDefinition
- All Implemented Interfaces:
TransactionDefinition
TransactionDefinition
interface,
offering bean-style configuration and sensible default values
(PROPAGATION_REQUIRED, ISOLATION_DEFAULT, TIMEOUT_DEFAULT, readOnly=false).- Since:
- 08.05.2003
- Author:
- Juergen Hoeller
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.transaction.TransactionDefinition
TransactionDefinition.Isolation, TransactionDefinition.Propagation
-
Field Summary
Fields inherited from interface io.micronaut.transaction.TransactionDefinition
DEFAULT, READ_ONLY, TIMEOUT_DEFAULT
-
Constructor Summary
ConstructorDescriptionCreate a new DefaultTransactionDefinition, with default settings.DefaultTransactionDefinition
(@NonNull TransactionDefinition.Propagation propagationBehavior) Create a new DefaultTransactionDefinition with the given propagation behavior.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
This implementation compares thetoString()
results.Collection<Class<? extends Throwable>>
Collection of exception classes that shouldn't cause the rollback.final @NonNull Optional<TransactionDefinition.Isolation>
Return the isolation level.final @Nullable String
getName()
Return the name of this transaction.final @NonNull TransactionDefinition.Propagation
Return the propagation behavior.Collection<Class<? extends Throwable>>
Collection of exception classes that should cause the rollback.Return the transaction timeout.int
hashCode()
This implementation returnstoString()
's hash code.Return whether to optimize as a read-only transaction.void
setDontRollbackOn
(@Nullable Collection<Class<? extends Throwable>> dontRollbackOn) Set exception classes which shouldn't cause the rollback.final void
setIsolationLevel
(@NonNull TransactionDefinition.Isolation isolationLevel) Set the isolation level.final void
Set the name of this transaction.final void
setPropagationBehavior
(@NonNull TransactionDefinition.Propagation propagationBehavior) Set the propagation behavior.final void
setReadOnly
(boolean readOnly) Set whether to optimize as read-only transaction.void
setRollbackOn
(@Nullable Collection<Class<? extends Throwable>> rollbackOn) Set exception classes which should cause the rollback.final void
setTimeout
(@NonNull Duration timeout) Set the timeout to apply, as number of seconds.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.micronaut.transaction.TransactionDefinition
getConnectionDefinition, rollbackOn
-
Constructor Details
-
DefaultTransactionDefinition
public DefaultTransactionDefinition()Create a new DefaultTransactionDefinition, with default settings. Can be modified through bean property setters. -
DefaultTransactionDefinition
Copy constructor. Definition can be modified through bean property setters. -
DefaultTransactionDefinition
public DefaultTransactionDefinition(@NonNull @NonNull TransactionDefinition.Propagation propagationBehavior) Create a new DefaultTransactionDefinition with the given propagation behavior. Can be modified through bean property setters.- Parameters:
propagationBehavior
- one of the propagation constants in the TransactionDefinition interface- See Also:
-
-
Method Details
-
setPropagationBehavior
public final void setPropagationBehavior(@NonNull @NonNull TransactionDefinition.Propagation propagationBehavior) Set the propagation behavior. Must be one of the propagation constants in the TransactionDefinition interface. Default is PROPAGATION_REQUIRED.Exclusively designed for use with
TransactionDefinition.Propagation.REQUIRED
orTransactionDefinition.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
TransactionDefinition.Isolation.DEFAULT
.- Parameters:
propagationBehavior
- The propagation behaviour to use.- Throws:
IllegalArgumentException
- if the supplied value is not one of thePROPAGATION_
constants- See Also:
-
getPropagationBehavior
Description copied from interface:TransactionDefinition
Return the propagation behavior.Must return one of the
PROPAGATION_XXX
constants defined onthis interface
.The default is
TransactionDefinition.Propagation.REQUIRED
.- Specified by:
getPropagationBehavior
in interfaceTransactionDefinition
- Returns:
- the propagation behavior
- See Also:
-
setIsolationLevel
public final void setIsolationLevel(@NonNull @NonNull TransactionDefinition.Isolation isolationLevel) Set the isolation level. Must be one of the isolation constants in the TransactionDefinition interface. Default is ISOLATION_DEFAULT.Exclusively designed for use with
TransactionDefinition.Propagation.REQUIRED
orTransactionDefinition.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
TransactionDefinition.Isolation.DEFAULT
.- Parameters:
isolationLevel
- The isolation level- Throws:
IllegalArgumentException
- if the supplied value is not one of theISOLATION_
constants- See Also:
-
getIsolationLevel
Description copied from interface:TransactionDefinition
Return the isolation level.Must return one of the
ISOLATION_XXX
constants defined onthis interface
. Those constants are designed to match the values of the same constants onConnection
.Exclusively designed for use with
TransactionDefinition.Propagation.REQUIRED
orTransactionDefinition.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 thanTransactionDefinition.Isolation.DEFAULT
.- Specified by:
getIsolationLevel
in interfaceTransactionDefinition
- Returns:
- the isolation level
- See Also:
-
setTimeout
Set the timeout to apply, as number of seconds. Default is TIMEOUT_DEFAULT (-1).Exclusively designed for use with
TransactionDefinition.Propagation.REQUIRED
orTransactionDefinition.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
.- Parameters:
timeout
- The timeout to use- See Also:
-
getTimeout
Description copied from interface:TransactionDefinition
Return the transaction timeout.Must return a number of seconds, or
TransactionDefinition.TIMEOUT_DEFAULT
.Exclusively designed for use with
TransactionDefinition.Propagation.REQUIRED
orTransactionDefinition.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
.- Specified by:
getTimeout
in interfaceTransactionDefinition
- Returns:
- the transaction timeout
-
setReadOnly
public final void setReadOnly(boolean readOnly) Set whether to optimize as read-only transaction. Default is "false".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 HibernateSession
.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.
- Parameters:
readOnly
- Whether the transaction is read only
-
isReadOnly
Description copied from interface:TransactionDefinition
Return whether to optimize as a read-only transaction.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 HibernateSession
.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.
- Specified by:
isReadOnly
in interfaceTransactionDefinition
- Returns:
true
if the transaction is to be optimized as read-only (false
by default)
-
setName
Set the name of this transaction. Default is none.This will be used as transaction name to be shown in a transaction monitor, if applicable (for example, WebLogic's).
- Parameters:
name
- The name of the transaction
-
getName
Description copied from interface:TransactionDefinition
Return the name of this transaction. Can benull
.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).- Specified by:
getName
in interfaceTransactionDefinition
- Returns:
- the name of this transaction (
null
by default)
-
setRollbackOn
Set exception classes which should cause the rollback. Empty if all should cause it.- Parameters:
rollbackOn
- The exception classes- Since:
- 3.5.0
-
setDontRollbackOn
public void setDontRollbackOn(@Nullable @Nullable Collection<Class<? extends Throwable>> dontRollbackOn) Set exception classes which shouldn't cause the rollback.- Parameters:
dontRollbackOn
- The exception classes- Since:
- 3.5.0
-
getRollbackOn
Description copied from interface:TransactionDefinition
Collection of exception classes that should cause the rollback. Empty if all exception should cause the rollback.- Specified by:
getRollbackOn
in interfaceTransactionDefinition
- Returns:
- the exception classes
-
getDontRollbackOn
Description copied from interface:TransactionDefinition
Collection of exception classes that shouldn't cause the rollback.- Specified by:
getDontRollbackOn
in interfaceTransactionDefinition
- Returns:
- the exception classes
-
equals
This implementation compares thetoString()
results. -
hashCode
public int hashCode()This implementation returnstoString()
's hash code. -
toString
-