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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Mar 1 09:44:22 EST 2010


Author: whitingjr
Date: 2010-03-01 09:44:22 -0500 (Mon, 01 Mar 2010)
New Revision: 31878

Added:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/
   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/LazyCachedXAManagedConnection.java
Log:
Added connection classes to bypass the pooling implementation.


Added: 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	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/CachedXAManagedConnectionFactory.java	2010-03-01 14:44:22 UTC (rev 31878)
@@ -0,0 +1,50 @@
+ /*
+  * 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.spi.ManagedConnection;
+import javax.sql.XAConnection;
+
+import org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory;
+
+/**
+ * This implementation object provides a customised ManagedConnection object
+ * that will return the same object for the thread.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class CachedXAManagedConnectionFactory extends XAManagedConnectionFactory
+{
+
+   /**
+    * Provide the custom ManagedConnection object.
+    */
+   protected ManagedConnection newXAManagedConnection(Properties props, XAConnection xaConnection) throws SQLException
+   {
+      return new LazyCachedXAManagedConnection(this, xaConnection, props, transactionIsolation, preparedStatementCacheSize);
+   }
+}

Added: 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/LazyCachedXAManagedConnection.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/xa/managed/LazyCachedXAManagedConnection.java	2010-03-01 14:44:22 UTC (rev 31878)
@@ -0,0 +1,94 @@
+ /*
+  * 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 java.util.Properties;
+
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.security.auth.Subject;
+import javax.sql.XAConnection;
+
+import org.apache.log4j.Logger;
+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 LazyCachedXAManagedConnection extends XAManagedConnection
+{
+   private ThreadLocal<Object> cachedConnection = new ThreadLocal<Object>();
+   private static Logger logger = Logger.getLogger(LazyCachedXAManagedConnection.class);
+   
+   public LazyCachedXAManagedConnection(XAManagedConnectionFactory mcf, XAConnection xaConnection, Properties props,
+         int transactionIsolation, int psCacheSize) throws SQLException
+   {
+      super(mcf, xaConnection, props, transactionIsolation, psCacheSize);
+   }
+   
+   /**
+    * Provide a cached ManagedConnection object. This implementation uses lazy
+    * loading, the first request will pass on the request to the underlying 
+    * implementation.
+    * After the first initial request all subsequent requests will return the 
+    * same ManagedConnection.
+    */
+   @Override
+   public Object getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
+   {
+      if (null == this.cachedConnection.get())
+      {
+         this.cachedConnection.set(super.getConnection(subject, cri));
+      }
+      /**
+       * In some situations the underlying Connection was closed by the application.
+       * The performance framework should not be doing this. Usually this happens 
+       * during initialisation of the 
+       * entity objects. So detect when this occured and obtain a
+       * fresh WrappedConnection handle.
+       */
+      try
+      {
+         if (((Connection)this.cachedConnection.get()).isClosed() )
+         {
+            //ok, throw away the cached object. This allocates the Connection again for the thread
+            this.cachedConnection.set(super.getConnection(subject, cri));
+         }
+      } catch (SQLException sqle)
+      {
+         logger.error(sqle.getMessage(), sqle);
+      }
+      
+      return this.cachedConnection.get();
+   }
+}



More information about the jboss-svn-commits mailing list