From c09d4962d0e8b0bdbbe5b7ea6cab9c30eb434106 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 9 Feb 2009 15:36:20 +0000 Subject: [PATCH] support for WebSphere's ResourceAdapter-managed transactions git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@605 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../AbstractMessageEndpointFactory.java | 15 ++++++++------- .../transaction/jta/JtaTransactionManager.java | 7 +++++-- .../jta/SimpleTransactionFactory.java | 6 +++++- .../transaction/jta/TransactionFactory.java | 16 ++++++++++++++-- .../jta/WebSphereUowTransactionManager.java | 18 ++++++++++++++++-- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/org.springframework.transaction/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java b/org.springframework.transaction/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java index 1edef5098bd..b4679e3a424 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java +++ b/org.springframework.transaction/src/main/java/org/springframework/jca/endpoint/AbstractMessageEndpointFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 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. @@ -17,7 +17,6 @@ package org.springframework.jca.endpoint; import java.lang.reflect.Method; - import javax.resource.ResourceException; import javax.resource.spi.ApplicationServerInternalException; import javax.resource.spi.UnavailableException; @@ -255,22 +254,24 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF */ private class TransactionDelegate { - private XAResource xaResource; + private final XAResource xaResource; private Transaction transaction; private boolean rollbackOnly; public TransactionDelegate(XAResource xaResource) { - if (transactionFactory != null && xaResource == null) { - throw new IllegalStateException("ResourceAdapter-provided XAResource is required for " + - "transaction management. Check your ResourceAdapter's configuration."); + if (xaResource == null) { + if (transactionFactory != null && !transactionFactory.supportsResourceAdapterManagedTransactions()) { + throw new IllegalStateException("ResourceAdapter-provided XAResource is required for " + + "transaction management. Check your ResourceAdapter's configuration."); + } } this.xaResource = xaResource; } public void beginTransaction() throws Exception { - if (transactionFactory != null) { + if (transactionFactory != null && this.xaResource != null) { this.transaction = transactionFactory.createTransaction(transactionName, transactionTimeout); this.transaction.enlistResource(this.xaResource); } 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 9830dbcedee..6f777cfec0c 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-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -21,7 +21,6 @@ import java.io.ObjectInputStream; import java.io.Serializable; import java.util.List; import java.util.Properties; - import javax.naming.NamingException; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; @@ -1192,6 +1191,10 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager return tm.getTransaction(); } + public boolean supportsResourceAdapterManagedTransactions() { + return false; + } + //--------------------------------------------------------------------- // Serialization support 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 51bfe5e9114..400a3a5a04d 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-2007 the original author or authors. + * Copyright 2002-2009 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. @@ -58,4 +58,8 @@ public class SimpleTransactionFactory implements TransactionFactory { return this.transactionManager.getTransaction(); } + public boolean supportsResourceAdapterManagedTransactions() { + return false; + } + } diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/TransactionFactory.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/TransactionFactory.java index eed1b5f8632..40c8ee48455 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/TransactionFactory.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/TransactionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 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. @@ -44,9 +44,21 @@ public interface TransactionFactory { * @return the active Transaction object (never null) * @throws NotSupportedException if the transaction manager does not support * a transaction of the specified type - * @throws SystemException if the transaction managed failed to create the + * @throws SystemException if the transaction manager failed to create the * transaction */ Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException; + /** + * Determine whether the underlying transaction manager supports XA transactions + * managed by a resource adapter (i.e. without explicit XA resource enlistment). + *

Typically false. Checked by + * {@link org.springframework.jca.endpoint.AbstractMessageEndpointFactory} + * in order to differentiate between invalid configuration and valid + * ResourceAdapter-managed transactions. + * @see javax.resource.spi.ResourceAdapter#endpointActivation + * @see javax.resource.spi.endpoint.MessageEndpointFactory#isDeliveryTransacted + */ + boolean supportsResourceAdapterManagedTransactions(); + } diff --git a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebSphereUowTransactionManager.java b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebSphereUowTransactionManager.java index 8f9fd2fa327..f537aa0b4ae 100644 --- a/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebSphereUowTransactionManager.java +++ b/org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebSphereUowTransactionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -160,7 +160,7 @@ public class WebSphereUowTransactionManager extends JtaTransactionManager if (logger.isDebugEnabled()) { logger.debug("Retrieving WebSphere UOWManager from JNDI location [" + uowManagerName + "]"); } - return (UOWManager) getJndiTemplate().lookup(uowManagerName, UOWManager.class); + return getJndiTemplate().lookup(uowManagerName, UOWManager.class); } catch (NamingException ex) { throw new TransactionSystemException( @@ -176,6 +176,20 @@ public class WebSphereUowTransactionManager extends JtaTransactionManager this.uowManager.registerInterposedSynchronization(new JtaAfterCompletionSynchronization(synchronizations)); } + /** + * Returns true since WebSphere ResourceAdapters (as exposed in JNDI) + * implicitly perform transaction enlistment if the MessageEndpointFactory's + * isDeliveryTransacted method returns true. + * In that case we'll simply skip the {@link #createTransaction} call. + * @see javax.resource.spi.endpoint.MessageEndpointFactory#isDeliveryTransacted + * @see org.springframework.jca.endpoint.AbstractMessageEndpointFactory + * @see TransactionFactory#createTransaction + */ + @Override + public boolean supportsResourceAdapterManagedTransactions() { + return true; + } + public Object execute(TransactionDefinition definition, TransactionCallback callback) throws TransactionException { if (definition == null) {