[jboss-svn-commits] JBL Code SVN: r32614 - in labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts: performance/xa/managed and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Apr 23 13:50:12 EDT 2010


Author: whitingjr
Date: 2010-04-23 13:50:11 -0400 (Fri, 23 Apr 2010)
New Revision: 32614

Added:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/CachedXADataSourceFactory.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnection.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrappedConnection.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrapperDataSource.java
Modified:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/MCXaDataSourceWrapper.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnectionFactory.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/TransactionalResourceFactory.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/XADataSourceWrapper.java
Log:
Fixed cached connection to enlist connection.

Added: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/CachedXADataSourceFactory.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/CachedXADataSourceFactory.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/CachedXADataSourceFactory.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -0,0 +1,76 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jbossts.performance;
+
+import java.sql.Connection;
+import java.util.Map;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+
+public class CachedXADataSourceFactory extends TransactionXADataSourceFactory
+{
+   
+   @Override
+   public ConnectionManager getDelegateManager()
+   {
+      return new CachedConnectionManagerDelegate();
+   }
+   
+   public class CachedConnectionManagerDelegate implements ConnectionManager
+   {
+      private static final long serialVersionUID = 1L;
+      private ThreadLocal<Object> cachedConnection = new ThreadLocal<Object>();
+
+      public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo cxRequestInfo) throws ResourceException
+      {// do not cache the connection here, delegate this responsibility to the callee
+         if (null == this.cachedConnection.get())
+         { 
+            this.cachedConnection.set(connectionManager.allocateConnection(mcf, cxRequestInfo));
+         }
+         try
+         {
+            if (((Connection)this.cachedConnection.get()).isClosed())
+            {/* renew the connection, the previous user of the connection really did want to close the
+            connection object. */
+               this.cachedConnection.set(connectionManager.allocateConnection(mcf, cxRequestInfo));
+            }   
+         }
+         catch (Exception e)
+         {
+            throw new ResourceException(e);
+         }
+//         this.cachedConnection.set(connectionManager.allocateConnection(mcf, cxRequestInfo));
+         return this.cachedConnection.get(); 
+      }
+   }
+
+   public CachedXADataSourceFactory(String jndi, String fqcn, Map<String, String> datasourceProperties)
+   {
+      super(jndi, fqcn, datasourceProperties);
+   }
+   
+   
+}

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/MCXaDataSourceWrapper.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/MCXaDataSourceWrapper.java	2010-04-23 17:48:58 UTC (rev 32613)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/MCXaDataSourceWrapper.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -38,6 +38,7 @@
 
 public class MCXaDataSourceWrapper extends XADataSourceWrapper
 {
+   @SuppressWarnings("unchecked")
    private Hashtable initialContextProperties;
    private static final Logger logger = Logger.getLogger(MCXaDataSourceWrapper.class);
    /* credentials repeater here on behalf of connection wrapper, dispite the credentials
@@ -45,11 +46,13 @@
    private String user;
    private String password;
    
+   @SuppressWarnings("unchecked")
    public Hashtable getInitialContextProperties()
    {
       return initialContextProperties;
    }
 
+   @SuppressWarnings("unchecked")
    public void setInitialContextProperties(Hashtable initialContextProperties)
    {
       this.initialContextProperties = initialContextProperties;

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java	2010-04-23 17:48:58 UTC (rev 32613)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -39,8 +39,8 @@
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
-import org.jboss.jbossts.performance.xa.managed.CachedXAManagedConnectionFactory;
 import org.jboss.jbossts.tomcat.TransactionalResourceFactory;
+import org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory;
 import org.jboss.resource.connectionmanager.CachedConnectionManager;
 import org.jboss.resource.connectionmanager.CachedConnectionManagerReference;
 import org.jboss.resource.connectionmanager.InternalManagedConnectionPool;
@@ -48,9 +48,6 @@
 import org.jboss.resource.connectionmanager.TxConnectionManager;
 import org.jboss.resource.connectionmanager.JBossManagedConnectionPool.BasePool;
 
-import com.arjuna.common.internal.util.logging.commonPropertyManager;
-import com.arjuna.common.util.logging.DebugLevel;
-
 /**
  * A TransactionXADataSourceFactory that creates the necessary connection pool and 
  * associates it with a TransactionManager using a TransactionalConnectionManager.
@@ -64,16 +61,19 @@
    private final org.jboss.logging.Logger jbLogger = org.jboss.logging.Logger.getLogger(TransactionXADataSourceFactory.class); 
    private String jndiName;
    private InitialContext initialContext;
+   @SuppressWarnings({"unused", "unchecked"})
    private Hashtable initialContextProperties;
    private Object xaDataSource;
-   private CachedXAManagedConnectionFactory managedConnectionFactory = new CachedXAManagedConnectionFactory();
+   private XAManagedConnectionFactory managedConnectionFactory ;
+
    CachedConnectionManager cachedConnectionManager;
    private InternalManagedConnectionPool.PoolParams poolParams = new InternalManagedConnectionPool.PoolParams();
-   private BasePool pool = new JBossManagedConnectionPool.OnePool(this.managedConnectionFactory, this.poolParams, false, jbLogger);
-   private TxConnectionManager connectionManager;
+   private BasePool pool ;
+   protected TxConnectionManager connectionManager;
    private TransactionManager transactionManager;
    private Map<String, String> daProperties;
    
+   
    public TransactionManager getTransactionManager()
    {
       return transactionManager;
@@ -84,24 +84,41 @@
       this.transactionManager = transactionManager;
    }
 
-   public TransactionXADataSourceFactory(String jndi, Map<String, String> datasourceProperties)
+   public TransactionXADataSourceFactory(String jndi, String factoryFQCN, Map<String, String> datasourceProperties)
    {
       this.jndiName = jndi;
       this.daProperties = datasourceProperties;
+      if (StringUtils.isNotBlank(factoryFQCN))
+      {
+         try
+         {
+            this.managedConnectionFactory =  (XAManagedConnectionFactory) Class.forName(factoryFQCN).newInstance();
+         }
+         catch (ClassNotFoundException cnfe)
+         {
+            logger.error(cnfe.getMessage(), cnfe);
+         }
+         catch (IllegalAccessException  iae) {
+            logger.error(iae.getMessage(), iae);
+         }
+         catch (InstantiationException ie) {
+            logger.error(ie.getMessage(), ie);
+         }
+      }
    }
    
    public void start() throws Exception
    {
       logger.info("Start called on transactional factory.");
       /* Configure programatically the logging level for ArjunaCore. */
-      DebugLevel level = new DebugLevel();
-      commonPropertyManager.getLoggingEnvironmentBean().setDebugLevel( level.printString( DebugLevel.FUNCS_AND_OPS ));
+      //TODO: conifgure logging programatically
       
+      this.pool = new JBossManagedConnectionPool.OnePool(this.managedConnectionFactory, this.poolParams, false, jbLogger);
       this.connectionManager = new TxConnectionManager(this.cachedConnectionManager, this.pool, this.transactionManager);
       this.connectionManager.setLocalTransactions(false);
       this.connectionManager.setTrackConnectionByTx(true);
       this.pool.setConnectionListenerFactory(connectionManager);
-      this.xaDataSource = this.connectionManager.getPoolingStrategy().getManagedConnectionFactory().createConnectionFactory(new ConnectionManagerDelegate());
+      this.xaDataSource = this.connectionManager.getPoolingStrategy().getManagedConnectionFactory().createConnectionFactory(getDelegateManager());
       if (null != this.daProperties)
       {/* Here use a Properties object to correctly format a properties file, use store to generate
       the file contents and convert to a string, which is passed to the setXADataSourceProperties method.
@@ -135,6 +152,8 @@
        */
       Shutdown shutdownHook = new Shutdown(this.connectionManager, this.pool);
       Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook));
+      
+//      }
    }
    
    public Object getDatasource()
@@ -153,6 +172,7 @@
    {
       return this.initialContext;
    }
+   @SuppressWarnings("unchecked")
    public void setInitialContextProperties(Hashtable properties)
    {
       this.initialContextProperties = properties;
@@ -207,6 +227,7 @@
          return connectionManager.allocateConnection(mcf, cxRequestInfo);
       }
    }
+   
    public void setCachedConnectionManager(CachedConnectionManagerReference reference)
    {
       this.cachedConnectionManager = reference.getCachedConnectionManager();
@@ -294,5 +315,9 @@
          this.basePool = pool; 
       }
    }
+   
+   public ConnectionManager getDelegateManager()
+   {
+      return new ConnectionManagerDelegate();
+   }
 }
-

Copied: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnection.java (from rev 31878, labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/LazyCachedXAManagedConnection.java)
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnection.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnection.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -0,0 +1,66 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jbossts.performance.xa.managed;
+
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.security.auth.Subject;
+import javax.sql.XAConnection;
+
+import org.jboss.resource.adapter.jdbc.WrappedConnection;
+import org.jboss.resource.adapter.jdbc.xa.XAManagedConnection;
+import org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory;
+
+/**
+ * A LazyCachedXAManagedConnection to hold a reference of the XAConnection
+ * object and associate it with the thread. The client application has been
+ * designed to use the same connection for a single thread.
+ * Reason for this design is to avoid the connection pooling implementation 
+ * which attempts to allocate a connection object for each transaction.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class CachedXAManagedConnection extends XAManagedConnection
+{
+   
+   public CachedXAManagedConnection(XAManagedConnectionFactory mcf, XAConnection xaConnection, Properties props,
+         int transactionIsolation, int psCacheSize) throws SQLException
+   {
+      super(mcf, xaConnection, props, transactionIsolation, psCacheSize);
+   }
+   
+   /**
+    * Provide a connection object using the ancestor class and wrap
+    * the connection object.
+    * Doing this provides object references for xa transactions. 
+    */
+   @Override
+   public Object getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
+   {
+      return new XAWrappedConnection((WrappedConnection)  super.getConnection(subject, cri), this.xaResource, this);
+   }
+}

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnectionFactory.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnectionFactory.java	2010-04-23 17:48:58 UTC (rev 32613)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnectionFactory.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -25,6 +25,8 @@
 import java.sql.SQLException;
 import java.util.Properties;
 
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
 import javax.resource.spi.ManagedConnection;
 import javax.sql.XAConnection;
 
@@ -40,11 +42,20 @@
 public class CachedXAManagedConnectionFactory extends XAManagedConnectionFactory
 {
 
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1124396543257247863L;
+
    /**
     * Provide the custom ManagedConnection object.
     */
    protected ManagedConnection newXAManagedConnection(Properties props, XAConnection xaConnection) throws SQLException
    {
-      return new LazyCachedXAManagedConnection(this, xaConnection, props, transactionIsolation, preparedStatementCacheSize);
+      return new CachedXAManagedConnection(this, xaConnection, props, transactionIsolation, preparedStatementCacheSize);
    }
+   
+   @Override
+   public Object createConnectionFactory(ConnectionManager cm) throws ResourceException
+   {
+      return new XAWrapperDataSource(this, cm);
+   }
 }

Added: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrappedConnection.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrappedConnection.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrappedConnection.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -0,0 +1,366 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jbossts.performance.xa.managed;
+
+import java.sql.CallableStatement;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.util.Map;
+
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.xa.XAResource;
+
+import org.apache.log4j.Logger;
+import org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection;
+import org.jboss.resource.adapter.jdbc.WrappedConnection;
+import org.jboss.resource.adapter.jdbc.WrapperDataSource;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
+
+/**
+ * A XAWrappedConnection object to expose to the caller the XAResource.
+ * This allows manual enlistment and delisting.
+ * This implementation has a confusing inheritance/field member design.
+ * The reason for this is
+ * to allow callers to cast to a WrappedConnection type at the same time
+ * as holding a reference to an XAResource.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class XAWrappedConnection extends WrappedConnection
+{
+   /**
+    * This holds a reference to the resource manager.
+    */
+   private ThreadLocal<XAResource> xaResLocal = new ThreadLocal<XAResource>();
+   /**
+    * A reference to the connection we are wrapping. All the methods pass through 
+    * to this object.
+    */
+   private WrappedConnection connection;
+   
+   private ThreadLocal<CachedXAManagedConnection> managedConnectionLocal = new ThreadLocal<CachedXAManagedConnection>();
+   
+   private Logger logger = Logger.getLogger(XAWrappedConnection.class);
+   
+   public XAWrappedConnection(WrappedConnection wrappedConn, XAResource xaRes, CachedXAManagedConnection managed)
+   {
+      super(null);
+      this.connection = wrappedConn;
+      this.xaResLocal.set(xaRes);
+      this.managedConnectionLocal.set( managed);
+   }
+   public XAResource getXAResource()
+   {
+      return this.xaResLocal.get();
+   }
+   
+   public CachedXAManagedConnection getManagedConnection()
+   {
+      return managedConnectionLocal.get();
+   }
+   
+   @Override
+   public void clearWarnings() throws SQLException
+   {
+      this.connection.clearWarnings();
+   }
+   /**
+    * This implementation supports the cached connection feature. This method
+    * will check for an active in progress transaction. When a transaction is 
+    * found then delist the connection from the XAResource.
+    */
+   @Override
+   public void close() throws SQLException
+   {
+      /** Rather than close the undelying connection it remains open to be reused by the 
+       * same thread of control.
+       */
+//      this.connection.close();
+      /**
+       * Here the connection is delisted from the transaction.
+       */
+      if (null != this.connection)
+      {
+         try
+         {
+            Transaction transaction = TransactionImple.getTransaction(); // this call is vendor specific and not intended to be neutral
+            CachedXAManagedConnection managedConnection = getManagedConnection();
+            if (null != transaction && null != managedConnection)
+            {
+               if (!transaction.delistResource(managedConnection, XAResource.TMSUCCESS))
+               {
+                  throw new SQLException("Failed to delist connection.");
+               }
+            }
+         }
+         catch (SystemException se)
+         {
+            logger.error(se.getMessage());
+            throw new SQLException(se);
+         }
+      }
+   }
+   @Override
+   public void commit() throws SQLException
+   {
+      this.connection.commit();
+   }
+
+   public Statement createStatement() throws SQLException
+   {
+      return this.connection.createStatement();
+   }
+   @Override
+   public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
+   {
+      return this.connection.createStatement(resultSetType, resultSetConcurrency);
+   }
+   @Override
+   public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+         throws SQLException
+   {
+      return this.connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+   }
+   @Override
+   public boolean getAutoCommit() throws SQLException
+   {
+      return this.connection.getAutoCommit();
+   }
+   @Override
+   public String getCatalog() throws SQLException
+   {
+      return this.connection.getCatalog();
+   }
+   @Override
+   public int getHoldability() throws SQLException
+   {
+      return this.connection.getHoldability();
+   }
+   @Override
+   public DatabaseMetaData getMetaData() throws SQLException
+   {
+      return this.connection.getMetaData();
+   }
+   @Override
+   public int getTransactionIsolation() throws SQLException
+   {
+      // FIXME getTransactionIsolation
+      return this.connection.getTransactionIsolation();
+   }
+   @SuppressWarnings("unchecked")
+   @Override
+   public Map<String, Class<?>> getTypeMap() throws SQLException
+   {
+      // FIXME getTypeMap
+      return this.connection.getTypeMap();
+   }
+   @Override
+   public SQLWarning getWarnings() throws SQLException
+   {
+      // FIXME getWarnings
+      return this.connection.getWarnings();
+   }
+   @Override
+   public boolean isClosed() throws SQLException
+   {
+      // FIXME isClosed
+      return this.connection.isClosed();
+   }
+   @Override
+   public boolean isReadOnly() throws SQLException
+   {
+      // FIXME isReadOnly
+      return this.connection.isReadOnly();
+   }
+   @Override
+   public String nativeSQL(String sql) throws SQLException
+   {
+      // FIXME nativeSQL
+      return this.connection.nativeSQL(sql);
+   }
+   @Override
+   public CallableStatement prepareCall(String sql) throws SQLException
+   {
+      // FIXME prepareCall
+      return this.connection.prepareCall(sql);
+   }
+   @Override
+   public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
+   {
+      // FIXME prepareCall
+      return this.connection.prepareCall(sql, resultSetType, resultSetConcurrency);
+   }
+   @Override
+   public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
+         int resultSetHoldability) throws SQLException
+   {
+      // FIXME prepareCall
+      return this.connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+   }
+   @Override
+   public PreparedStatement prepareStatement(String sql) throws SQLException
+   {
+      // FIXME prepareStatement
+      return this.connection.prepareStatement(sql);
+   }
+   @Override
+   public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
+   {
+      // FIXME prepareStatement
+      return this.connection.prepareStatement(sql, autoGeneratedKeys);
+   }
+   @Override
+   public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
+         throws SQLException
+   {
+      // FIXME prepareStatement
+      return this.connection.prepareStatement(sql, resultSetType, resultSetConcurrency);
+   }
+   @Override
+   public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
+         int resultSetHoldability) throws SQLException
+   {
+      // FIXME prepareStatement
+      return this.connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+   }
+   @Override
+   public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
+   {
+      // FIXME prepareStatement
+      return this.connection.prepareStatement(sql, columnIndexes);
+   }
+   @Override
+   public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
+   {
+      // FIXME prepareStatement
+      return this.connection.prepareStatement(sql, columnNames);
+   }
+   @Override
+   public void releaseSavepoint(Savepoint savepoint) throws SQLException
+   {
+      // FIXME releaseSavepoint
+      this.connection.releaseSavepoint(savepoint);
+   }
+
+   @Override
+   public void rollback() throws SQLException
+   {
+      this.connection.rollback();
+      
+   }
+
+   @Override
+   public void rollback(Savepoint savepoint) throws SQLException
+   {
+      // FIXME rollback
+      this.connection.rollback(savepoint);
+   }
+
+   @Override
+   public void setAutoCommit(boolean autoCommit) throws SQLException
+   {
+      // FIXME setAutoCommit
+      this.connection.setAutoCommit(autoCommit);
+   }
+
+   @Override
+   public void setCatalog(String catalog) throws SQLException
+   {
+      // FIXME setCatalog
+      this.connection.setCatalog(catalog);
+   }
+
+
+   @Override
+   public void setHoldability(int holdability) throws SQLException
+   {
+      // FIXME setHoldability
+      this.connection.setHoldability(holdability);
+   }
+
+   @Override
+   public void setReadOnly(boolean readOnly) throws SQLException
+   {
+      // FIXME setReadOnly
+      this.connection.setReadOnly(readOnly);
+   }
+
+   @Override
+   public Savepoint setSavepoint() throws SQLException
+   {
+      // FIXME setSavepoint
+      return this.connection.setSavepoint();
+   }
+
+   @Override
+   public Savepoint setSavepoint(String name) throws SQLException
+   {
+      // FIXME setSavepoint
+      return this.connection.setSavepoint(name);
+   }
+
+   @Override
+   public void setTransactionIsolation(int level) throws SQLException
+   {
+      // FIXME setTransactionIsolation
+      this.connection.setTransactionIsolation(level);
+   }
+
+//   @Override
+//   public void setTypeMap(Map<String, Class<?>> map) throws SQLException
+//   {
+//      // FIXME setTypeMap
+//      this.connection.setTypeMap(map);
+//   }
+//
+//   @Override
+//   public <T> T unwrap(Class<T> iface) throws SQLException
+//   {
+//      // FIXME unwrap
+//      return this.connection.unwrap(iface);
+//   }
+
+   /**
+    * This constructor is purely to satisfy the compiler and is not intended 
+    * for use.
+    * @param mc 
+    */
+   public XAWrappedConnection(final BaseWrapperManagedConnection mc)
+   {
+      super(mc);
+   }
+   
+   @Override
+   protected void setDataSource(WrapperDataSource dataSource)
+   {
+      // FIXME setDataSource
+      super.setDataSource(dataSource);
+   }
+}

Added: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrapperDataSource.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrapperDataSource.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/XAWrapperDataSource.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jbossts.performance.xa.managed;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.resource.spi.ConnectionManager;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+
+import org.apache.log4j.Logger;
+import org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnectionFactory;
+import org.jboss.resource.adapter.jdbc.WrapperDataSource;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
+/**
+ * 
+ * This object is responsible for demarcating the transaction boundary.
+ * This should be used for xa transactions.
+ * Typically this is performed by an EJB container. This object uses
+ * the calls to getConnection and close to enlist and delist a connection
+ * to transaction association using the XAResource.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+
+public class XAWrapperDataSource extends WrapperDataSource
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 6212545475101720539L;
+   
+   private Logger logger = Logger.getLogger(XAWrapperDataSource.class);
+   
+
+   protected XAWrapperDataSource(final BaseWrapperManagedConnectionFactory mcf, final ConnectionManager cm)
+   {
+      super(mcf, cm);
+   }
+
+   /**
+    * This implementation expects the connection manager to pass through a 
+    * custom Connection object for caching the connection. This method is
+    * responsible for enlisting the connection with the resource manager.
+    */
+   @Override
+   public Connection getConnection() throws SQLException
+   {
+      /* Downcast the connection to the cached connection implementation. */
+      XAWrappedConnection wc = (XAWrappedConnection)super.getConnection();
+      try
+      {
+         Transaction transaction = TransactionImple.getTransaction();
+         if (null != transaction )
+         {/* Only enlist the connection if there is an active transaction 
+         associated with this thread. */
+            if (!transaction.enlistResource(wc.getManagedConnection()))
+            {
+               throw new SQLException("Failed to enlist connection.");
+            }
+         }
+      }
+      catch (SystemException se)
+      {
+         logger.error(se.getMessage());
+         throw new SQLException(se);
+      }
+      catch (RollbackException re)
+      {
+         logger.error(re.getMessage());
+         throw new SQLException(re);
+      }
+      return wc;
+   }
+}

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/TransactionalResourceFactory.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/TransactionalResourceFactory.java	2010-04-23 17:48:58 UTC (rev 32613)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/TransactionalResourceFactory.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -23,7 +23,6 @@
 
 import javax.naming.spi.ObjectFactory;
 
-import java.util.Hashtable;
 import java.util.*;
 import java.lang.reflect.Method;
 import javax.naming.Name;
@@ -73,7 +72,8 @@
      *
      * @param obj The reference object describing the DataSource configuration
      */
-    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+    @SuppressWarnings("unchecked")
+   public Object getObjectInstance(Object obj, Name name, Context nameCtx,
                                     Hashtable environment) throws Exception
     {
         Reference ref = (Reference) obj;
@@ -186,7 +186,8 @@
      * @return
      * @throws NamingException
      */
-    protected XADataSource loadXADataSource(String classname) throws NamingException
+    @SuppressWarnings("unchecked")
+   protected XADataSource loadXADataSource(String classname) throws NamingException
     {
 
         Class clazz = null;

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/XADataSourceWrapper.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/XADataSourceWrapper.java	2010-04-23 17:48:58 UTC (rev 32613)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/tomcat/XADataSourceWrapper.java	2010-04-23 17:50:11 UTC (rev 32614)
@@ -181,7 +181,8 @@
         return iface.isAssignableFrom(XADataSource.class);
     }
 
-    public <T> T unwrap(Class<T> iface) throws SQLException
+    @SuppressWarnings("unchecked")
+   public <T> T unwrap(Class<T> iface) throws SQLException
     {
         if(isWrapperFor(iface)) {
             return (T)getUnwrappedXADataSource();



More information about the jboss-svn-commits mailing list