Class DefaultTransactionDefinition
- All Implemented Interfaces:
- Serializable,- TransactionDefinition
- Direct Known Subclasses:
- DefaultTransactionAttribute,- TransactionTemplate
TransactionDefinition interface,
 offering bean-style configuration and sensible default values
 (PROPAGATION_REQUIRED, ISOLATION_DEFAULT, TIMEOUT_DEFAULT, readOnly=false).
 Base class for both TransactionTemplate and
 DefaultTransactionAttribute.
- Since:
- 08.05.2003
- Author:
- Juergen Hoeller
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringPrefix for the isolation constants defined in TransactionDefinition.static final StringPrefix for the propagation constants defined in TransactionDefinition.static final StringPrefix for transaction timeout values in description strings.static final StringMarker for read-only transactions in description strings.Fields inherited from interface org.springframework.transaction.TransactionDefinitionISOLATION_DEFAULT, ISOLATION_READ_COMMITTED, ISOLATION_READ_UNCOMMITTED, ISOLATION_REPEATABLE_READ, ISOLATION_SERIALIZABLE, PROPAGATION_MANDATORY, PROPAGATION_NESTED, PROPAGATION_NEVER, PROPAGATION_NOT_SUPPORTED, PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, PROPAGATION_SUPPORTS, TIMEOUT_DEFAULT
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a newDefaultTransactionDefinitionwith default settings.DefaultTransactionDefinition(int propagationBehavior) Create a newDefaultTransactionDefinitionwith the given propagation behavior.Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanThis implementation compares thetoString()results.protected final StringBuilderReturn an identifying description for this transaction definition.final intReturn the isolation level.final StringgetName()Return the name of this transaction.final intReturn the propagation behavior.final intReturn the transaction timeout.inthashCode()This implementation returnstoString()'s hash code.final booleanReturn whether to optimize as a read-only transaction.final voidsetIsolationLevel(int isolationLevel) Set the isolation level.final voidsetIsolationLevelName(String constantName) Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g.final voidSet the name of this transaction.final voidsetPropagationBehavior(int propagationBehavior) Set the propagation behavior.final voidsetPropagationBehaviorName(String constantName) Set the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g.final voidsetReadOnly(boolean readOnly) Set whether to optimize as read-only transaction.final voidsetTimeout(int timeout) Set the timeout to apply, as number of seconds.toString()Return an identifying description for this transaction definition.
- 
Field Details- 
PREFIX_PROPAGATIONPrefix for the propagation constants defined in TransactionDefinition.- See Also:
 
- 
PREFIX_ISOLATIONPrefix for the isolation constants defined in TransactionDefinition.- See Also:
 
- 
PREFIX_TIMEOUTPrefix for transaction timeout values in description strings.- See Also:
 
- 
READ_ONLY_MARKERMarker for read-only transactions in description strings.- See Also:
 
 
- 
- 
Constructor Details- 
DefaultTransactionDefinitionpublic DefaultTransactionDefinition()Create a newDefaultTransactionDefinitionwith default settings. Can be modified through bean property setters.
- 
DefaultTransactionDefinitionCopy constructor. Definition can be modified through bean property setters.
- 
DefaultTransactionDefinitionpublic DefaultTransactionDefinition(int propagationBehavior) Create a newDefaultTransactionDefinitionwith 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- 
setPropagationBehaviorNameSet the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g. "PROPAGATION_REQUIRED".- Parameters:
- constantName- name of the constant
- Throws:
- IllegalArgumentException- if the supplied value is not resolvable to one of the- PROPAGATION_constants or is- null
- See Also:
 
- 
setPropagationBehaviorpublic final void setPropagationBehavior(int 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.- Throws:
- IllegalArgumentException- if the supplied value is not one of the- PROPAGATION_constants
- See Also:
 
- 
getPropagationBehaviorpublic final int getPropagationBehavior()Description 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:
 
- 
setIsolationLevelNameSet the isolation level by the name of the corresponding constant in TransactionDefinition, e.g. "ISOLATION_DEFAULT".- Parameters:
- constantName- name of the constant
- Throws:
- IllegalArgumentException- if the supplied value is not resolvable to one of the- ISOLATION_constants or is- null
- See Also:
 
- 
setIsolationLevelpublic final void setIsolationLevel(int 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.- Throws:
- IllegalArgumentException- if the supplied value is not one of the- ISOLATION_constants
- See Also:
 
- 
getIsolationLevelpublic final int getIsolationLevel()Description 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:
 
- 
setTimeoutpublic final void setTimeout(int timeout) Set 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.- See Also:
 
- 
getTimeoutpublic final int getTimeout()Description 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. 
- 
isReadOnlypublic final boolean isReadOnly()Description 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)
- See Also:
 
- 
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). 
- 
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. 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}
- See Also:
 
- 
equalsThis implementation compares thetoString()results.
- 
hashCodepublic int hashCode()This implementation returnstoString()'s hash code.
- 
toStringReturn an identifying description for this transaction definition.The format matches the one used by TransactionAttributeEditor, to be able to feedtoStringresults into bean properties of typeTransactionAttribute.Has to be overridden in subclasses for correct equalsandhashCodebehavior. Alternatively,equals(java.lang.Object)andhashCode()can be overridden themselves.
- 
getDefinitionDescriptionReturn an identifying description for this transaction definition.Available to subclasses, for inclusion in their toString()result.
 
-