Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 99235 invoked from network); 8 Jun 2004 17:38:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 8 Jun 2004 17:38:13 -0000 Received: (qmail 19543 invoked by uid 500); 8 Jun 2004 17:38:23 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 19471 invoked by uid 500); 8 Jun 2004 17:38:23 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@geronimo.apache.org Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 19456 invoked by uid 500); 8 Jun 2004 17:38:23 -0000 Delivered-To: apmail-incubator-geronimo-cvs@apache.org Received: (qmail 19450 invoked by uid 99); 8 Jun 2004 17:38:22 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 08 Jun 2004 10:38:22 -0700 Received: (qmail 99169 invoked by uid 1712); 8 Jun 2004 17:38:01 -0000 Date: 8 Jun 2004 17:38:01 -0000 Message-ID: <20040608173801.99168.qmail@minotaur.apache.org> From: djencks@apache.org To: incubator-geronimo-cvs@apache.org Subject: cvs commit: incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound LocalXAResourceInsertionInterceptorTest.java ManagedConnectionFactoryWrapperTest.java TransactionEnlistingInterceptorTest.java XAResourceInsertionInterceptorTest.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N djencks 2004/06/08 10:38:01 Modified: modules/connector/src/java/org/apache/geronimo/connector/deployment AbstractRARConfigBuilder.java RAR_1_0ConfigBuilder.java RAR_1_5ConfigBuilder.java modules/connector/src/java/org/apache/geronimo/connector/outbound AbstractConnectionManager.java ConnectionManagerFactory.java GenericConnectionManager.java LocalXAResource.java LocalXAResourceInsertionInterceptor.java ManagedConnectionFactoryWrapper.java XAResourceInsertionInterceptor.java modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig LocalTransactions.java NoTransactions.java TransactionLog.java TransactionSupport.java XATransactions.java modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog JDBCLog.java LogXAResource.java LogXAResourceInsertionInterceptor.java modules/connector/src/test/org/apache/geronimo/connector/outbound LocalXAResourceInsertionInterceptorTest.java ManagedConnectionFactoryWrapperTest.java TransactionEnlistingInterceptorTest.java XAResourceInsertionInterceptorTest.java Log: introduce NamedXAResource so transactions can log which resource managers are involved Revision Changes Path 1.20 +2 -2 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/AbstractRARConfigBuilder.java Index: AbstractRARConfigBuilder.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/AbstractRARConfigBuilder.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- AbstractRARConfigBuilder.java 5 Jun 2004 01:40:09 -0000 1.19 +++ AbstractRARConfigBuilder.java 8 Jun 2004 17:38:00 -0000 1.20 @@ -301,7 +301,7 @@ throw new DeploymentException("Unexpected pooling support element"); } try { - connectionManagerGBean.setAttribute("Name", connectionfactoryInstance.getName()); +// connectionManagerGBean.setAttribute("Name", connectionfactoryInstance.getName()); connectionManagerGBean.setAttribute("TransactionSupport", transactionSupport); connectionManagerGBean.setAttribute("Pooling", pooling); connectionManagerGBean.setReferencePatterns("ConnectionTracker", Collections.singleton(connectionTrackerNamePattern)); 1.12 +2 -2 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilder.java Index: RAR_1_0ConfigBuilder.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilder.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- RAR_1_0ConfigBuilder.java 5 Jun 2004 01:40:09 -0000 1.11 +++ RAR_1_0ConfigBuilder.java 8 Jun 2004 17:38:00 -0000 1.12 @@ -121,7 +121,7 @@ context.addGBean(ObjectName.getInstance(BASE_PASSWORD_CREDENTIAL_LOGIN_MODULE_NAME + connectionfactoryInstance.getName()), realmGBean); managedConnectionFactoryGBean.setReferencePatterns("ManagedConnectionFactoryListener", Collections.singleton(ObjectName.getInstance(BASE_PASSWORD_CREDENTIAL_LOGIN_MODULE_NAME + connectionfactoryInstance.getName()))); } - managedConnectionFactoryGBean.setAttribute("SelfName", managedConnectionFactoryObjectName); +// managedConnectionFactoryGBean.setAttribute("SelfName", managedConnectionFactoryObjectName); } catch (Exception e) { throw new DeploymentException(e); } 1.17 +2 -2 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilder.java Index: RAR_1_5ConfigBuilder.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilder.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- RAR_1_5ConfigBuilder.java 5 Jun 2004 01:40:09 -0000 1.16 +++ RAR_1_5ConfigBuilder.java 8 Jun 2004 17:38:00 -0000 1.17 @@ -175,7 +175,7 @@ context.addGBean(ObjectName.getInstance(BASE_PASSWORD_CREDENTIAL_LOGIN_MODULE_NAME + connectionfactoryInstance.getName()), realmGBean); managedConnectionFactoryGBean.setReferencePatterns("ManagedConnectionFactoryListener", Collections.singleton(ObjectName.getInstance(BASE_PASSWORD_CREDENTIAL_LOGIN_MODULE_NAME + connectionfactoryInstance.getName()))); } - managedConnectionFactoryGBean.setAttribute("SelfName", managedConnectionFactoryObjectName); +// managedConnectionFactoryGBean.setAttribute("SelfName", managedConnectionFactoryObjectName); } catch (Exception e) { throw new DeploymentException(e); } 1.5 +2 -1 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractConnectionManager.java Index: AbstractConnectionManager.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/AbstractConnectionManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AbstractConnectionManager.java 5 Jun 2004 07:53:21 -0000 1.4 +++ AbstractConnectionManager.java 8 Jun 2004 17:38:00 -0000 1.5 @@ -32,6 +32,7 @@ * @version $Revision$ $Date$ */ public abstract class AbstractConnectionManager implements ConnectionManagerFactory, GBeanLifecycle, ConnectionManager, LazyAssociatableConnectionManager { + protected ConnectionInterceptor stack; public AbstractConnectionManager() { 1.5 +1 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerFactory.java Index: ConnectionManagerFactory.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ConnectionManagerFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ConnectionManagerFactory.java 10 Mar 2004 09:58:32 -0000 1.4 +++ ConnectionManagerFactory.java 8 Jun 2004 17:38:00 -0000 1.5 @@ -29,6 +29,4 @@ Object createConnectionFactory(ManagedConnectionFactory mcf) throws ResourceException; - String getName(); - } 1.5 +10 -19 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java Index: GenericConnectionManager.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/GenericConnectionManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- GenericConnectionManager.java 2 Jun 2004 05:33:02 -0000 1.4 +++ GenericConnectionManager.java 8 Jun 2004 17:38:00 -0000 1.5 @@ -33,14 +33,13 @@ */ public class GenericConnectionManager extends AbstractConnectionManager { + private String objectName; + //connection manager configuration choices private TransactionSupport transactionSupport; private PoolingSupport pooling; - /** - * Identifying string used by unshareable resource detection - */ - private String name; //dependencies + protected RealmBridge realmBridge; protected ConnectionTracker connectionTracker; @@ -50,12 +49,12 @@ public GenericConnectionManager(TransactionSupport transactionSupport, PoolingSupport pooling, - String name, + String objectName, RealmBridge realmBridge, ConnectionTracker connectionTracker) { this.transactionSupport = transactionSupport; this.pooling = pooling; - this.name = name; + this.objectName = objectName; this.realmBridge = realmBridge; this.connectionTracker = connectionTracker; } @@ -82,7 +81,7 @@ MCFConnectionInterceptor tail = new MCFConnectionInterceptor(); ConnectionInterceptor stack = tail; - stack = transactionSupport.addXAResourceInsertionInterceptor(stack); + stack = transactionSupport.addXAResourceInsertionInterceptor(stack, objectName); stack = pooling.addPoolingInterceptors(stack); //experimental threadlocal caching //moved to XATransactions @@ -98,14 +97,13 @@ stack = new ConnectionHandleInterceptor(stack); if (connectionTracker != null) { stack = new ConnectionTrackingInterceptor(stack, - getName(), + objectName, connectionTracker); } tail.setStack(stack); this.stack = stack; } - public TransactionSupport getTransactionSupport() { return transactionSupport; } @@ -122,14 +120,6 @@ this.pooling = pooling; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public RealmBridge getRealmBridge() { return realmBridge; } @@ -151,6 +141,7 @@ static { GBeanInfoFactory infoFactory = new GBeanInfoFactory(GenericConnectionManager.class, AbstractConnectionManager.GBEAN_INFO); + infoFactory.addAttribute("ObjectName", String.class, true); infoFactory.addAttribute("Name", String.class, true); infoFactory.addAttribute("TransactionSupport", TransactionSupport.class, true); infoFactory.addAttribute("Pooling", PoolingSupport.class, true); @@ -161,7 +152,7 @@ infoFactory.setConstructor(new String[]{ "TransactionSupport", "Pooling", - "Name", + "ObjectName", "RealmBridge", "ConnectionTracker"}); 1.5 +11 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/LocalXAResource.java Index: LocalXAResource.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/LocalXAResource.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- LocalXAResource.java 6 May 2004 03:58:22 -0000 1.4 +++ LocalXAResource.java 8 Jun 2004 17:38:00 -0000 1.5 @@ -23,6 +23,8 @@ import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; +import org.apache.geronimo.transaction.manager.NamedXAResource; + /** * LocalXAResource adapts a local transaction to be controlled by a * JTA transaction manager. Of course, it cannot provide xa @@ -31,15 +33,17 @@ * * @version $Revision$ $Date$ */ -public class LocalXAResource implements XAResource { +public class LocalXAResource implements NamedXAResource { //accessible in package for testing final LocalTransaction localTransaction; + private final String name; private Xid xid; private int transactionTimeout; - public LocalXAResource(LocalTransaction localTransaction) { + public LocalXAResource(LocalTransaction localTransaction, String name) { this.localTransaction = localTransaction; + this.name = name; } // Implementation of javax.transaction.xa.XAResource @@ -123,5 +127,9 @@ public int prepare(Xid xid) throws XAException { //log warning that semantics are incorrect... return XAResource.XA_OK; + } + + public String getName() { + return name; } } 1.4 +7 -6 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/LocalXAResourceInsertionInterceptor.java Index: LocalXAResourceInsertionInterceptor.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/LocalXAResourceInsertionInterceptor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LocalXAResourceInsertionInterceptor.java 10 Mar 2004 09:58:32 -0000 1.3 +++ LocalXAResourceInsertionInterceptor.java 8 Jun 2004 17:38:00 -0000 1.4 @@ -30,17 +30,18 @@ implements ConnectionInterceptor { private final ConnectionInterceptor next; + private final String name; - public LocalXAResourceInsertionInterceptor(final ConnectionInterceptor next) { + public LocalXAResourceInsertionInterceptor(final ConnectionInterceptor next, final String name) { this.next = next; - } // XAResourceInsertionInterceptor constructor + this.name = name; + } public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); mci.setXAResource( - new LocalXAResource( - mci.getManagedConnection().getLocalTransaction())); + new LocalXAResource(mci.getManagedConnection().getLocalTransaction(), name)); } public void returnConnection( @@ -49,4 +50,4 @@ next.returnConnection(connectionInfo, connectionReturnAction); } -} // XAResourceInsertionInterceptor +} 1.14 +8 -8 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java Index: ManagedConnectionFactoryWrapper.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ManagedConnectionFactoryWrapper.java 5 Jun 2004 07:53:21 -0000 1.13 +++ ManagedConnectionFactoryWrapper.java 8 Jun 2004 17:38:00 -0000 1.14 @@ -70,7 +70,7 @@ private Object proxy; private ConnectorMethodInterceptor interceptor; private final Kernel kernel; - private final ObjectName selfName; + private final String objectName; //default constructor for enhancement proxy endpoint public ManagedConnectionFactoryWrapper() { @@ -80,7 +80,7 @@ connectionInterface = null; connectionImplClass = null; kernel = null; - selfName = null; + objectName = null; } public ManagedConnectionFactoryWrapper(Class managedConnectionFactoryClass, @@ -93,7 +93,7 @@ ConnectionManagerFactory connectionManagerFactory, ManagedConnectionFactoryListener managedConnectionFactoryListener, Kernel kernel, - ObjectName selfName) throws InstantiationException, IllegalAccessException { + String objectName) throws InstantiationException, IllegalAccessException { this.managedConnectionFactoryClass = managedConnectionFactoryClass; this.connectionFactoryInterface = connectionFactoryInterface; this.connectionFactoryImplClass = connectionFactoryImplClass; @@ -110,7 +110,7 @@ delegate.addAll(managedConnectionFactory); this.managedConnectionFactoryListener = managedConnectionFactoryListener; this.kernel = kernel; - this.selfName = selfName; + this.objectName = objectName; } @@ -177,7 +177,7 @@ enhancer.setSuperclass(connectionFactoryInterface); enhancer.setCallbackType(net.sf.cglib.proxy.MethodInterceptor.class); enhancer.setUseFactory(false);//???? - interceptor = new ConnectorMethodInterceptor(kernel.getKernelName(), selfName); + interceptor = new ConnectorMethodInterceptor(kernel.getKernelName(), ObjectName.getInstance(objectName)); enhancer.setCallbacks(new Callback[]{interceptor}); proxy = enhancer.create(new Class[0], new Object[0]); } @@ -240,7 +240,7 @@ infoFactory.addAttribute("ConnectionFactoryImplClass", Class.class, true); infoFactory.addAttribute("ConnectionInterface", Class.class, true); infoFactory.addAttribute("ConnectionImplClass", Class.class, true); - infoFactory.addAttribute("SelfName", ObjectName.class, true); + infoFactory.addAttribute("objectName", String.class, false); infoFactory.addAttribute("GlobalJNDIName", String.class, true); infoFactory.addAttribute("kernel", Kernel.class, false); @@ -262,7 +262,7 @@ "ConnectionManagerFactory", "ManagedConnectionFactoryListener", "kernel", - "SelfName"}); + "objectName"}); GBEAN_INFO = infoFactory.getBeanInfo(); } 1.4 +7 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/XAResourceInsertionInterceptor.java Index: XAResourceInsertionInterceptor.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/XAResourceInsertionInterceptor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XAResourceInsertionInterceptor.java 10 Mar 2004 09:58:32 -0000 1.3 +++ XAResourceInsertionInterceptor.java 8 Jun 2004 17:38:00 -0000 1.4 @@ -19,6 +19,8 @@ import javax.resource.ResourceException; +import org.apache.geronimo.transaction.manager.WrapperNamedXAResource; + /** * XAResourceInsertionInterceptor.java * @@ -28,15 +30,17 @@ public class XAResourceInsertionInterceptor implements ConnectionInterceptor { private final ConnectionInterceptor next; + private final String name; - public XAResourceInsertionInterceptor(final ConnectionInterceptor next) { + public XAResourceInsertionInterceptor(final ConnectionInterceptor next, final String name) { this.next = next; + this.name = name; } public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { next.getConnection(connectionInfo); ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); - mci.setXAResource(mci.getManagedConnection().getXAResource()); + mci.setXAResource(new WrapperNamedXAResource(mci.getManagedConnection().getXAResource(), name)); } public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) { 1.3 +3 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/LocalTransactions.java Index: LocalTransactions.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/LocalTransactions.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LocalTransactions.java 30 May 2004 19:03:36 -0000 1.2 +++ LocalTransactions.java 8 Jun 2004 17:38:00 -0000 1.3 @@ -34,8 +34,8 @@ private LocalTransactions() { } - public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack) { - return new LocalXAResourceInsertionInterceptor(stack); + public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack, String name) { + return new LocalXAResourceInsertionInterceptor(stack, name); } public ConnectionInterceptor addTransactionInterceptors(ConnectionInterceptor stack) { 1.2 +2 -2 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/NoTransactions.java Index: NoTransactions.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/NoTransactions.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NoTransactions.java 6 May 2004 03:58:22 -0000 1.1 +++ NoTransactions.java 8 Jun 2004 17:38:00 -0000 1.2 @@ -31,7 +31,7 @@ private NoTransactions() { } - public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack) { + public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack, String name) { return stack; } 1.3 +3 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/TransactionLog.java Index: TransactionLog.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/TransactionLog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TransactionLog.java 30 May 2004 19:03:36 -0000 1.2 +++ TransactionLog.java 8 Jun 2004 17:38:00 -0000 1.3 @@ -35,8 +35,8 @@ private TransactionLog() { } - public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack) { - return new LogXAResourceInsertionInterceptor(stack); + public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack, String name) { + return new LogXAResourceInsertionInterceptor(stack, name); } public ConnectionInterceptor addTransactionInterceptors(ConnectionInterceptor stack) { 1.2 +2 -2 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/TransactionSupport.java Index: TransactionSupport.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/TransactionSupport.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TransactionSupport.java 6 May 2004 03:58:22 -0000 1.1 +++ TransactionSupport.java 8 Jun 2004 17:38:00 -0000 1.2 @@ -28,7 +28,7 @@ * * */ public abstract class TransactionSupport implements Serializable { - public abstract ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack); + public abstract ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack, String name); public abstract ConnectionInterceptor addTransactionInterceptors(ConnectionInterceptor stack); } 1.4 +3 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/XATransactions.java Index: XATransactions.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/XATransactions.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XATransactions.java 30 May 2004 19:03:36 -0000 1.3 +++ XATransactions.java 8 Jun 2004 17:38:00 -0000 1.4 @@ -54,8 +54,8 @@ this.useThreadCaching = useThreadCaching; } - public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack) { - return new XAResourceInsertionInterceptor(stack); + public ConnectionInterceptor addXAResourceInsertionInterceptor(ConnectionInterceptor stack, String name) { + return new XAResourceInsertionInterceptor(stack, name); } public ConnectionInterceptor addTransactionInterceptors(ConnectionInterceptor stack) { 1.6 +64 -17 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog/JDBCLog.java Index: JDBCLog.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog/JDBCLog.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- JDBCLog.java 5 Jun 2004 07:53:21 -0000 1.5 +++ JDBCLog.java 8 Jun 2004 17:38:01 -0000 1.6 @@ -22,7 +22,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; + import javax.sql.DataSource; import javax.transaction.xa.Xid; @@ -33,15 +36,19 @@ import org.apache.geronimo.gbean.WaitingException; import org.apache.geronimo.transaction.manager.LogException; import org.apache.geronimo.transaction.manager.TransactionLog; -import org.apache.geronimo.transaction.manager.XidImpl; +import org.apache.geronimo.transaction.manager.XidFactory; /** + * "Last Resource optimization" for single servers wishing to have valid xa transactions with + * a single 1-pc datasource. The database is used for the log, and the database work is + * committed when the log writes its prepare record. + * * @version $Revision$ $Date$ */ public class JDBCLog implements TransactionLog, GBeanLifecycle { - private final static String INSERT_XID = "INSERT INTO TXLOG (SYSTEMID, FORMATID, GLOBALID, BRANCHID) VALUES (?, ?, ?, ?)"; + private final static String INSERT_XID = "INSERT INTO TXLOG (SYSTEMID, FORMATID, GLOBALID, BRANCHID, NAME) VALUES (?, ?, ?, ?, ?)"; private final static String DELETE_XID = "DELETE FROM TXLOG WHERE SYSTEMID = ? AND FORMATID = ? AND GLOBALID = ? BRANCHID = ?"; - private final static String RECOVER = "SELECT FORMATID, GLOBALID, BRANCHID FROM TXLOG WHERE SYSTEMID = ?"; + private final static String RECOVER = "SELECT FORMATID, GLOBALID, BRANCHID, NAME FROM TXLOG WHERE SYSTEMID = ? ORDER BY FORMATID, GLOBALID, BRANCHID, NAME"; private DataSource dataSource; private final String systemId; @@ -66,15 +73,42 @@ public void begin(Xid xid) throws LogException { } - public void prepare(Xid xid) throws LogException { - xidOperation(xid, INSERT_XID); + public void prepare(Xid xid, String[] names) throws LogException { + int formatId = xid.getFormatId(); + byte[] globalTransactionId = xid.getGlobalTransactionId(); + byte[] branchQualifier = xid.getBranchQualifier(); + try { + Connection connection = dataSource.getConnection(); + try { + PreparedStatement ps = connection.prepareStatement(INSERT_XID); + try { + for (int i = 0; i < names.length; i++ ) { + ps.setString(0, systemId); + ps.setInt(1, formatId); + ps.setBytes(2, globalTransactionId); + ps.setBytes(3, branchQualifier); + ps.setString(4, names[i]); + ps.execute(); + } + } finally { + ps.close(); + } + if (!connection.getAutoCommit()) { + connection.commit(); + } + } finally { + connection.close(); + } + } catch (SQLException e) { + throw new LogException("Failure during prepare or commit", e); + } } - private void xidOperation(Xid xid, String sql) throws LogException { + public void commit(Xid xid) throws LogException { try { Connection connection = dataSource.getConnection(); try { - PreparedStatement ps = connection.prepareStatement(sql); + PreparedStatement ps = connection.prepareStatement(DELETE_XID); try { ps.setString(0, systemId); ps.setInt(1, xid.getFormatId()); @@ -95,37 +129,50 @@ } } - public void commit(Xid xid) throws LogException { - xidOperation(xid, DELETE_XID); - } - public void rollback(Xid xid) throws LogException { throw new LogException("JDBCLog does not support rollback of prepared transactions. Use it only on servers that do not import transactions"); } - public List recover() throws LogException { + public Map recover(XidFactory xidFactory) throws LogException { try { Connection connection = dataSource.getConnection(); try { - List xids = new ArrayList(); + Map xids = new HashMap(); PreparedStatement ps = connection.prepareStatement(RECOVER); ps.setString(0, systemId); ResultSet rs = ps.executeQuery(); + Xid lastXid = null; + Xid currentXid = null; + List names = new ArrayList(); while (rs.next()) { int formatId = rs.getInt(0); byte[] globalId = rs.getBytes(1); byte[] branchId = rs.getBytes(2); - Xid xid = new XidImpl(formatId, globalId, branchId); - xids.add(xid); + String name = rs.getString(3); + currentXid = xidFactory.recover(formatId, globalId, branchId); + if (!currentXid.equals(lastXid) && lastXid != null) { + addRecoveredXid(xids, lastXid, names); + names.clear(); + lastXid = currentXid; + } + names.add(name); + } + if (currentXid != null) { + addRecoveredXid(xids, currentXid, names); } return xids; } finally { connection.close(); } } catch (SQLException e) { - throw new LogException("Recover failure", e); + throw new LogException("Recovery failure", e); } + } + + private void addRecoveredXid(Map xids, Xid xid, List names) { + String[] nameArray = (String[])names.toArray(new String[names.size()]); + xids.put(xid, nameArray); } public String getXMLStats() { 1.3 +13 -4 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog/LogXAResource.java Index: LogXAResource.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog/LogXAResource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LogXAResource.java 30 May 2004 19:03:36 -0000 1.2 +++ LogXAResource.java 8 Jun 2004 17:38:01 -0000 1.3 @@ -23,19 +23,24 @@ import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; +import org.apache.geronimo.transaction.manager.NamedXAResource; + /** - * + * Works with JDBCLog to provide last resource optimization for a single 1-pc database. + * The database work is committed when the log writes its prepare record, not here. * * @version $Revision$ $Date$ * * */ -public class LogXAResource implements XAResource { +public class LogXAResource implements NamedXAResource { + final String name; final LocalTransaction localTransaction; private Xid xid; - public LogXAResource(LocalTransaction localTransaction) { + public LogXAResource(LocalTransaction localTransaction, String name) { this.localTransaction = localTransaction; + this.name = name; } public void commit(Xid xid, boolean onePhase) throws XAException { } @@ -99,4 +104,8 @@ throw new XAException("unknown state"); } } + + public String getName() { + return name; + } } 1.2 +5 -3 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog/LogXAResourceInsertionInterceptor.java Index: LogXAResourceInsertionInterceptor.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog/LogXAResourceInsertionInterceptor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LogXAResourceInsertionInterceptor.java 6 May 2004 03:58:23 -0000 1.1 +++ LogXAResourceInsertionInterceptor.java 8 Jun 2004 17:38:01 -0000 1.2 @@ -35,9 +35,11 @@ implements ConnectionInterceptor { private final ConnectionInterceptor next; + private final String name; - public LogXAResourceInsertionInterceptor(final ConnectionInterceptor next) { + public LogXAResourceInsertionInterceptor(final ConnectionInterceptor next, String name) { this.next = next; + this.name = name; } public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { @@ -45,7 +47,7 @@ ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo(); mci.setXAResource( new LogXAResource( - mci.getManagedConnection().getLocalTransaction())); + mci.getManagedConnection().getLocalTransaction(), name)); } public void returnConnection( 1.5 +3 -2 incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/LocalXAResourceInsertionInterceptorTest.java Index: LocalXAResourceInsertionInterceptorTest.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/LocalXAResourceInsertionInterceptorTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- LocalXAResourceInsertionInterceptorTest.java 20 Apr 2004 18:29:39 -0000 1.4 +++ LocalXAResourceInsertionInterceptorTest.java 8 Jun 2004 17:38:01 -0000 1.5 @@ -30,10 +30,11 @@ private LocalXAResourceInsertionInterceptor localXAResourceInsertionInterceptor; private LocalTransaction localTransaction; + private String name = "LocalXAResource"; protected void setUp() throws Exception { super.setUp(); - localXAResourceInsertionInterceptor = new LocalXAResourceInsertionInterceptor(this); + localXAResourceInsertionInterceptor = new LocalXAResourceInsertionInterceptor(this, name); } protected void tearDown() throws Exception { 1.5 +14 -15 incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapperTest.java Index: ManagedConnectionFactoryWrapperTest.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapperTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ManagedConnectionFactoryWrapperTest.java 5 Jun 2004 01:40:09 -0000 1.4 +++ ManagedConnectionFactoryWrapperTest.java 8 Jun 2004 17:38:01 -0000 1.5 @@ -53,7 +53,7 @@ public class ManagedConnectionFactoryWrapperTest extends TestCase { private Kernel kernel; - private ObjectName selfName; + private ObjectName managedConnectionFactoryName; private ObjectName ctcName; private ObjectName cmfName; private static final String GLOBAL_NAME = "GLOBAL_NAME"; @@ -61,23 +61,23 @@ private static final String TARGET_NAME = "testCFName"; public void testProxy() throws Exception { - Object proxy = kernel.invoke(selfName, "getProxy"); + Object proxy = kernel.invoke(managedConnectionFactoryName, "getProxy"); assertNotNull(proxy); assertTrue(proxy instanceof ConnectionFactory); Connection connection = ((ConnectionFactory) proxy).getConnection(); assertNotNull(connection); - kernel.stopGBean(selfName); + kernel.stopGBean(managedConnectionFactoryName); try { ((ConnectionFactory) proxy).getConnection(); fail(); } catch (IllegalStateException ise) { } - kernel.startGBean(selfName); + kernel.startGBean(managedConnectionFactoryName); ((ConnectionFactory) proxy).getConnection(); } public void testSerialization() throws Exception { - ConnectionFactory proxy = (ConnectionFactory) kernel.invoke(selfName, "getProxy"); + ConnectionFactory proxy = (ConnectionFactory) kernel.invoke(managedConnectionFactoryName, "getProxy"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(proxy); @@ -90,7 +90,7 @@ assertTrue(proxy instanceof ConnectionFactory); Connection connection = proxy.getConnection(); assertNotNull(connection); - kernel.stopGBean(selfName); + kernel.stopGBean(managedConnectionFactoryName); ObjectInputStream ois2 = new ObjectInputStream(new ByteArrayInputStream(bytes)); ConnectionFactory proxy3 = (ConnectionFactory) ois2.readObject(); try { @@ -98,7 +98,7 @@ fail(); } catch (IllegalStateException ise) { } - kernel.startGBean(selfName); + kernel.startGBean(managedConnectionFactoryName); proxy3.getConnection(); } @@ -112,13 +112,13 @@ Context ctx = new InitialContext(env); ConnectionFactory cf = (ConnectionFactory) ctx.lookup("geronimo:" + GLOBAL_NAME); assertNotNull(cf); - kernel.stopGBean(selfName); + kernel.stopGBean(managedConnectionFactoryName); try { ctx.lookup("geronimo:" + GLOBAL_NAME); fail(); } catch (NamingException ne) { } - kernel.startGBean(selfName); + kernel.startGBean(managedConnectionFactoryName); ConnectionFactory cf2 = (ConnectionFactory) ctx.lookup("geronimo:" + GLOBAL_NAME); assertNotNull(cf2); } @@ -190,7 +190,7 @@ cmfName = ObjectName.getInstance("test:role=ConnectionManagerFactory"); kernel.loadGBean(cmfName, cmf); - selfName = ObjectName.getInstance(JMXReferenceFactory.BASE_MANAGED_CONNECTION_FACTORY_NAME + TARGET_NAME); + managedConnectionFactoryName = ObjectName.getInstance(JMXReferenceFactory.BASE_MANAGED_CONNECTION_FACTORY_NAME + TARGET_NAME); GBeanMBean mcfw = new GBeanMBean(ManagedConnectionFactoryWrapper.getGBeanInfo()); mcfw.setAttribute("ManagedConnectionFactoryClass", MockManagedConnectionFactory.class); @@ -202,16 +202,15 @@ //"ResourceAdapterWrapper", mcfw.setReferencePatterns("ConnectionManagerFactory", Collections.singleton(cmfName)); //"ManagedConnectionFactoryListener", - mcfw.setAttribute("SelfName", selfName); - kernel.loadGBean(selfName, mcfw); + kernel.loadGBean(managedConnectionFactoryName, mcfw); kernel.startGBean(ctcName); kernel.startGBean(cmfName); - kernel.startGBean(selfName); + kernel.startGBean(managedConnectionFactoryName); } protected void tearDown() throws Exception { - kernel.stopGBean(selfName); + kernel.stopGBean(managedConnectionFactoryName); kernel.shutdown(); } 1.7 +3 -2 incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptorTest.java Index: TransactionEnlistingInterceptorTest.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/TransactionEnlistingInterceptorTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TransactionEnlistingInterceptorTest.java 24 May 2004 19:10:35 -0000 1.6 +++ TransactionEnlistingInterceptorTest.java 8 Jun 2004 17:38:01 -0000 1.7 @@ -27,6 +27,7 @@ import org.apache.geronimo.transaction.TransactionContext; import org.apache.geronimo.transaction.UnspecifiedTransactionContext; import org.apache.geronimo.transaction.manager.TransactionManagerImpl; +import org.apache.geronimo.transaction.manager.NamedXAResource; /** * @@ -35,7 +36,7 @@ * * */ public class TransactionEnlistingInterceptorTest extends ConnectionInterceptorTestUtils - implements XAResource { + implements NamedXAResource { private TransactionEnlistingInterceptor transactionEnlistingInterceptor; private boolean started; 1.5 +10 -4 incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/XAResourceInsertionInterceptorTest.java Index: XAResourceInsertionInterceptorTest.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/outbound/XAResourceInsertionInterceptorTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- XAResourceInsertionInterceptorTest.java 20 Apr 2004 18:32:00 -0000 1.4 +++ XAResourceInsertionInterceptorTest.java 8 Jun 2004 17:38:01 -0000 1.5 @@ -32,10 +32,11 @@ private XAResourceInsertionInterceptor xaResourceInsertionInterceptor; private XAResource xaResource; + private String name = "XAResource"; protected void setUp() throws Exception { super.setUp(); - xaResourceInsertionInterceptor = new XAResourceInsertionInterceptor(this); + xaResourceInsertionInterceptor = new XAResourceInsertionInterceptor(this, name); } protected void tearDown() throws Exception { @@ -48,11 +49,15 @@ xaResource = new TestXAResource(); managedConnection = new TestManagedConnection(xaResource); xaResourceInsertionInterceptor.getConnection(connectionInfo); - assertTrue("Expected the same XAResource", xaResource == connectionInfo.getManagedConnectionInfo().getXAResource()); + xaResource.setTransactionTimeout(200); + //xaresource is wrapped, so we do something to ours to make it distinguishable. + assertEquals("Expected the same XAResource", 200, connectionInfo.getManagedConnectionInfo().getXAResource().getTransactionTimeout()); } private static class TestXAResource implements XAResource { + private int txTimeout; + public void commit(Xid xid, boolean onePhase) throws XAException { } @@ -63,7 +68,7 @@ } public int getTransactionTimeout() throws XAException { - return 0; + return txTimeout; } public boolean isSameRM(XAResource xaResource) throws XAException { @@ -82,6 +87,7 @@ } public boolean setTransactionTimeout(int seconds) throws XAException { + this.txTimeout = seconds; return false; }