类 JtaTransactionManager
- java.lang.Object
- org.springframework.transaction.support.AbstractPlatformTransactionManager
- org.springframework.transaction.jta.JtaTransactionManager
- 所有已实现的接口:
Serializable,InitializingBean,TransactionFactory,PlatformTransactionManager,TransactionManager
public class JtaTransactionManager extends AbstractPlatformTransactionManager implements TransactionFactory, InitializingBean, Serializable
PlatformTransactionManagerimplementation for JTA, delegating to a backend JTA provider. This is typically used to delegate to a Java EE server's transaction coordinator, but may also be configured with a local JTA provider which is embedded within the application.This transaction manager is appropriate for handling distributed transactions, i.e. transactions that span multiple resources, and for controlling transactions on application server resources (e.g. JDBC DataSources available in JNDI) in general. For a single JDBC DataSource, DataSourceTransactionManager is perfectly sufficient, and for accessing a single resource with Hibernate (including transactional cache), HibernateTransactionManager is appropriate, for example.
For typical JTA transactions (REQUIRED, SUPPORTS, MANDATORY, NEVER), a plain JtaTransactionManager definition is all you need, portable across all Java EE servers. This corresponds to the functionality of the JTA UserTransaction, for which Java EE specifies a standard JNDI name ("java:comp/UserTransaction"). There is no need to configure a server-specific TransactionManager lookup for this kind of JTA usage.
Transaction suspension (REQUIRES_NEW, NOT_SUPPORTED) is just available with a JTA TransactionManager being registered. Common TransactionManager locations are autodetected by JtaTransactionManager, provided that the "autodetectTransactionManager" flag is set to "true" (which it is by default).
Note: Support for the JTA TransactionManager interface is not required by Java EE. Almost all Java EE servers expose it, but do so as extension to EE. There might be some issues with compatibility, despite the TransactionManager interface being part of JTA. As a consequence, Spring provides various vendor-specific PlatformTransactionManagers, which are recommended to be used if appropriate:
WebLogicJtaTransactionManagerandWebSphereUowTransactionManager. For all other Java EE servers, the standard JtaTransactionManager is sufficient.This pure JtaTransactionManager class supports timeouts but not per-transaction isolation levels. Custom subclasses may override the
doJtaBegin(org.springframework.transaction.jta.JtaTransactionObject, org.springframework.transaction.TransactionDefinition)method for specific JTA extensions in order to provide this functionality; Spring includes a correspondingWebLogicJtaTransactionManagerclass for WebLogic Server. Such adapters for specific Java EE transaction coordinators may also expose transaction names for monitoring; with standard JTA, transaction names will simply be ignored.Consider using Spring's
tx:jta-transaction-managerconfiguration element for automatically picking the appropriate JTA platform transaction manager (automatically detecting WebLogic and WebSphere).JTA 1.1 adds the TransactionSynchronizationRegistry facility, as public Java EE 5 API in addition to the standard JTA UserTransaction handle. As of Spring 2.5, this JtaTransactionManager autodetects the TransactionSynchronizationRegistry and uses it for registering Spring-managed synchronizations when participating in an existing JTA transaction (e.g. controlled by EJB CMT). If no TransactionSynchronizationRegistry is available, then such synchronizations will be registered via the (non-EE) JTA TransactionManager handle.
This class is serializable. However, active synchronizations do not survive serialization.
- 从以下版本开始:
- 24.03.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
UserTransaction,TransactionManager,TransactionSynchronizationRegistry,setUserTransactionName(java.lang.String),setUserTransaction(javax.transaction.UserTransaction),setTransactionManagerName(java.lang.String),setTransactionManager(javax.transaction.TransactionManager),WebLogicJtaTransactionManager, 序列化表格
嵌套类概要
从类继承的嵌套类/接口 org.springframework.transaction.support.AbstractPlatformTransactionManager
AbstractPlatformTransactionManager.SuspendedResourcesHolder
字段概要
字段 修饰符和类型 字段 说明 static StringDEFAULT_TRANSACTION_SYNCHRONIZATION_REGISTRY_NAMEStandard Java EE 5 JNDI location for the JTA TransactionSynchronizationRegistry.static StringDEFAULT_USER_TRANSACTION_NAMEDefault JNDI location for the JTA UserTransaction.static String[]FALLBACK_TRANSACTION_MANAGER_NAMESFallback JNDI locations for the JTA TransactionManager.从类继承的字段 org.springframework.transaction.support.AbstractPlatformTransactionManager
logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
构造器概要
构造器 构造器 说明 JtaTransactionManager()Create a new JtaTransactionManager instance, to be configured as bean.JtaTransactionManager(TransactionManager transactionManager)Create a new JtaTransactionManager instance.JtaTransactionManager(UserTransaction userTransaction)Create a new JtaTransactionManager instance.JtaTransactionManager(UserTransaction userTransaction, TransactionManager transactionManager)Create a new JtaTransactionManager instance.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Initialize the UserTransaction as well as the TransactionManager handle.protected voidapplyIsolationLevel(JtaTransactionObject txObject, int isolationLevel)Apply the given transaction isolation level.protected voidapplyTimeout(JtaTransactionObject txObject, int timeout)Apply the given transaction timeout.protected UserTransactionbuildUserTransaction(TransactionManager transactionManager)Build a UserTransaction handle based on the given TransactionManager.protected voidcheckUserTransactionAndTransactionManager()Check the UserTransaction as well as the TransactionManager handle, assuming standard JTA requirements.TransactioncreateTransaction(String name, int timeout)Create an active Transaction object based on the given name and timeout.protected voiddoBegin(Object transaction, TransactionDefinition definition)Begin a new transaction with semantics according to the given transaction definition.protected voiddoCleanupAfterCompletion(Object transaction)Cleanup resources after transaction completion.protected voiddoCommit(DefaultTransactionStatus status)Perform an actual commit of the given transaction.protected JtaTransactionObjectdoGetJtaTransaction(UserTransaction ut)Get a JTA transaction object for the given current UserTransaction.protected ObjectdoGetTransaction()This implementation returns a JtaTransactionObject instance for the JTA UserTransaction.protected voiddoJtaBegin(JtaTransactionObject txObject, TransactionDefinition definition)Perform a JTA begin on the JTA UserTransaction or TransactionManager.protected voiddoJtaResume(JtaTransactionObject txObject, Object suspendedTransaction)Perform a JTA resume on the JTA TransactionManager.protected ObjectdoJtaSuspend(JtaTransactionObject txObject)Perform a JTA suspend on the JTA TransactionManager.protected voiddoRegisterAfterCompletionWithJtaTransaction(JtaTransactionObject txObject, List<TransactionSynchronization> synchronizations)Register a JTA synchronization on the JTA TransactionManager, for callingafterCompletionon the given Spring TransactionSynchronizations.protected voiddoResume(Object transaction, Object suspendedResources)Resume the resources of the current transaction.protected voiddoRollback(DefaultTransactionStatus status)Perform an actual rollback of the given transaction.protected voiddoSetRollbackOnly(DefaultTransactionStatus status)Set the given transaction rollback-only.protected ObjectdoSuspend(Object transaction)Suspend the resources of the current transaction.protected TransactionManagerfindTransactionManager(UserTransaction ut)Find the JTA TransactionManager through autodetection: checking whether the UserTransaction object implements the TransactionManager, and checking the fallback JNDI locations.protected TransactionSynchronizationRegistryfindTransactionSynchronizationRegistry(UserTransaction ut, TransactionManager tm)Find the JTA 1.1 TransactionSynchronizationRegistry through autodetection: checking whether the UserTransaction object or TransactionManager object implements it, and checking Java EE 5's standard JNDI location.protected UserTransactionfindUserTransaction()Find the JTA UserTransaction through a default JNDI lookup: "java:comp/UserTransaction".PropertiesgetJndiEnvironment()Return the JNDI environment to use for JNDI lookups.JndiTemplategetJndiTemplate()Return the JndiTemplate used for JNDI lookups.TransactionManagergetTransactionManager()Return the JTA TransactionManager that this transaction manager uses, if any.TransactionSynchronizationRegistrygetTransactionSynchronizationRegistry()Return the JTA 1.1 TransactionSynchronizationRegistry that this transaction manager uses, if any.UserTransactiongetUserTransaction()Return the JTA UserTransaction that this transaction manager uses.protected voidinitTransactionSynchronizationRegistry()Initialize the JTA 1.1 TransactionSynchronizationRegistry, if available.protected voidinitUserTransactionAndTransactionManager()Initialize the UserTransaction as well as the TransactionManager handle.protected booleanisExistingTransaction(Object transaction)Check if the given transaction object indicates an existing transaction (that is, a transaction which has already started).protected TransactionManagerlookupTransactionManager(String transactionManagerName)Look up the JTA TransactionManager in JNDI via the configured name.protected TransactionSynchronizationRegistrylookupTransactionSynchronizationRegistry(String registryName)Look up the JTA 1.1 TransactionSynchronizationRegistry in JNDI via the configured name.protected UserTransactionlookupUserTransaction(String userTransactionName)Look up the JTA UserTransaction in JNDI via the configured name.protected voidregisterAfterCompletionWithExistingTransaction(Object transaction, List<TransactionSynchronization> synchronizations)Register the given list of transaction synchronizations with the existing transaction.protected TransactionManagerretrieveTransactionManager()Allows subclasses to retrieve the JTA TransactionManager in a vendor-specific manner.protected TransactionSynchronizationRegistryretrieveTransactionSynchronizationRegistry()Allows subclasses to retrieve the JTA 1.1 TransactionSynchronizationRegistry in a vendor-specific manner.protected UserTransactionretrieveUserTransaction()Allows subclasses to retrieve the JTA UserTransaction in a vendor-specific manner.voidsetAllowCustomIsolationLevels(boolean allowCustomIsolationLevels)Set whether to allow custom isolation levels to be specified.voidsetAutodetectTransactionManager(boolean autodetectTransactionManager)Set whether to autodetect a JTA UserTransaction object that implements the JTA TransactionManager interface too (i.e. the JNDI location for the TransactionManager is "java:comp/UserTransaction", same as for the UserTransaction).voidsetAutodetectTransactionSynchronizationRegistry(boolean autodetectTransactionSynchronizationRegistry)Set whether to autodetect a JTA 1.1 TransactionSynchronizationRegistry object at its default JDNI location ("java:comp/TransactionSynchronizationRegistry") if the UserTransaction has also been obtained from JNDI, and also whether to fall back to checking whether the JTA UserTransaction/TransactionManager object implements the JTA TransactionSynchronizationRegistry interface too.voidsetAutodetectUserTransaction(boolean autodetectUserTransaction)Set whether to autodetect the JTA UserTransaction at its default JNDI location "java:comp/UserTransaction", as specified by Java EE.voidsetCacheUserTransaction(boolean cacheUserTransaction)Set whether to cache the JTA UserTransaction object fetched from JNDI.voidsetJndiEnvironment(Properties jndiEnvironment)Set the JNDI environment to use for JNDI lookups.voidsetJndiTemplate(JndiTemplate jndiTemplate)Set the JndiTemplate to use for JNDI lookups.voidsetTransactionManager(TransactionManager transactionManager)Set the JTA TransactionManager to use as direct reference.voidsetTransactionManagerName(String transactionManagerName)Set the JNDI name of the JTA TransactionManager.voidsetTransactionSynchronizationRegistry(TransactionSynchronizationRegistry transactionSynchronizationRegistry)Set the JTA 1.1 TransactionSynchronizationRegistry to use as direct reference.voidsetTransactionSynchronizationRegistryName(String transactionSynchronizationRegistryName)Set the JNDI name of the JTA 1.1 TransactionSynchronizationRegistry.voidsetUserTransaction(UserTransaction userTransaction)Set the JTA UserTransaction to use as direct reference.voidsetUserTransactionName(String userTransactionName)Set the JNDI name of the JTA UserTransaction.protected booleanshouldCommitOnGlobalRollbackOnly()This implementation returns "true": a JTA commit will properly handle transactions that have been marked rollback-only at a global level.booleansupportsResourceAdapterManagedTransactions()Determine whether the underlying transaction manager supports XA transactions managed by a resource adapter (i.e. without explicit XA resource enlistment).protected booleanuseSavepointForNestedTransaction()This implementation returns false to cause a further invocation of doBegin despite an already existing transaction.从类继承的方法 org.springframework.transaction.support.AbstractPlatformTransactionManager
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, suspend, triggerBeforeCommit, triggerBeforeCompletion
字段详细资料
DEFAULT_USER_TRANSACTION_NAME
public static final String DEFAULT_USER_TRANSACTION_NAME
Default JNDI location for the JTA UserTransaction. Many Java EE servers also provide support for the JTA TransactionManager interface there.
FALLBACK_TRANSACTION_MANAGER_NAMES
public static final String[] FALLBACK_TRANSACTION_MANAGER_NAMES
Fallback JNDI locations for the JTA TransactionManager. Applied if the JTA UserTransaction does not implement the JTA TransactionManager interface, provided that the "autodetectTransactionManager" flag is "true".
DEFAULT_TRANSACTION_SYNCHRONIZATION_REGISTRY_NAME
public static final String DEFAULT_TRANSACTION_SYNCHRONIZATION_REGISTRY_NAME
Standard Java EE 5 JNDI location for the JTA TransactionSynchronizationRegistry. Autodetected when available.- 另请参阅:
- 常量字段值
构造器详细资料
JtaTransactionManager
public JtaTransactionManager()
Create a new JtaTransactionManager instance, to be configured as bean. InvokeafterPropertiesSetto activate the configuration.
JtaTransactionManager
public JtaTransactionManager(UserTransaction userTransaction)
Create a new JtaTransactionManager instance.- 参数:
userTransaction- the JTA UserTransaction to use as direct reference
JtaTransactionManager
public JtaTransactionManager(UserTransaction userTransaction, TransactionManager transactionManager)
Create a new JtaTransactionManager instance.- 参数:
userTransaction- the JTA UserTransaction to use as direct referencetransactionManager- the JTA TransactionManager to use as direct reference
JtaTransactionManager
public JtaTransactionManager(TransactionManager transactionManager)
Create a new JtaTransactionManager instance.- 参数:
transactionManager- the JTA TransactionManager to use as direct reference
方法详细资料
setJndiTemplate
public void setJndiTemplate(JndiTemplate jndiTemplate)
Set the JndiTemplate to use for JNDI lookups. A default one is used if not set.
getJndiTemplate
public JndiTemplate getJndiTemplate()
Return the JndiTemplate used for JNDI lookups.
setJndiEnvironment
public void setJndiEnvironment(@Nullable Properties jndiEnvironment)
Set the JNDI environment to use for JNDI lookups. Creates a JndiTemplate with the given environment settings.
getJndiEnvironment
@Nullable public Properties getJndiEnvironment()
Return the JNDI environment to use for JNDI lookups.
setUserTransaction
public void setUserTransaction(@Nullable UserTransaction userTransaction)
Set the JTA UserTransaction to use as direct reference.Typically just used for local JTA setups; in a Java EE environment, the UserTransaction will always be fetched from JNDI.
getUserTransaction
@Nullable public UserTransaction getUserTransaction()
Return the JTA UserTransaction that this transaction manager uses.
setUserTransactionName
public void setUserTransactionName(String userTransactionName)
Set the JNDI name of the JTA UserTransaction.Note that the UserTransaction will be autodetected at the Java EE default location "java:comp/UserTransaction" if not specified explicitly.
setAutodetectUserTransaction
public void setAutodetectUserTransaction(boolean autodetectUserTransaction)
Set whether to autodetect the JTA UserTransaction at its default JNDI location "java:comp/UserTransaction", as specified by Java EE. Will proceed without UserTransaction if none found.Default is "true", autodetecting the UserTransaction unless it has been specified explicitly. Turn this flag off to allow for JtaTransactionManager operating against the TransactionManager only, despite a default UserTransaction being available.
setCacheUserTransaction
public void setCacheUserTransaction(boolean cacheUserTransaction)
Set whether to cache the JTA UserTransaction object fetched from JNDI.Default is "true": UserTransaction lookup will only happen at startup, reusing the same UserTransaction handle for all transactions of all threads. This is the most efficient choice for all application servers that provide a shared UserTransaction object (the typical case).
Turn this flag off to enforce a fresh lookup of the UserTransaction for every transaction. This is only necessary for application servers that return a new UserTransaction for every transaction, keeping state tied to the UserTransaction object itself rather than the current thread.
setTransactionManager
public void setTransactionManager(@Nullable TransactionManager transactionManager)
Set the JTA TransactionManager to use as direct reference.A TransactionManager is necessary for suspending and resuming transactions, as this not supported by the UserTransaction interface.
Note that the TransactionManager will be autodetected if the JTA UserTransaction object implements the JTA TransactionManager interface too, as well as autodetected at various well-known fallback JNDI locations.
getTransactionManager
@Nullable public TransactionManager getTransactionManager()
Return the JTA TransactionManager that this transaction manager uses, if any.
setTransactionManagerName
public void setTransactionManagerName(String transactionManagerName)
Set the JNDI name of the JTA TransactionManager.A TransactionManager is necessary for suspending and resuming transactions, as this not supported by the UserTransaction interface.
Note that the TransactionManager will be autodetected if the JTA UserTransaction object implements the JTA TransactionManager interface too, as well as autodetected at various well-known fallback JNDI locations.
setAutodetectTransactionManager
public void setAutodetectTransactionManager(boolean autodetectTransactionManager)
Set whether to autodetect a JTA UserTransaction object that implements the JTA TransactionManager interface too (i.e. the JNDI location for the TransactionManager is "java:comp/UserTransaction", same as for the UserTransaction). Also checks the fallback JNDI locations "java:comp/TransactionManager" and "java:/TransactionManager". Will proceed without TransactionManager if none found.Default is "true", autodetecting the TransactionManager unless it has been specified explicitly. Can be turned off to deliberately ignore an available TransactionManager, for example when there are known issues with suspend/resume and any attempt to use REQUIRES_NEW or NOT_SUPPORTED should fail fast.
setTransactionSynchronizationRegistry
public void setTransactionSynchronizationRegistry(@Nullable TransactionSynchronizationRegistry transactionSynchronizationRegistry)
Set the JTA 1.1 TransactionSynchronizationRegistry to use as direct reference.A TransactionSynchronizationRegistry allows for interposed registration of transaction synchronizations, as an alternative to the regular registration methods on the JTA TransactionManager API. Also, it is an official part of the Java EE 5 platform, in contrast to the JTA TransactionManager itself.
Note that the TransactionSynchronizationRegistry will be autodetected in JNDI and also from the UserTransaction/TransactionManager object if implemented there as well.
getTransactionSynchronizationRegistry
@Nullable public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
Return the JTA 1.1 TransactionSynchronizationRegistry that this transaction manager uses, if any.
setTransactionSynchronizationRegistryName
public void setTransactionSynchronizationRegistryName(String transactionSynchronizationRegistryName)
Set the JNDI name of the JTA 1.1 TransactionSynchronizationRegistry.Note that the TransactionSynchronizationRegistry will be autodetected at the Java EE 5 default location "java:comp/TransactionSynchronizationRegistry" if not specified explicitly.
setAutodetectTransactionSynchronizationRegistry
public void setAutodetectTransactionSynchronizationRegistry(boolean autodetectTransactionSynchronizationRegistry)
Set whether to autodetect a JTA 1.1 TransactionSynchronizationRegistry object at its default JDNI location ("java:comp/TransactionSynchronizationRegistry") if the UserTransaction has also been obtained from JNDI, and also whether to fall back to checking whether the JTA UserTransaction/TransactionManager object implements the JTA TransactionSynchronizationRegistry interface too.Default is "true", autodetecting the TransactionSynchronizationRegistry unless it has been specified explicitly. Can be turned off to delegate synchronization registration to the regular JTA TransactionManager API.
setAllowCustomIsolationLevels
public void setAllowCustomIsolationLevels(boolean allowCustomIsolationLevels)
Set whether to allow custom isolation levels to be specified.Default is "false", throwing an exception if a non-default isolation level is specified for a transaction. Turn this flag on if affected resource adapters check the thread-bound transaction context and apply the specified isolation levels individually (e.g. through an IsolationLevelDataSourceAdapter).
afterPropertiesSet
public void afterPropertiesSet() throws TransactionSystemException
Initialize the UserTransaction as well as the TransactionManager handle.
initUserTransactionAndTransactionManager
protected void initUserTransactionAndTransactionManager() throws TransactionSystemException
Initialize the UserTransaction as well as the TransactionManager handle.- 抛出:
TransactionSystemException- if initialization failed
checkUserTransactionAndTransactionManager
protected void checkUserTransactionAndTransactionManager() throws IllegalStateException
Check the UserTransaction as well as the TransactionManager handle, assuming standard JTA requirements.- 抛出:
IllegalStateException- if no sufficient handles are available
initTransactionSynchronizationRegistry
protected void initTransactionSynchronizationRegistry()
Initialize the JTA 1.1 TransactionSynchronizationRegistry, if available.To be called after
initUserTransactionAndTransactionManager(), since it may check the UserTransaction and TransactionManager handles.- 抛出:
TransactionSystemException- if initialization failed
buildUserTransaction
protected UserTransaction buildUserTransaction(TransactionManager transactionManager)
Build a UserTransaction handle based on the given TransactionManager.- 参数:
transactionManager- the TransactionManager- 返回:
- a corresponding UserTransaction handle
lookupUserTransaction
protected UserTransaction lookupUserTransaction(String userTransactionName) throws TransactionSystemException
Look up the JTA UserTransaction in JNDI via the configured name.Called by
afterPropertiesSetif no direct UserTransaction reference was set. Can be overridden in subclasses to provide a different UserTransaction object.- 参数:
userTransactionName- the JNDI name of the UserTransaction- 返回:
- the UserTransaction object
- 抛出:
TransactionSystemException- if the JNDI lookup failed- 另请参阅:
setJndiTemplate(org.springframework.jndi.JndiTemplate),setUserTransactionName(java.lang.String)
lookupTransactionManager
protected TransactionManager lookupTransactionManager(String transactionManagerName) throws TransactionSystemException
Look up the JTA TransactionManager in JNDI via the configured name.Called by
afterPropertiesSetif no direct TransactionManager reference was set. Can be overridden in subclasses to provide a different TransactionManager object.- 参数:
transactionManagerName- the JNDI name of the TransactionManager- 返回:
- the UserTransaction object
- 抛出:
TransactionSystemException- if the JNDI lookup failed- 另请参阅:
setJndiTemplate(org.springframework.jndi.JndiTemplate),setTransactionManagerName(java.lang.String)
lookupTransactionSynchronizationRegistry
protected TransactionSynchronizationRegistry lookupTransactionSynchronizationRegistry(String registryName) throws TransactionSystemException
Look up the JTA 1.1 TransactionSynchronizationRegistry in JNDI via the configured name.Can be overridden in subclasses to provide a different TransactionManager object.
- 参数:
registryName- the JNDI name of the TransactionSynchronizationRegistry- 返回:
- the TransactionSynchronizationRegistry object
- 抛出:
TransactionSystemException- if the JNDI lookup failed- 另请参阅:
setJndiTemplate(org.springframework.jndi.JndiTemplate),setTransactionSynchronizationRegistryName(java.lang.String)
retrieveUserTransaction
@Nullable protected UserTransaction retrieveUserTransaction() throws TransactionSystemException
Allows subclasses to retrieve the JTA UserTransaction in a vendor-specific manner. Only called if no "userTransaction" or "userTransactionName" specified.The default implementation simply returns
null.- 返回:
- the JTA UserTransaction handle to use, or
nullif none found - 抛出:
TransactionSystemException- in case of errors- 另请参阅:
setUserTransaction(javax.transaction.UserTransaction),setUserTransactionName(java.lang.String)
retrieveTransactionManager
@Nullable protected TransactionManager retrieveTransactionManager() throws TransactionSystemException
Allows subclasses to retrieve the JTA TransactionManager in a vendor-specific manner. Only called if no "transactionManager" or "transactionManagerName" specified.The default implementation simply returns
null.- 返回:
- the JTA TransactionManager handle to use, or
nullif none found - 抛出:
TransactionSystemException- in case of errors- 另请参阅:
setTransactionManager(javax.transaction.TransactionManager),setTransactionManagerName(java.lang.String)
retrieveTransactionSynchronizationRegistry
@Nullable protected TransactionSynchronizationRegistry retrieveTransactionSynchronizationRegistry() throws TransactionSystemException
Allows subclasses to retrieve the JTA 1.1 TransactionSynchronizationRegistry in a vendor-specific manner.The default implementation simply returns
null.- 返回:
- the JTA TransactionSynchronizationRegistry handle to use, or
nullif none found - 抛出:
TransactionSystemException- in case of errors
findUserTransaction
@Nullable protected UserTransaction findUserTransaction()
Find the JTA UserTransaction through a default JNDI lookup: "java:comp/UserTransaction".- 返回:
- the JTA UserTransaction reference, or
nullif not found - 另请参阅:
DEFAULT_USER_TRANSACTION_NAME
findTransactionManager
@Nullable protected TransactionManager findTransactionManager(@Nullable UserTransaction ut)
Find the JTA TransactionManager through autodetection: checking whether the UserTransaction object implements the TransactionManager, and checking the fallback JNDI locations.- 参数:
ut- the JTA UserTransaction object- 返回:
- the JTA TransactionManager reference, or
nullif not found - 另请参阅:
FALLBACK_TRANSACTION_MANAGER_NAMES
findTransactionSynchronizationRegistry
@Nullable protected TransactionSynchronizationRegistry findTransactionSynchronizationRegistry(@Nullable UserTransaction ut, @Nullable TransactionManager tm) throws TransactionSystemException
Find the JTA 1.1 TransactionSynchronizationRegistry through autodetection: checking whether the UserTransaction object or TransactionManager object implements it, and checking Java EE 5's standard JNDI location.The default implementation simply returns
null.- 参数:
ut- the JTA UserTransaction objecttm- the JTA TransactionManager object- 返回:
- the JTA TransactionSynchronizationRegistry handle to use, or
nullif none found - 抛出:
TransactionSystemException- in case of errors
doGetTransaction
protected Object doGetTransaction()
This implementation returns a JtaTransactionObject instance for the JTA UserTransaction.The UserTransaction object will either be looked up freshly for the current transaction, or the cached one looked up at startup will be used. The latter is the default: Most application servers use a shared singleton UserTransaction that can be cached. Turn off the "cacheUserTransaction" flag to enforce a fresh lookup for every transaction.
- 指定者:
doGetTransaction在类中AbstractPlatformTransactionManager- 返回:
- the current transaction object
- 另请参阅:
setCacheUserTransaction(boolean)
doGetJtaTransaction
protected JtaTransactionObject doGetJtaTransaction(UserTransaction ut)
Get a JTA transaction object for the given current UserTransaction.Subclasses can override this to provide a JtaTransactionObject subclass, for example holding some additional JTA handle needed.
- 参数:
ut- the UserTransaction handle to use for the current transaction- 返回:
- the JtaTransactionObject holding the UserTransaction
isExistingTransaction
protected boolean isExistingTransaction(Object transaction)
从类复制的说明:AbstractPlatformTransactionManagerCheck if the given transaction object indicates an existing transaction (that is, a transaction which has already started).The result will be evaluated according to the specified propagation behavior for the new transaction. An existing transaction might get suspended (in case of PROPAGATION_REQUIRES_NEW), or the new transaction might participate in the existing one (in case of PROPAGATION_REQUIRED).
The default implementation returns
false, assuming that participating in existing transactions is generally not supported. Subclasses are of course encouraged to provide such support.- 覆盖:
isExistingTransaction在类中AbstractPlatformTransactionManager- 参数:
transaction- the transaction object returned by doGetTransaction- 返回:
- if there is an existing transaction
- 另请参阅:
AbstractPlatformTransactionManager.doGetTransaction()
useSavepointForNestedTransaction
protected boolean useSavepointForNestedTransaction()
This implementation returns false to cause a further invocation of doBegin despite an already existing transaction.JTA implementations might support nested transactions via further
UserTransaction.begin()invocations, but never support savepoints.
doBegin
protected void doBegin(Object transaction, TransactionDefinition definition)
从类复制的说明:AbstractPlatformTransactionManagerBegin a new transaction with semantics according to the given transaction definition. Does not have to care about applying the propagation behavior, as this has already been handled by this abstract manager.This method gets called when the transaction manager has decided to actually start a new transaction. Either there wasn't any transaction before, or the previous transaction has been suspended.
A special scenario is a nested transaction without savepoint: If
useSavepointForNestedTransaction()returns "false", this method will be called to start a nested transaction when necessary. In such a context, there will be an active transaction: The implementation of this method has to detect this and start an appropriate nested transaction.- 指定者:
doBegin在类中AbstractPlatformTransactionManager- 参数:
transaction- the transaction object returned bydoGetTransactiondefinition- a TransactionDefinition instance, describing propagation behavior, isolation level, read-only flag, timeout, and transaction name
doJtaBegin
protected void doJtaBegin(JtaTransactionObject txObject, TransactionDefinition definition) throws NotSupportedException, SystemException
Perform a JTA begin on the JTA UserTransaction or TransactionManager.This implementation only supports standard JTA functionality: that is, no per-transaction isolation levels and no transaction names. Can be overridden in subclasses, for specific JTA implementations.
Calls
applyIsolationLevelandapplyTimeoutbefore invoking the UserTransaction'sbeginmethod.- 参数:
txObject- the JtaTransactionObject containing the UserTransactiondefinition- the TransactionDefinition instance, describing propagation behavior, isolation level, read-only flag, timeout, and transaction name- 抛出:
NotSupportedException- if thrown by JTA methodsSystemException- if thrown by JTA methods- 另请参阅:
getUserTransaction(),getTransactionManager(),applyIsolationLevel(org.springframework.transaction.jta.JtaTransactionObject, int),applyTimeout(org.springframework.transaction.jta.JtaTransactionObject, int),JtaTransactionObject.getUserTransaction(),UserTransaction.setTransactionTimeout(int),UserTransaction.begin()
applyIsolationLevel
protected void applyIsolationLevel(JtaTransactionObject txObject, int isolationLevel) throws InvalidIsolationLevelException, SystemException
Apply the given transaction isolation level. The default implementation will throw an exception for any level other than ISOLATION_DEFAULT.To be overridden in subclasses for specific JTA implementations, as alternative to overriding the full
doJtaBegin(org.springframework.transaction.jta.JtaTransactionObject, org.springframework.transaction.TransactionDefinition)method.- 参数:
txObject- the JtaTransactionObject containing the UserTransactionisolationLevel- isolation level taken from transaction definition- 抛出:
InvalidIsolationLevelException- if the given isolation level cannot be appliedSystemException- if thrown by the JTA implementation- 另请参阅:
doJtaBegin(org.springframework.transaction.jta.JtaTransactionObject, org.springframework.transaction.TransactionDefinition),JtaTransactionObject.getUserTransaction(),getTransactionManager()
applyTimeout
protected void applyTimeout(JtaTransactionObject txObject, int timeout) throws SystemException
Apply the given transaction timeout. The default implementation will callUserTransaction.setTransactionTimeoutfor a non-default timeout value.- 参数:
txObject- the JtaTransactionObject containing the UserTransactiontimeout- the timeout value taken from transaction definition- 抛出:
SystemException- if thrown by the JTA implementation- 另请参阅:
doJtaBegin(org.springframework.transaction.jta.JtaTransactionObject, org.springframework.transaction.TransactionDefinition),JtaTransactionObject.getUserTransaction(),UserTransaction.setTransactionTimeout(int)
doSuspend
protected Object doSuspend(Object transaction)
从类复制的说明:AbstractPlatformTransactionManagerSuspend the resources of the current transaction. Transaction synchronization will already have been suspended.The default implementation throws a TransactionSuspensionNotSupportedException, assuming that transaction suspension is generally not supported.
- 覆盖:
doSuspend在类中AbstractPlatformTransactionManager- 参数:
transaction- the transaction object returned bydoGetTransaction- 返回:
- an object that holds suspended resources (will be kept unexamined for passing it into doResume)
- 另请参阅:
AbstractPlatformTransactionManager.doResume(java.lang.Object, java.lang.Object)
doJtaSuspend
protected Object doJtaSuspend(JtaTransactionObject txObject) throws SystemException
Perform a JTA suspend on the JTA TransactionManager.Can be overridden in subclasses, for specific JTA implementations.
- 参数:
txObject- the JtaTransactionObject containing the UserTransaction- 返回:
- the suspended JTA Transaction object
- 抛出:
SystemException- if thrown by JTA methods- 另请参阅:
getTransactionManager(),TransactionManager.suspend()
doResume
protected void doResume(@Nullable Object transaction, Object suspendedResources)
从类复制的说明:AbstractPlatformTransactionManagerResume the resources of the current transaction. Transaction synchronization will be resumed afterwards.The default implementation throws a TransactionSuspensionNotSupportedException, assuming that transaction suspension is generally not supported.
- 覆盖:
doResume在类中AbstractPlatformTransactionManager- 参数:
transaction- the transaction object returned bydoGetTransactionsuspendedResources- the object that holds suspended resources, as returned by doSuspend- 另请参阅:
AbstractPlatformTransactionManager.doSuspend(java.lang.Object)
doJtaResume
protected void doJtaResume(@Nullable JtaTransactionObject txObject, Object suspendedTransaction) throws InvalidTransactionException, SystemException
Perform a JTA resume on the JTA TransactionManager.Can be overridden in subclasses, for specific JTA implementations.
- 参数:
txObject- the JtaTransactionObject containing the UserTransactionsuspendedTransaction- the suspended JTA Transaction object- 抛出:
InvalidTransactionException- if thrown by JTA methodsSystemException- if thrown by JTA methods- 另请参阅:
getTransactionManager(),TransactionManager.resume(javax.transaction.Transaction)
shouldCommitOnGlobalRollbackOnly
protected boolean shouldCommitOnGlobalRollbackOnly()
This implementation returns "true": a JTA commit will properly handle transactions that have been marked rollback-only at a global level.- 覆盖:
shouldCommitOnGlobalRollbackOnly在类中AbstractPlatformTransactionManager- 另请参阅:
AbstractPlatformTransactionManager.doCommit(org.springframework.transaction.support.DefaultTransactionStatus),DefaultTransactionStatus.isGlobalRollbackOnly(),AbstractTransactionStatus.isLocalRollbackOnly(),TransactionExecution.setRollbackOnly(),UnexpectedRollbackException,UserTransaction.commit(),RollbackException
doCommit
protected void doCommit(DefaultTransactionStatus status)
从类复制的说明:AbstractPlatformTransactionManagerPerform an actual commit of the given transaction.An implementation does not need to check the "new transaction" flag or the rollback-only flag; this will already have been handled before. Usually, a straight commit will be performed on the transaction object contained in the passed-in status.
- 指定者:
doCommit在类中AbstractPlatformTransactionManager- 参数:
status- the status representation of the transaction- 另请参阅:
DefaultTransactionStatus.getTransaction()
doRollback
protected void doRollback(DefaultTransactionStatus status)
从类复制的说明:AbstractPlatformTransactionManagerPerform an actual rollback of the given transaction.An implementation does not need to check the "new transaction" flag; this will already have been handled before. Usually, a straight rollback will be performed on the transaction object contained in the passed-in status.
- 指定者:
doRollback在类中AbstractPlatformTransactionManager- 参数:
status- the status representation of the transaction- 另请参阅:
DefaultTransactionStatus.getTransaction()
doSetRollbackOnly
protected void doSetRollbackOnly(DefaultTransactionStatus status)
从类复制的说明:AbstractPlatformTransactionManagerSet the given transaction rollback-only. Only called on rollback if the current transaction participates in an existing one.The default implementation throws an IllegalTransactionStateException, assuming that participating in existing transactions is generally not supported. Subclasses are of course encouraged to provide such support.
- 覆盖:
doSetRollbackOnly在类中AbstractPlatformTransactionManager- 参数:
status- the status representation of the transaction
registerAfterCompletionWithExistingTransaction
protected void registerAfterCompletionWithExistingTransaction(Object transaction, List<TransactionSynchronization> synchronizations)
从类复制的说明:AbstractPlatformTransactionManagerRegister the given list of transaction synchronizations with the existing transaction.Invoked when the control of the Spring transaction manager and thus all Spring transaction synchronizations end, without the transaction being completed yet. This is for example the case when participating in an existing JTA or EJB CMT transaction.
The default implementation simply invokes the
afterCompletionmethods immediately, passing in "STATUS_UNKNOWN". This is the best we can do if there's no chance to determine the actual outcome of the outer transaction.- 覆盖:
registerAfterCompletionWithExistingTransaction在类中AbstractPlatformTransactionManager- 参数:
transaction- the transaction object returned bydoGetTransactionsynchronizations- a List of TransactionSynchronization objects- 另请参阅:
AbstractPlatformTransactionManager.invokeAfterCompletion(java.util.List, int),TransactionSynchronization.afterCompletion(int),TransactionSynchronization.STATUS_UNKNOWN
doRegisterAfterCompletionWithJtaTransaction
protected void doRegisterAfterCompletionWithJtaTransaction(JtaTransactionObject txObject, List<TransactionSynchronization> synchronizations) throws RollbackException, SystemException
Register a JTA synchronization on the JTA TransactionManager, for callingafterCompletionon the given Spring TransactionSynchronizations.The default implementation registers the synchronizations on the JTA 1.1 TransactionSynchronizationRegistry, if available, or on the JTA TransactionManager's current Transaction - again, if available. If none of the two is available, a warning will be logged.
Can be overridden in subclasses, for specific JTA implementations.
- 参数:
txObject- the current transaction objectsynchronizations- a List of TransactionSynchronization objects- 抛出:
RollbackException- if thrown by JTA methodsSystemException- if thrown by JTA methods- 另请参阅:
getTransactionManager(),Transaction.registerSynchronization(javax.transaction.Synchronization),TransactionSynchronizationRegistry.registerInterposedSynchronization(javax.transaction.Synchronization)
doCleanupAfterCompletion
protected void doCleanupAfterCompletion(Object transaction)
从类复制的说明:AbstractPlatformTransactionManagerCleanup resources after transaction completion.Called after
doCommitanddoRollbackexecution, on any outcome. The default implementation does nothing.Should not throw any exceptions but just issue warnings on errors.
- 覆盖:
doCleanupAfterCompletion在类中AbstractPlatformTransactionManager- 参数:
transaction- the transaction object returned bydoGetTransaction
createTransaction
public Transaction createTransaction(@Nullable String name, int timeout) throws NotSupportedException, SystemException
从接口复制的说明:TransactionFactoryCreate an active Transaction object based on the given name and timeout.- 指定者:
createTransaction在接口中TransactionFactory- 参数:
name- the transaction name (may benull)timeout- the transaction timeout (may be -1 for the default timeout)- 返回:
- the active Transaction object (never
null) - 抛出:
NotSupportedException- if the transaction manager does not support a transaction of the specified typeSystemException- if the transaction manager failed to create the transaction
supportsResourceAdapterManagedTransactions
public boolean supportsResourceAdapterManagedTransactions()
从接口复制的说明:TransactionFactoryDetermine whether the underlying transaction manager supports XA transactions managed by a resource adapter (i.e. without explicit XA resource enlistment).Typically
false. Checked byAbstractMessageEndpointFactoryin order to differentiate between invalid configuration and valid ResourceAdapter-managed transactions.