JCA listener containers delegate to wrapped Transaction handle (for Geronimo compatibility; SPR-6991)
This commit is contained in:
parent
c13e5f9f5b
commit
4e7752c9ba
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -55,7 +55,7 @@ import org.springframework.util.StringUtils;
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.transaction.PlatformTransactionManager} implementation
|
* {@link org.springframework.transaction.PlatformTransactionManager} implementation
|
||||||
* for JTA, delegating to a backend JTA provider. This is typically used to delegate
|
* for JTA, delegating to a backend JTA provider. This is typically used to delegate
|
||||||
* to a J2EE server's transaction coordinator, but may also be configured with a
|
* to a Java EE server's transaction coordinator, but may also be configured with a
|
||||||
* local JTA provider which is embedded within the application.
|
* local JTA provider which is embedded within the application.
|
||||||
*
|
*
|
||||||
* <p>This transaction manager is appropriate for handling distributed transactions,
|
* <p>This transaction manager is appropriate for handling distributed transactions,
|
||||||
|
|
@ -66,8 +66,8 @@ import org.springframework.util.StringUtils;
|
||||||
* HibernateTransactionManager is appropriate, for example.
|
* HibernateTransactionManager is appropriate, for example.
|
||||||
*
|
*
|
||||||
* <p><b>For typical JTA transactions (REQUIRED, SUPPORTS, MANDATORY, NEVER), a plain
|
* <p><b>For typical JTA transactions (REQUIRED, SUPPORTS, MANDATORY, NEVER), a plain
|
||||||
* JtaTransactionManager definition is all you need, portable across all J2EE servers.</b>
|
* JtaTransactionManager definition is all you need, portable across all Java EE servers.</b>
|
||||||
* This corresponds to the functionality of the JTA UserTransaction, for which J2EE
|
* 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
|
* 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.
|
* configure a server-specific TransactionManager lookup for this kind of JTA usage.
|
||||||
*
|
*
|
||||||
|
|
@ -76,20 +76,20 @@ import org.springframework.util.StringUtils;
|
||||||
* autodetected by JtaTransactionManager, provided that the "autodetectTransactionManager"
|
* autodetected by JtaTransactionManager, provided that the "autodetectTransactionManager"
|
||||||
* flag is set to "true" (which it is by default).
|
* flag is set to "true" (which it is by default).
|
||||||
*
|
*
|
||||||
* <p>Note: Support for the JTA TransactionManager interface is not required by J2EE.
|
* <p>Note: Support for the JTA TransactionManager interface is not required by Java EE.
|
||||||
* Almost all J2EE servers expose it, but do so as extension to J2EE. There might be some
|
* 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.
|
* issues with compatibility, despite the TransactionManager interface being part of JTA.
|
||||||
* As a consequence, Spring provides various vendor-specific PlatformTransactionManagers,
|
* As a consequence, Spring provides various vendor-specific PlatformTransactionManagers,
|
||||||
* which are recommended to be used if appropriate: {@link WebLogicJtaTransactionManager},
|
* which are recommended to be used if appropriate: {@link WebLogicJtaTransactionManager},
|
||||||
* {@link WebSphereUowTransactionManager} and {@link OC4JJtaTransactionManager}.
|
* {@link WebSphereUowTransactionManager} and {@link OC4JJtaTransactionManager}.
|
||||||
* For all other J2EE servers, the standard JtaTransactionManager is sufficient.
|
* For all other Java EE servers, the standard JtaTransactionManager is sufficient.
|
||||||
*
|
*
|
||||||
* <p>This pure JtaTransactionManager class supports timeouts but not per-transaction
|
* <p>This pure JtaTransactionManager class supports timeouts but not per-transaction
|
||||||
* isolation levels. Custom subclasses may override the {@link #doJtaBegin} method for
|
* isolation levels. Custom subclasses may override the {@link #doJtaBegin} method for
|
||||||
* specific JTA extensions in order to provide this functionality; Spring includes
|
* specific JTA extensions in order to provide this functionality; Spring includes
|
||||||
* corresponding {@link WebLogicJtaTransactionManager} and {@link OC4JJtaTransactionManager}
|
* corresponding {@link WebLogicJtaTransactionManager} and {@link OC4JJtaTransactionManager}
|
||||||
* classes, for BEA's WebLogic Server and Oracle's OC4J, respectively. Such adapters
|
* classes, for BEA's WebLogic Server and Oracle's OC4J, respectively. Such adapters
|
||||||
* for specific J2EE transaction coordinators may also expose transaction names for
|
* for specific Java EE transaction coordinators may also expose transaction names for
|
||||||
* monitoring; with standard JTA, transaction names will simply be ignored.
|
* monitoring; with standard JTA, transaction names will simply be ignored.
|
||||||
*
|
*
|
||||||
* <p><b>Consider using Spring's <code>tx:jta-transaction-manager</code> configuration
|
* <p><b>Consider using Spring's <code>tx:jta-transaction-manager</code> configuration
|
||||||
|
|
@ -102,7 +102,7 @@ import org.springframework.util.StringUtils;
|
||||||
* it for registering Spring-managed synchronizations when participating in an existing
|
* it for registering Spring-managed synchronizations when participating in an existing
|
||||||
* JTA transaction (e.g. controlled by EJB CMT). If no TransactionSynchronizationRegistry
|
* JTA transaction (e.g. controlled by EJB CMT). If no TransactionSynchronizationRegistry
|
||||||
* is available (or the JTA 1.1 API isn't available), then such synchronizations
|
* is available (or the JTA 1.1 API isn't available), then such synchronizations
|
||||||
* will be registered via the (non-J2EE) JTA TransactionManager handle.
|
* will be registered via the (non-EE) JTA TransactionManager handle.
|
||||||
*
|
*
|
||||||
* <p>This class is serializable. However, active synchronizations do not survive serialization.
|
* <p>This class is serializable. However, active synchronizations do not survive serialization.
|
||||||
*
|
*
|
||||||
|
|
@ -121,7 +121,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
implements TransactionFactory, InitializingBean, Serializable {
|
implements TransactionFactory, InitializingBean, Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default JNDI location for the JTA UserTransaction. Many J2EE servers
|
* Default JNDI location for the JTA UserTransaction. Many Java EE servers
|
||||||
* also provide support for the JTA TransactionManager interface there.
|
* also provide support for the JTA TransactionManager interface there.
|
||||||
* @see #setUserTransactionName
|
* @see #setUserTransactionName
|
||||||
* @see #setAutodetectTransactionManager
|
* @see #setAutodetectTransactionManager
|
||||||
|
|
@ -271,7 +271,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the JTA UserTransaction to use as direct reference.
|
* Set the JTA UserTransaction to use as direct reference.
|
||||||
* <p>Typically just used for local JTA setups; in a J2EE environment,
|
* <p>Typically just used for local JTA setups; in a Java EE environment,
|
||||||
* the UserTransaction will always be fetched from JNDI.
|
* the UserTransaction will always be fetched from JNDI.
|
||||||
* @see #setUserTransactionName
|
* @see #setUserTransactionName
|
||||||
* @see #setAutodetectUserTransaction
|
* @see #setAutodetectUserTransaction
|
||||||
|
|
@ -289,8 +289,8 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the JNDI name of the JTA UserTransaction.
|
* Set the JNDI name of the JTA UserTransaction.
|
||||||
* <p>Note that the UserTransaction will be autodetected at the J2EE default
|
* <p>Note that the UserTransaction will be autodetected at the Java EE
|
||||||
* location "java:comp/UserTransaction" if not specified explicitly.
|
* default location "java:comp/UserTransaction" if not specified explicitly.
|
||||||
* @see #DEFAULT_USER_TRANSACTION_NAME
|
* @see #DEFAULT_USER_TRANSACTION_NAME
|
||||||
* @see #setUserTransaction
|
* @see #setUserTransaction
|
||||||
* @see #setAutodetectUserTransaction
|
* @see #setAutodetectUserTransaction
|
||||||
|
|
@ -301,7 +301,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether to autodetect the JTA UserTransaction at its default
|
* Set whether to autodetect the JTA UserTransaction at its default
|
||||||
* JNDI location "java:comp/UserTransaction", as specified by J2EE.
|
* JNDI location "java:comp/UserTransaction", as specified by Java EE.
|
||||||
* Will proceed without UserTransaction if none found.
|
* Will proceed without UserTransaction if none found.
|
||||||
* <p>Default is "true", autodetecting the UserTransaction unless
|
* <p>Default is "true", autodetecting the UserTransaction unless
|
||||||
* it has been specified explicitly. Turn this flag off to allow for
|
* it has been specified explicitly. Turn this flag off to allow for
|
||||||
|
|
@ -1169,7 +1169,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
tm.setTransactionTimeout(timeout);
|
tm.setTransactionTimeout(timeout);
|
||||||
}
|
}
|
||||||
tm.begin();
|
tm.begin();
|
||||||
return tm.getTransaction();
|
return new ManagedTransactionAdapter(tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsResourceAdapterManagedTransactions() {
|
public boolean supportsResourceAdapterManagedTransactions() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2010 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.transaction.jta;
|
||||||
|
|
||||||
|
import javax.transaction.HeuristicMixedException;
|
||||||
|
import javax.transaction.HeuristicRollbackException;
|
||||||
|
import javax.transaction.RollbackException;
|
||||||
|
import javax.transaction.Synchronization;
|
||||||
|
import javax.transaction.SystemException;
|
||||||
|
import javax.transaction.Transaction;
|
||||||
|
import javax.transaction.TransactionManager;
|
||||||
|
import javax.transaction.xa.XAResource;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapter for a managed JTA Transaction handle, taking a JTA
|
||||||
|
* {@link javax.transaction.TransactionManager} reference and creating
|
||||||
|
* a JTA {@link javax.transaction.Transaction} handle for it.
|
||||||
|
*
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @since 3.0.2
|
||||||
|
*/
|
||||||
|
public class ManagedTransactionAdapter implements Transaction {
|
||||||
|
|
||||||
|
private final TransactionManager transactionManager;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ManagedTransactionAdapter for the given TransactionManager.
|
||||||
|
* @param transactionManager the JTA TransactionManager to wrap
|
||||||
|
*/
|
||||||
|
public ManagedTransactionAdapter(TransactionManager transactionManager) throws SystemException {
|
||||||
|
Assert.notNull(transactionManager, "TransactionManager must not be null");
|
||||||
|
this.transactionManager = transactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the JTA TransactionManager that this adapter delegates to.
|
||||||
|
*/
|
||||||
|
public final TransactionManager getTransactionManager() {
|
||||||
|
return this.transactionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
|
||||||
|
SecurityException, SystemException {
|
||||||
|
this.transactionManager.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rollback() throws SystemException {
|
||||||
|
this.transactionManager.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRollbackOnly() throws SystemException {
|
||||||
|
this.transactionManager.setRollbackOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() throws SystemException {
|
||||||
|
return this.transactionManager.getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enlistResource(XAResource xaRes) throws RollbackException, SystemException {
|
||||||
|
return this.transactionManager.getTransaction().enlistResource(xaRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean delistResource(XAResource xaRes, int flag) throws SystemException {
|
||||||
|
return this.transactionManager.getTransaction().delistResource(xaRes, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSynchronization(Synchronization sync) throws RollbackException, SystemException {
|
||||||
|
this.transactionManager.getTransaction().registerSynchronization(sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -18,7 +18,6 @@ package org.springframework.transaction.jta;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import javax.transaction.NotSupportedException;
|
import javax.transaction.NotSupportedException;
|
||||||
import javax.transaction.SystemException;
|
import javax.transaction.SystemException;
|
||||||
import javax.transaction.Transaction;
|
import javax.transaction.Transaction;
|
||||||
|
|
@ -241,7 +240,7 @@ public class OC4JJtaTransactionManager extends JtaTransactionManager {
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new SystemException("Could not invoke OC4J's UserTransaction.begin(String) method: " + ex);
|
throw new SystemException("Could not invoke OC4J's UserTransaction.begin(String) method: " + ex);
|
||||||
}
|
}
|
||||||
return getTransactionManager().getTransaction();
|
return new ManagedTransactionAdapter(getTransactionManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -55,7 +55,7 @@ public class SimpleTransactionFactory implements TransactionFactory {
|
||||||
this.transactionManager.setTransactionTimeout(timeout);
|
this.transactionManager.setTransactionTimeout(timeout);
|
||||||
}
|
}
|
||||||
this.transactionManager.begin();
|
this.transactionManager.begin();
|
||||||
return this.transactionManager.getTransaction();
|
return new ManagedTransactionAdapter(this.transactionManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsResourceAdapterManagedTransactions() {
|
public boolean supportsResourceAdapterManagedTransactions() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -65,31 +65,30 @@ public class UserTransactionAdapter implements UserTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setTransactionTimeout(int timeout) throws SystemException {
|
||||||
|
this.transactionManager.setTransactionTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
public void begin() throws NotSupportedException, SystemException {
|
public void begin() throws NotSupportedException, SystemException {
|
||||||
this.transactionManager.begin();
|
this.transactionManager.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commit()
|
public void commit()
|
||||||
throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
|
throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
|
||||||
SecurityException, IllegalStateException, SystemException {
|
SecurityException, SystemException {
|
||||||
|
|
||||||
this.transactionManager.commit();
|
this.transactionManager.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void rollback() throws SecurityException, SystemException {
|
||||||
|
this.transactionManager.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRollbackOnly() throws SystemException {
|
||||||
|
this.transactionManager.setRollbackOnly();
|
||||||
|
}
|
||||||
|
|
||||||
public int getStatus() throws SystemException {
|
public int getStatus() throws SystemException {
|
||||||
return this.transactionManager.getStatus();
|
return this.transactionManager.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rollback() throws IllegalStateException, SecurityException, SystemException {
|
|
||||||
this.transactionManager.rollback();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRollbackOnly() throws IllegalStateException, SystemException {
|
|
||||||
this.transactionManager.setRollbackOnly();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionTimeout(int timeout) throws SystemException {
|
|
||||||
this.transactionManager.setTransactionTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -30,7 +30,7 @@ import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.TransactionSystemException;
|
import org.springframework.transaction.TransactionSystemException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special {@link JtaTransactionManager} variant for BEA WebLogic (8.1 and higher).
|
* Special {@link JtaTransactionManager} variant for BEA WebLogic (9.0 and higher).
|
||||||
* Supports the full power of Spring's transaction definitions on WebLogic's
|
* Supports the full power of Spring's transaction definitions on WebLogic's
|
||||||
* transaction coordinator, <i>beyond standard JTA</i>: transaction names,
|
* transaction coordinator, <i>beyond standard JTA</i>: transaction names,
|
||||||
* per-transaction isolation levels, and proper resuming of transactions in all cases.
|
* per-transaction isolation levels, and proper resuming of transactions in all cases.
|
||||||
|
|
@ -325,7 +325,7 @@ public class WebLogicJtaTransactionManager extends JtaTransactionManager {
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new SystemException("Could not invoke WebLogic's UserTransaction.begin() method: " + ex);
|
throw new SystemException("Could not invoke WebLogic's UserTransaction.begin() method: " + ex);
|
||||||
}
|
}
|
||||||
return getTransactionManager().getTransaction();
|
return new ManagedTransactionAdapter(getTransactionManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue