geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog JDBCLog.java
Date Fri, 11 Jun 2004 19:22:05 GMT
djencks     2004/06/11 12:22:05

  Modified:    modules/connector/src/test-data/connector_1_5
                        geronimo-ra.xml
               modules/connector/src/java/org/apache/geronimo/connector
                        ResourceAdapterWrapper.java
               modules/connector/src/java/org/apache/geronimo/connector/outbound
                        AbstractConnectionManager.java
                        ConnectionManagerFactory.java
                        GenericConnectionManager.java LocalXAResource.java
                        ManagedConnectionFactoryWrapper.java
               modules/connector/src/java/org/apache/geronimo/connector/outbound/transactionlog
                        JDBCLog.java
  Log:
  Supply the means for the ManagedConnectionFactory to participate in recovery. Modify the
JDBCLog to recover names and branch Xids.
  
  Revision  Changes    Path
  1.15      +8 -3      incubator-geronimo/modules/connector/src/test-data/connector_1_5/geronimo-ra.xml
  
  Index: geronimo-ra.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/test-data/connector_1_5/geronimo-ra.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- geronimo-ra.xml	6 May 2004 03:59:56 -0000	1.14
  +++ geronimo-ra.xml	11 Jun 2004 19:22:04 -0000	1.15
  @@ -108,15 +108,20 @@
           <attribute name="StartMaximumPoolSize" type="int">10</attribute>
           <attribute name="ScheduledMinimumPoolSize" type="int">0</attribute>
           <attribute name="ScheduledMaximumPoolSize" type="int">10</attribute>
  -        <reference name="XAWork">geronimo.transaction:service=TransactionManager</reference>
  +        <reference name="XAWork">geronimo.server:type=TransactionManager</reference>
       </gbean>
   
       <gbean name="geronimo.connector:role=BootstrapContext" class="org.apache.geronimo.connector.BootstrapContext">
           <reference name="WorkManager">geronimo.connector:service=WorkManager</reference>
  -        <reference name="XATerminator">geronimo.transaction:service=TransactionManager</reference>
  +        <reference name="XATerminator">geronimo.server:type=TransactionManager</reference>
       </gbean>
   
  -    <gbean name="geronimo.transaction:service=TransactionManager" class="org.apache.geronimo.transaction.TransactionManagerProxy"/>
  +    <gbean name="geronimo.server:type=TransactionManager" class="org.apache.geronimo.transaction.GeronimoTransactionManager">
  +        <references name="resourceManagers">
  +            <pattern>geronimo.management:J2eeType=ManagedConnectionFactory,*</pattern>
  +            <pattern>geronimo.server:j2eeType=MessageDrivenBean,*</pattern>
  +        </references>
  +    </gbean>
   
       <gbean name="geronimo.security:service=RealmBridge,name=TargetRealm" class="org.apache.geronimo.security.bridge.ConfiguredIdentityUserPasswordRealmBridge">
           <attribute name="TargetRealm" type="java.lang.String">TargetRealm</attribute>
  
  
  
  1.11      +2 -1      incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java
  
  Index: ResourceAdapterWrapper.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ResourceAdapterWrapper.java	5 Jun 2004 07:53:21 -0000	1.10
  +++ ResourceAdapterWrapper.java	11 Jun 2004 19:22:04 -0000	1.11
  @@ -121,4 +121,5 @@
       public static GBeanInfo getGBeanInfo() {
           return GBEAN_INFO;
       }
  +
   }
  
  
  
  1.6       +24 -8     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractConnectionManager.java	8 Jun 2004 17:38:00 -0000	1.5
  +++ AbstractConnectionManager.java	11 Jun 2004 19:22:04 -0000	1.6
  @@ -27,22 +27,29 @@
   import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.GBeanLifecycle;
   import org.apache.geronimo.gbean.WaitingException;
  +import org.apache.geronimo.transaction.manager.NamedXAResource;
   
   /**
    * @version $Revision$ $Date$
    */
   public abstract class AbstractConnectionManager implements ConnectionManagerFactory, GBeanLifecycle,
ConnectionManager, LazyAssociatableConnectionManager {
   
  -    protected ConnectionInterceptor stack;
  +    private ConnectionInterceptor stack;
  +
  +    private ConnectionInterceptor recoveryStack;
  +
   
       public AbstractConnectionManager() {
       }
   
       public void doStart() throws WaitingException, Exception {
  -        setUpConnectionManager();
  +        ConnectionInterceptor[] stacks = setUpConnectionManager();
  +        assert stacks.length == 2;
  +        stack = stacks[0];
  +        recoveryStack = stacks[1];
       }
   
  -    protected abstract void setUpConnectionManager() throws IllegalStateException;
  +    protected abstract ConnectionInterceptor[] setUpConnectionManager() throws IllegalStateException;
   
       public void doStop() {
           stack = null;
  @@ -60,7 +67,7 @@
        * out: useable connection object.
        */
       public Object allocateConnection(ManagedConnectionFactory managedConnectionFactory,
  -            ConnectionRequestInfo connectionRequestInfo)
  +                                     ConnectionRequestInfo connectionRequestInfo)
               throws ResourceException {
           ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory,
connectionRequestInfo);
           ConnectionInfo ci = new ConnectionInfo(mci);
  @@ -74,8 +81,8 @@
        * out: supplied connection object is assiciated with a non-null ManagedConnection
from mcf.
        */
       public void associateConnection(Object connection,
  -            ManagedConnectionFactory managedConnectionFactory,
  -            ConnectionRequestInfo connectionRequestInfo)
  +                                    ManagedConnectionFactory managedConnectionFactory,
  +                                    ConnectionRequestInfo connectionRequestInfo)
               throws ResourceException {
           ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory,
connectionRequestInfo);
           ConnectionInfo ci = new ConnectionInfo(mci);
  @@ -87,13 +94,22 @@
           return stack;
       }
   
  +
  +    public ConnectionManagerFactory.ReturnableXAResource getRecoveryXAResource(ManagedConnectionFactory
managedConnectionFactory) throws ResourceException {
  +        ManagedConnectionInfo mci = new ManagedConnectionInfo(managedConnectionFactory,
null);
  +        ConnectionInfo recoveryConnectionInfo = new ConnectionInfo(mci);
  +        recoveryStack.getConnection(recoveryConnectionInfo);
  +        return new ConnectionManagerFactory.ReturnableXAResource((NamedXAResource) mci.getXAResource(),
recoveryStack, recoveryConnectionInfo);
  +    }
  +
  +
       protected static final GBeanInfo GBEAN_INFO;
   
   
       static {
           GBeanInfoFactory infoFactory = new GBeanInfoFactory(AbstractConnectionManager.class);
   
  -        infoFactory.addOperation("createConnectionFactory", new Class[]{ManagedConnectionFactory.class});
  +        infoFactory.addInterface(ConnectionManagerFactory.class);
   
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
  
  
  
  1.6       +73 -1     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConnectionManagerFactory.java	8 Jun 2004 17:38:00 -0000	1.5
  +++ ConnectionManagerFactory.java	11 Jun 2004 19:22:04 -0000	1.6
  @@ -19,6 +19,11 @@
   
   import javax.resource.ResourceException;
   import javax.resource.spi.ManagedConnectionFactory;
  +import javax.transaction.xa.XAException;
  +import javax.transaction.xa.XAResource;
  +import javax.transaction.xa.Xid;
  +
  +import org.apache.geronimo.transaction.manager.NamedXAResource;
   
   /**
    * ConnectionManagerFactory
  @@ -28,5 +33,72 @@
   public interface ConnectionManagerFactory {
   
       Object createConnectionFactory(ManagedConnectionFactory mcf) throws ResourceException;
  +
  +    ReturnableXAResource getRecoveryXAResource(ManagedConnectionFactory managedConnectionFactory)
throws ResourceException;
  +
  +    public class ReturnableXAResource implements NamedXAResource {
  +        private final ConnectionInterceptor stack;
  +        private final ConnectionInfo connectionInfo;
  +        private final NamedXAResource delegate;
  +
  +        public ReturnableXAResource(NamedXAResource delegate, ConnectionInterceptor stack,
ConnectionInfo connectionInfo) {
  +            this.delegate = delegate;
  +            this.stack = stack;
  +            this.connectionInfo = connectionInfo;
  +        }
  +
  +        public void returnConnection() {
  +            stack.returnConnection(connectionInfo, ConnectionReturnAction.DESTROY);
  +        }
  +
  +        public String getName() {
  +            return delegate.getName();
  +        }
  +
  +        public void commit(Xid xid, boolean onePhase) throws XAException {
  +            delegate.commit(xid, onePhase);
  +        }
  +
  +        public void end(Xid xid, int flags) throws XAException {
  +            delegate.end(xid, flags);
  +        }
  +
  +        public void forget(Xid xid) throws XAException {
  +            delegate.forget(xid);
  +        }
  +
  +        public int getTransactionTimeout() throws XAException {
  +            return delegate.getTransactionTimeout();
  +        }
  +
  +        public boolean isSameRM(XAResource other) throws XAException {
  +            if (other instanceof ReturnableXAResource) {
  +                return delegate.isSameRM(((ReturnableXAResource)other).delegate);
  +            }
  +            return delegate.isSameRM(other);
  +        }
  +
  +        public int prepare(Xid xid) throws XAException {
  +            return delegate.prepare(xid);
  +        }
  +
  +        public Xid[] recover(int flag) throws XAException {
  +            return delegate.recover(flag);
  +        }
  +
  +        public void rollback(Xid xid) throws XAException {
  +            delegate.rollback(xid);
  +        }
  +
  +        public boolean setTransactionTimeout(int seconds) throws XAException {
  +            return delegate.setTransactionTimeout(seconds);
  +        }
  +
  +        public void start(Xid xid, int flags) throws XAException {
  +            delegate.start(xid, flags);
  +        }
  +
  +
  +    }
   
   }
  
  
  
  1.6       +8 -4      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GenericConnectionManager.java	8 Jun 2004 17:38:00 -0000	1.5
  +++ GenericConnectionManager.java	11 Jun 2004 19:22:04 -0000	1.6
  @@ -17,6 +17,9 @@
   
   package org.apache.geronimo.connector.outbound;
   
  +import javax.resource.spi.ManagedConnectionFactory;
  +import javax.resource.ResourceException;
  +
   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool;
   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
   import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
  @@ -71,7 +74,7 @@
        * LocalXAResourceInsertionInterceptor or XAResourceInsertionInterceptor (useTransactions
(&localTransactions))
        * MCFConnectionInterceptor
        */
  -    protected void setUpConnectionManager() throws IllegalStateException {
  +    protected ConnectionInterceptor[] setUpConnectionManager() throws IllegalStateException
{
           //check for consistency between attributes
           if (realmBridge == null && pooling instanceof PartitionedPool &&
((PartitionedPool) pooling).isPartitionBySubject()) {
               throw new IllegalStateException("To use Subject in pooling, you need a SecurityDomain");
  @@ -94,6 +97,8 @@
               stack = new SubjectInterceptor(stack, realmBridge);
           }
   
  +        ConnectionInterceptor recoveryStack = stack;
  +
           stack = new ConnectionHandleInterceptor(stack);
           if (connectionTracker != null) {
               stack = new ConnectionTrackingInterceptor(stack,
  @@ -101,7 +106,7 @@
                       connectionTracker);
           }
           tail.setStack(stack);
  -        this.stack = stack;
  +        return new ConnectionInterceptor[] {stack, recoveryStack};
       }
   
       public TransactionSupport getTransactionSupport() {
  @@ -162,6 +167,5 @@
       public static GBeanInfo getGBeanInfo() {
           return GenericConnectionManager.GBEAN_INFO;
       }
  -
   
   }
  
  
  
  1.6       +2 -2      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LocalXAResource.java	8 Jun 2004 17:38:00 -0000	1.5
  +++ LocalXAResource.java	11 Jun 2004 19:22:04 -0000	1.6
  @@ -75,7 +75,7 @@
       }
   
       public Xid[] recover(int n) throws XAException {
  -        return null;
  +        return new Xid[0];
       }
   
       public void rollback(Xid xid) throws XAException {
  
  
  
  1.15      +22 -3     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ManagedConnectionFactoryWrapper.java	8 Jun 2004 17:38:00 -0000	1.14
  +++ ManagedConnectionFactoryWrapper.java	11 Jun 2004 19:22:04 -0000	1.15
  @@ -19,8 +19,10 @@
   
   import javax.management.ObjectName;
   import javax.naming.NamingException;
  +import javax.resource.ResourceException;
   import javax.resource.spi.ManagedConnectionFactory;
   import javax.resource.spi.ResourceAdapterAssociation;
  +import javax.transaction.SystemException;
   
   import net.sf.cglib.proxy.Callback;
   import net.sf.cglib.proxy.Enhancer;
  @@ -37,11 +39,13 @@
   import org.apache.geronimo.gbean.WaitingException;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.naming.geronimo.GeronimoContextManager;
  +import org.apache.geronimo.transaction.manager.NamedXAResource;
  +import org.apache.geronimo.transaction.manager.ResourceManager;
   
   /**
    * @version $Revision$ $Date$
    */
  -public class ManagedConnectionFactoryWrapper implements GBeanLifecycle, DynamicGBean {
  +public class ManagedConnectionFactoryWrapper implements GBeanLifecycle, DynamicGBean, ResourceManager
{
   
       private static final GBeanInfo GBEAN_INFO;
       private static final Log log = LogFactory.getLog(ManagedConnectionFactoryWrapper.class);
  @@ -232,6 +236,20 @@
           return interceptor;
       }
   
  +    //ResourceManager implementation
  +    public NamedXAResource getRecoveryXAResources() throws SystemException {
  +        try {
  +            return connectionManagerFactory.getRecoveryXAResource(managedConnectionFactory);
  +        } catch (ResourceException e) {
  +            throw (SystemException)new SystemException("Could not obtain recovery XAResource
for managedConnectionFactory " + objectName).initCause(e);
  +        }
  +    }
  +
  +    public void returnResource(NamedXAResource xaResource) {
  +        ((ConnectionManagerFactory.ReturnableXAResource)xaResource).returnConnection();
  +    }
  +
  +
       static {
           GBeanInfoFactory infoFactory = new GBeanInfoFactory(ManagedConnectionFactoryWrapper.class);
   
  @@ -247,6 +265,8 @@
           infoFactory.addOperation("getProxy");
           infoFactory.addOperation("getMethodInterceptor");
   
  +        infoFactory.addInterface(ResourceManager.class);
  +
           infoFactory.addReference("ResourceAdapterWrapper", ResourceAdapterWrapper.class);
           infoFactory.addReference("ConnectionManagerFactory", ConnectionManagerFactory.class);
           infoFactory.addReference("ManagedConnectionFactoryListener", ManagedConnectionFactoryListener.class);
  @@ -270,6 +290,5 @@
       public static GBeanInfo getGBeanInfo() {
           return GBEAN_INFO;
       }
  -
   
   }
  
  
  
  1.7       +22 -15    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JDBCLog.java	8 Jun 2004 17:38:01 -0000	1.6
  +++ JDBCLog.java	11 Jun 2004 19:22:05 -0000	1.7
  @@ -25,6 +25,7 @@
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
  +import java.util.Iterator;
   
   import javax.sql.DataSource;
   import javax.transaction.xa.Xid;
  @@ -37,6 +38,8 @@
   import org.apache.geronimo.transaction.manager.LogException;
   import org.apache.geronimo.transaction.manager.TransactionLog;
   import org.apache.geronimo.transaction.manager.XidFactory;
  +import org.apache.geronimo.transaction.manager.TransactionBranchInfo;
  +import org.apache.geronimo.transaction.manager.TransactionBranchInfoImpl;
   
   /**
    * "Last Resource optimization" for single servers wishing to have valid xa transactions
with
  @@ -46,9 +49,9 @@
    * @version $Revision$ $Date$
    */
   public class JDBCLog implements TransactionLog, GBeanLifecycle {
  -    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, NAME FROM
TXLOG WHERE SYSTEMID = ? ORDER BY FORMATID, GLOBALID, BRANCHID, NAME";
  +    private final static String INSERT_XID = "INSERT INTO TXLOG (SYSTEMID, FORMATID, GLOBALID,
GLOBALBRANCHID, BRANCHBRANCHID, NAME) VALUES (?, ?, ?, ?, ?)";
  +    private final static String DELETE_XID = "DELETE FROM TXLOG WHERE SYSTEMID = ? AND
FORMATID = ? AND GLOBALID = ?  AND GLOBALBRANCHID = ?";
  +    private final static String RECOVER = "SELECT FORMATID, GLOBALID, GLOBALBRANCHID, BRANCHBRANCHID,
NAME FROM TXLOG WHERE SYSTEMID = ? ORDER BY FORMATID, GLOBALID, GLOBALBRANCHID, BRANCHBRANCHID,
NAME";
   
       private DataSource dataSource;
       private final String systemId;
  @@ -73,7 +76,7 @@
       public void begin(Xid xid) throws LogException {
       }
   
  -    public void prepare(Xid xid, String[] names) throws LogException {
  +    public void prepare(Xid xid, List branches) throws LogException {
           int formatId = xid.getFormatId();
           byte[] globalTransactionId = xid.getGlobalTransactionId();
           byte[] branchQualifier = xid.getBranchQualifier();
  @@ -82,12 +85,14 @@
               try {
                   PreparedStatement ps = connection.prepareStatement(INSERT_XID);
                   try {
  -                    for (int i = 0; i < names.length; i++ ) {
  +                    for (Iterator iterator = branches.iterator(); iterator.hasNext();)
{
  +                        TransactionBranchInfo branch = (TransactionBranchInfo) iterator.next();
                           ps.setString(0, systemId);
                           ps.setInt(1, formatId);
                           ps.setBytes(2, globalTransactionId);
                           ps.setBytes(3, branchQualifier);
  -                        ps.setString(4, names[i]);
  +                        ps.setBytes(4, branch.getBranchXid().getBranchQualifier());
  +                        ps.setString(5, branch.getResourceName());
                           ps.execute();
                       }
                   } finally {
  @@ -143,22 +148,24 @@
                   ResultSet rs = ps.executeQuery();
                   Xid lastXid = null;
                   Xid currentXid = null;
  -                List names = new ArrayList();
  +                List branches = new ArrayList();
                   while (rs.next()) {
                       int formatId = rs.getInt(0);
                       byte[] globalId = rs.getBytes(1);
  -                    byte[] branchId = rs.getBytes(2);
  -                    String name = rs.getString(3);
  -                    currentXid = xidFactory.recover(formatId, globalId, branchId);
  +                    byte[] globalBranchId = rs.getBytes(2);
  +                    byte[] branchBranchId = rs.getBytes(3);
  +                    String name = rs.getString(4);
  +                    currentXid = xidFactory.recover(formatId, globalId, globalBranchId);
  +                    Xid branchXid = xidFactory.recover(formatId, globalId, branchBranchId);
                       if (!currentXid.equals(lastXid) && lastXid != null) {
  -                        addRecoveredXid(xids, lastXid, names);
  -                        names.clear();
  +                        addRecoveredXid(xids, lastXid, branches);
  +                        branches.clear();
                           lastXid = currentXid;
                       }
  -                    names.add(name);
  +                    branches.add(new TransactionBranchInfoImpl(branchXid, name));
                   }
                   if (currentXid != null) {
  -                    addRecoveredXid(xids, currentXid, names);
  +                    addRecoveredXid(xids, currentXid, branches);
                   }
                   return xids;
               } finally {
  
  
  

Mime
View raw message