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 SummaryNested classes/interfaces inherited from interface io.micronaut.transaction.TransactionDefinitionTransactionDefinition.Isolation, TransactionDefinition.Propagation
- 
Field SummaryFields inherited from interface io.micronaut.transaction.TransactionDefinitionDEFAULT, READ_ONLY, TIMEOUT_DEFAULT
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new DefaultTransactionDefinition, with default settings.DefaultTransactionDefinition(@NonNull TransactionDefinition.Propagation propagationBehavior) Create a new DefaultTransactionDefinition with the given propagation behavior.Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanThis 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 StringgetName()Return the name of this transaction.final @NonNull TransactionDefinition.PropagationReturn the propagation behavior.Collection<Class<? extends Throwable>>Collection of exception classes that should cause the rollback.Return the transaction timeout.inthashCode()This implementation returnstoString()'s hash code.Return whether to optimize as a read-only transaction.voidsetDontRollbackOn(@Nullable Collection<Class<? extends Throwable>> dontRollbackOn) Set exception classes which shouldn't cause the rollback.final voidsetIsolationLevel(@NonNull TransactionDefinition.Isolation isolationLevel) Set the isolation level.final voidSet the name of this transaction.final voidsetPropagationBehavior(@NonNull TransactionDefinition.Propagation propagationBehavior) Set the propagation behavior.final voidsetReadOnly(boolean readOnly) Set whether to optimize as read-only transaction.voidsetRollbackOn(@Nullable Collection<Class<? extends Throwable>> rollbackOn) Set exception classes which should cause the rollback.final voidsetTimeout(@NonNull Duration timeout) Set the timeout to apply, as number of seconds.toString()Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.micronaut.transaction.TransactionDefinitiongetConnectionDefinition, rollbackOn
- 
Constructor Details- 
DefaultTransactionDefinitionpublic DefaultTransactionDefinition()Create a new DefaultTransactionDefinition, with default settings. Can be modified through bean property setters.
- 
DefaultTransactionDefinitionCopy constructor. Definition can be modified through bean property setters.
- 
DefaultTransactionDefinitionpublic 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- 
setPropagationBehaviorpublic 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.REQUIREDorTransactionDefinition.Propagation.REQUIRES_NEWsince 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 the- PROPAGATION_constants
- See Also:
 
- 
getPropagationBehaviorDescription copied from interface:TransactionDefinitionReturn the propagation behavior.Must return one of the PROPAGATION_XXXconstants defined onthis interface.The default is TransactionDefinition.Propagation.REQUIRED.- Specified by:
- getPropagationBehaviorin interface- TransactionDefinition
- Returns:
- the propagation behavior
- See Also:
 
- 
setIsolationLevelpublic 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.REQUIREDorTransactionDefinition.Propagation.REQUIRES_NEWsince 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 the- ISOLATION_constants
- See Also:
 
- 
getIsolationLevelDescription copied from interface:TransactionDefinitionReturn the isolation level.Must return one of the ISOLATION_XXXconstants defined onthis interface. Those constants are designed to match the values of the same constants onConnection.Exclusively designed for use with TransactionDefinition.Propagation.REQUIREDorTransactionDefinition.Propagation.REQUIRES_NEWsince 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:
- getIsolationLevelin interface- TransactionDefinition
- Returns:
- the isolation level
- See Also:
 
- 
setTimeoutSet the timeout to apply, as number of seconds. Default is TIMEOUT_DEFAULT (-1).Exclusively designed for use with TransactionDefinition.Propagation.REQUIREDorTransactionDefinition.Propagation.REQUIRES_NEWsince 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:
 
- 
getTimeoutDescription copied from interface:TransactionDefinitionReturn the transaction timeout.Must return a number of seconds, or TransactionDefinition.TIMEOUT_DEFAULT.Exclusively designed for use with TransactionDefinition.Propagation.REQUIREDorTransactionDefinition.Propagation.REQUIRES_NEWsince 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:
- getTimeoutin interface- TransactionDefinition
- Returns:
- the transaction timeout
 
- 
setReadOnlypublic 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
 
- 
isReadOnlyDescription copied from interface:TransactionDefinitionReturn 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:
- isReadOnlyin interface- TransactionDefinition
- Returns:
- trueif the transaction is to be optimized as read-only (- falseby default)
 
- 
setNameSet 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
 
- 
getNameDescription copied from interface:TransactionDefinitionReturn 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:
- getNamein interface- TransactionDefinition
- Returns:
- the name of this transaction (nullby default}
 
- 
setRollbackOnSet exception classes which should cause the rollback. Empty if all should cause it.- Parameters:
- rollbackOn- The exception classes
- Since:
- 3.5.0
 
- 
setDontRollbackOnpublic 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
 
- 
getRollbackOnDescription copied from interface:TransactionDefinitionCollection of exception classes that should cause the rollback. Empty if all exception should cause the rollback.- Specified by:
- getRollbackOnin interface- TransactionDefinition
- Returns:
- the exception classes
 
- 
getDontRollbackOnDescription copied from interface:TransactionDefinitionCollection of exception classes that shouldn't cause the rollback.- Specified by:
- getDontRollbackOnin interface- TransactionDefinition
- Returns:
- the exception classes
 
- 
equalsThis implementation compares thetoString()results.
- 
hashCodepublic int hashCode()This implementation returnstoString()'s hash code.
- 
toString
 
-