support for WebSphere's ResourceAdapter-managed transactions

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@605 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2009-02-09 15:36:20 +00:00
parent a9b28cf9bd
commit c09d4962d0
5 changed files with 48 additions and 14 deletions

View File

@ -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"); * 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.
@ -17,7 +17,6 @@
package org.springframework.jca.endpoint; package org.springframework.jca.endpoint;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import javax.resource.ResourceException; import javax.resource.ResourceException;
import javax.resource.spi.ApplicationServerInternalException; import javax.resource.spi.ApplicationServerInternalException;
import javax.resource.spi.UnavailableException; import javax.resource.spi.UnavailableException;
@ -255,22 +254,24 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF
*/ */
private class TransactionDelegate { private class TransactionDelegate {
private XAResource xaResource; private final XAResource xaResource;
private Transaction transaction; private Transaction transaction;
private boolean rollbackOnly; private boolean rollbackOnly;
public TransactionDelegate(XAResource xaResource) { public TransactionDelegate(XAResource xaResource) {
if (transactionFactory != null && xaResource == null) { if (xaResource == null) {
if (transactionFactory != null && !transactionFactory.supportsResourceAdapterManagedTransactions()) {
throw new IllegalStateException("ResourceAdapter-provided XAResource is required for " + throw new IllegalStateException("ResourceAdapter-provided XAResource is required for " +
"transaction management. Check your ResourceAdapter's configuration."); "transaction management. Check your ResourceAdapter's configuration.");
} }
}
this.xaResource = xaResource; this.xaResource = xaResource;
} }
public void beginTransaction() throws Exception { public void beginTransaction() throws Exception {
if (transactionFactory != null) { if (transactionFactory != null && this.xaResource != null) {
this.transaction = transactionFactory.createTransaction(transactionName, transactionTimeout); this.transaction = transactionFactory.createTransaction(transactionName, transactionTimeout);
this.transaction.enlistResource(this.xaResource); this.transaction.enlistResource(this.xaResource);
} }

View File

@ -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"); * 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.
@ -21,7 +21,6 @@ import java.io.ObjectInputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException; import javax.transaction.HeuristicRollbackException;
@ -1192,6 +1191,10 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
return tm.getTransaction(); return tm.getTransaction();
} }
public boolean supportsResourceAdapterManagedTransactions() {
return false;
}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Serialization support // Serialization support

View File

@ -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"); * 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.
@ -58,4 +58,8 @@ public class SimpleTransactionFactory implements TransactionFactory {
return this.transactionManager.getTransaction(); return this.transactionManager.getTransaction();
} }
public boolean supportsResourceAdapterManagedTransactions() {
return false;
}
} }

View File

@ -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"); * 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.
@ -44,9 +44,21 @@ public interface TransactionFactory {
* @return the active Transaction object (never <code>null</code>) * @return the active Transaction object (never <code>null</code>)
* @throws NotSupportedException if the transaction manager does not support * @throws NotSupportedException if the transaction manager does not support
* a transaction of the specified type * 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
*/ */
Transaction createTransaction(String name, int timeout) throws NotSupportedException, SystemException; 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).
* <p>Typically <code>false</code>. 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();
} }

View File

@ -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"); * 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.
@ -160,7 +160,7 @@ public class WebSphereUowTransactionManager extends JtaTransactionManager
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Retrieving WebSphere UOWManager from JNDI location [" + uowManagerName + "]"); 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) { catch (NamingException ex) {
throw new TransactionSystemException( throw new TransactionSystemException(
@ -176,6 +176,20 @@ public class WebSphereUowTransactionManager extends JtaTransactionManager
this.uowManager.registerInterposedSynchronization(new JtaAfterCompletionSynchronization(synchronizations)); this.uowManager.registerInterposedSynchronization(new JtaAfterCompletionSynchronization(synchronizations));
} }
/**
* Returns <code>true</code> since WebSphere ResourceAdapters (as exposed in JNDI)
* implicitly perform transaction enlistment if the MessageEndpointFactory's
* <code>isDeliveryTransacted</code> method returns <code>true</code>.
* 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 { public Object execute(TransactionDefinition definition, TransactionCallback callback) throws TransactionException {
if (definition == null) { if (definition == null) {