diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java index 36f496b113e..2efda302864 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/JtaTransactionManager.java @@ -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"); * 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 * 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. * *

This transaction manager is appropriate for handling distributed transactions, @@ -66,8 +66,8 @@ import org.springframework.util.StringUtils; * HibernateTransactionManager is appropriate, for example. * *

For typical JTA transactions (REQUIRED, SUPPORTS, MANDATORY, NEVER), a plain - * JtaTransactionManager definition is all you need, portable across all J2EE servers. - * This corresponds to the functionality of the JTA UserTransaction, for which J2EE + * 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. * @@ -76,20 +76,20 @@ import org.springframework.util.StringUtils; * 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 J2EE. - * Almost all J2EE servers expose it, but do so as extension to J2EE. There might be some + *

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: {@link WebLogicJtaTransactionManager}, * {@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. * *

This pure JtaTransactionManager class supports timeouts but not per-transaction * isolation levels. Custom subclasses may override the {@link #doJtaBegin} method for * specific JTA extensions in order to provide this functionality; Spring includes * corresponding {@link WebLogicJtaTransactionManager} and {@link OC4JJtaTransactionManager} * 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. * *

Consider using Spring's tx:jta-transaction-manager configuration @@ -102,7 +102,7 @@ import org.springframework.util.StringUtils; * it for registering Spring-managed synchronizations when participating in an existing * 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 - * will be registered via the (non-J2EE) JTA TransactionManager handle. + * will be registered via the (non-EE) JTA TransactionManager handle. * *

This class is serializable. However, active synchronizations do not survive serialization. * @@ -121,7 +121,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager 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. * @see #setUserTransactionName * @see #setAutodetectTransactionManager @@ -271,7 +271,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Set the JTA UserTransaction to use as direct reference. - *

Typically just used for local JTA setups; in a J2EE environment, + *

Typically just used for local JTA setups; in a Java EE environment, * the UserTransaction will always be fetched from JNDI. * @see #setUserTransactionName * @see #setAutodetectUserTransaction @@ -289,8 +289,8 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Set the JNDI name of the JTA UserTransaction. - *

Note that the UserTransaction will be autodetected at the J2EE default - * location "java:comp/UserTransaction" if not specified explicitly. + *

Note that the UserTransaction will be autodetected at the Java EE + * default location "java:comp/UserTransaction" if not specified explicitly. * @see #DEFAULT_USER_TRANSACTION_NAME * @see #setUserTransaction * @see #setAutodetectUserTransaction @@ -301,7 +301,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * 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. *

Default is "true", autodetecting the UserTransaction unless * 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.begin(); - return tm.getTransaction(); + return new ManagedTransactionAdapter(tm); } public boolean supportsResourceAdapterManagedTransactions() { diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/ManagedTransactionAdapter.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/ManagedTransactionAdapter.java new file mode 100644 index 00000000000..ee9938c7029 --- /dev/null +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/ManagedTransactionAdapter.java @@ -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); + } + +} diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/OC4JJtaTransactionManager.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/OC4JJtaTransactionManager.java index 8abaece2391..7f45e3fb8db 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/OC4JJtaTransactionManager.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/OC4JJtaTransactionManager.java @@ -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"); * 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.Method; - import javax.transaction.NotSupportedException; import javax.transaction.SystemException; import javax.transaction.Transaction; @@ -241,7 +240,7 @@ public class OC4JJtaTransactionManager extends JtaTransactionManager { catch (Exception ex) { throw new SystemException("Could not invoke OC4J's UserTransaction.begin(String) method: " + ex); } - return getTransactionManager().getTransaction(); + return new ManagedTransactionAdapter(getTransactionManager()); } else { diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java index 400a3a5a04d..679e15060b6 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java @@ -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"); * 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.begin(); - return this.transactionManager.getTransaction(); + return new ManagedTransactionAdapter(this.transactionManager); } public boolean supportsResourceAdapterManagedTransactions() { diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/UserTransactionAdapter.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/UserTransactionAdapter.java index 8c18b89395e..9472928761a 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/UserTransactionAdapter.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/UserTransactionAdapter.java @@ -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"); * 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 { this.transactionManager.begin(); } public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, - SecurityException, IllegalStateException, SystemException { - + SecurityException, SystemException { 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 { 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); - } - } diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebLogicJtaTransactionManager.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebLogicJtaTransactionManager.java index 1fe2d4e1d7b..b9f994d27aa 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebLogicJtaTransactionManager.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebLogicJtaTransactionManager.java @@ -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"); * 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; /** - * 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 * transaction coordinator, beyond standard JTA: transaction names, * per-transaction isolation levels, and proper resuming of transactions in all cases. @@ -325,7 +325,7 @@ public class WebLogicJtaTransactionManager extends JtaTransactionManager { catch (Exception ex) { throw new SystemException("Could not invoke WebLogic's UserTransaction.begin() method: " + ex); } - return getTransactionManager().getTransaction(); + return new ManagedTransactionAdapter(getTransactionManager()); } else {