类 DefaultTransactionDefinition
- java.lang.Object
- org.springframework.transaction.support.DefaultTransactionDefinition
- 所有已实现的接口:
Serializable,TransactionDefinition
public class DefaultTransactionDefinition extends Object implements TransactionDefinition, Serializable
Default implementation of theTransactionDefinitioninterface, offering bean-style configuration and sensible default values (PROPAGATION_REQUIRED, ISOLATION_DEFAULT, TIMEOUT_DEFAULT, readOnly=false).Base class for both
TransactionTemplateandDefaultTransactionAttribute.- 从以下版本开始:
- 08.05.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
- 序列化表格
字段概要
字段 修饰符和类型 字段 说明 static StringPREFIX_ISOLATIONPrefix for the isolation constants defined in TransactionDefinition.static StringPREFIX_PROPAGATIONPrefix for the propagation constants defined in TransactionDefinition.static StringPREFIX_TIMEOUTPrefix for transaction timeout values in description strings.static StringREAD_ONLY_MARKERMarker for read-only transactions in description strings.从接口继承的字段 org.springframework.transaction.TransactionDefinition
ISOLATION_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
构造器概要
构造器 构造器 说明 DefaultTransactionDefinition()Create a new DefaultTransactionDefinition, with default settings.DefaultTransactionDefinition(int propagationBehavior)Create a new DefaultTransactionDefinition with the given propagation behavior.DefaultTransactionDefinition(TransactionDefinition other)Copy constructor.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 booleanequals(Object other)This implementation compares thetoString()results.protected StringBuildergetDefinitionDescription()Return an identifying description for this transaction definition.intgetIsolationLevel()Return the isolation level.StringgetName()Return the name of this transaction.intgetPropagationBehavior()Return the propagation behavior.intgetTimeout()Return the transaction timeout.inthashCode()This implementation returnstoString()'s hash code.booleanisReadOnly()Return whether to optimize as a read-only transaction.voidsetIsolationLevel(int isolationLevel)Set the isolation level.voidsetIsolationLevelName(String constantName)Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g.voidsetName(String name)Set the name of this transaction.voidsetPropagationBehavior(int propagationBehavior)Set the propagation behavior.voidsetPropagationBehaviorName(String constantName)Set the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g.voidsetReadOnly(boolean readOnly)Set whether to optimize as read-only transaction.voidsetTimeout(int timeout)Set the timeout to apply, as number of seconds.StringtoString()Return an identifying description for this transaction definition.
字段详细资料
PREFIX_PROPAGATION
public static final String PREFIX_PROPAGATION
Prefix for the propagation constants defined in TransactionDefinition.- 另请参阅:
- 常量字段值
PREFIX_ISOLATION
public static final String PREFIX_ISOLATION
Prefix for the isolation constants defined in TransactionDefinition.- 另请参阅:
- 常量字段值
PREFIX_TIMEOUT
public static final String PREFIX_TIMEOUT
Prefix for transaction timeout values in description strings.- 另请参阅:
- 常量字段值
READ_ONLY_MARKER
public static final String READ_ONLY_MARKER
Marker for read-only transactions in description strings.- 另请参阅:
- 常量字段值
构造器详细资料
DefaultTransactionDefinition
public DefaultTransactionDefinition()
Create a new DefaultTransactionDefinition, with default settings. Can be modified through bean property setters.
DefaultTransactionDefinition
public DefaultTransactionDefinition(TransactionDefinition other)
Copy constructor. Definition can be modified through bean property setters.
DefaultTransactionDefinition
public DefaultTransactionDefinition(int propagationBehavior)
Create a new DefaultTransactionDefinition with the given propagation behavior. Can be modified through bean property setters.- 参数:
propagationBehavior- one of the propagation constants in the TransactionDefinition interface- 另请参阅:
setIsolationLevel(int),setTimeout(int),setReadOnly(boolean)
方法详细资料
setPropagationBehaviorName
public final void setPropagationBehaviorName(String constantName) throws IllegalArgumentException
Set the propagation behavior by the name of the corresponding constant in TransactionDefinition, e.g. "PROPAGATION_REQUIRED".- 参数:
constantName- name of the constant- 抛出:
IllegalArgumentException- if the supplied value is not resolvable to one of thePROPAGATION_constants or isnull- 另请参阅:
setPropagationBehavior(int),TransactionDefinition.PROPAGATION_REQUIRED
setPropagationBehavior
public 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.- 抛出:
IllegalArgumentException- if the supplied value is not one of thePROPAGATION_constants- 另请参阅:
TransactionDefinition.PROPAGATION_REQUIRED
getPropagationBehavior
public final int getPropagationBehavior()
从接口复制的说明:TransactionDefinitionReturn the propagation behavior.Must return one of the
PROPAGATION_XXXconstants defined onthis interface.The default is
TransactionDefinition.PROPAGATION_REQUIRED.- 指定者:
getPropagationBehavior在接口中TransactionDefinition- 返回:
- the propagation behavior
- 另请参阅:
TransactionDefinition.PROPAGATION_REQUIRED,TransactionSynchronizationManager.isActualTransactionActive()
setIsolationLevelName
public final void setIsolationLevelName(String constantName) throws IllegalArgumentException
Set the isolation level by the name of the corresponding constant in TransactionDefinition, e.g. "ISOLATION_DEFAULT".- 参数:
constantName- name of the constant- 抛出:
IllegalArgumentException- if the supplied value is not resolvable to one of theISOLATION_constants or isnull- 另请参阅:
setIsolationLevel(int),TransactionDefinition.ISOLATION_DEFAULT
setIsolationLevel
public 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.- 抛出:
IllegalArgumentException- if the supplied value is not one of theISOLATION_constants- 另请参阅:
TransactionDefinition.ISOLATION_DEFAULT
getIsolationLevel
public final int getIsolationLevel()
从接口复制的说明: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.- 指定者:
getIsolationLevel在接口中TransactionDefinition- 返回:
- the isolation level
- 另请参阅:
TransactionDefinition.ISOLATION_DEFAULT,AbstractPlatformTransactionManager.setValidateExistingTransaction(boolean)
setTimeout
public 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.
getTimeout
public final int getTimeout()
从接口复制的说明: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.- 指定者:
getTimeout在接口中TransactionDefinition- 返回:
- 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.
isReadOnly
public final boolean isReadOnly()
从接口复制的说明: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.
- 指定者:
isReadOnly在接口中TransactionDefinition- 返回:
trueif the transaction is to be optimized as read-only (falseby default)- 另请参阅:
TransactionSynchronization.beforeCommit(boolean),TransactionSynchronizationManager.isCurrentTransactionReadOnly()
setName
public final void setName(String name)
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).
getName
@Nullable public final String getName()
从接口复制的说明: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).- 指定者:
getName在接口中TransactionDefinition- 返回:
- the name of this transaction (
nullby default} - 另请参阅:
TransactionAspectSupport,TransactionSynchronizationManager.getCurrentTransactionName()
equals
public boolean equals(@Nullable Object other)
This implementation compares thetoString()results.- 覆盖:
equals在类中Object- 另请参阅:
toString()
hashCode
public int hashCode()
This implementation returnstoString()'s hash code.- 覆盖:
hashCode在类中Object- 另请参阅:
toString()
toString
public String toString()
Return 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.
getDefinitionDescription
protected final StringBuilder getDefinitionDescription()
Return an identifying description for this transaction definition.Available to subclasses, for inclusion in their
toString()result.