[jboss-svn-commits] JBL Code SVN: r31886 - labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Mar 1 10:40:56 EST 2010


Author: whitingjr
Date: 2010-03-01 10:40:55 -0500 (Mon, 01 Mar 2010)
New Revision: 31886

Added:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java
Modified:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java
Log:
Created cached connection and pooled connection abstraction.


Copied: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java (from rev 31828, labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/RawConnection.java)
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java	2010-03-01 15:40:55 UTC (rev 31886)
@@ -0,0 +1,79 @@
+ /*
+  * 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.task.pooling;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+/**
+ * This object provides Connection objects using lazy loading. This 
+ * is necessary to ensure the Connection objects are loaded in
+ * separate threads just before demand.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class CachedConnection implements ConnectionHandler
+{
+   private final DataSource resA;
+   private final DataSource resB;
+   private Connection connectionA;
+   private Connection connectionB;
+   
+   public CachedConnection(final DataSource dataSourceA, final DataSource dataSourceB)
+   {
+      this.resA = dataSourceA;
+      this.resB = dataSourceB;
+   }
+   
+   @Override
+   public Connection getConnectionA() throws SQLException
+   {
+      if (null == connectionA)
+      {
+         this.connectionA = resA.getConnection();
+      }
+      return this.connectionA;
+   }
+
+   @Override
+   public Connection getConnectionB() throws SQLException
+   {
+      if (null == connectionB)
+      {
+         this.connectionB = this.resB.getConnection();
+      }
+      return this.connectionB;
+   }
+   
+   @Override
+   public Connection closeQuietly(Connection conn) throws SQLException
+   {
+      /* This method is a NOOP. The intention is not to release the
+       * connection back to the pool but to retain it open instead.*/
+      return conn;
+   }
+
+}

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java	2010-03-01 15:39:54 UTC (rev 31885)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java	2010-03-01 15:40:55 UTC (rev 31886)
@@ -25,8 +25,15 @@
 import java.sql.Connection;
 import java.sql.SQLException;
 
+/**
+ * A ConnectionHandler to abstract the allocation of Connection objects.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
 public interface ConnectionHandler
 {
    public Connection getConnectionA() throws SQLException;
    public Connection getConnectionB() throws SQLException;
+   public Connection closeQuietly(Connection conn) throws SQLException;
 }

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java	2010-03-01 15:39:54 UTC (rev 31885)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java	2010-03-01 15:40:55 UTC (rev 31886)
@@ -27,6 +27,16 @@
 
 import javax.sql.DataSource;
 
+import org.apache.commons.dbutils.DbUtils;
+
+/**
+ * A PooledConnectionHandler to allocate Connection objects from the 
+ * underlying JCA. It does not change the pooling behaviour in any
+ * way.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
 public class PooledConnectionHandler implements ConnectionHandler
 {
    private final DataSource dataSourceA;
@@ -51,5 +61,12 @@
    {
       return this.dataSourceB.getConnection();
    }
+   
+   @Override
+   public Connection closeQuietly(Connection conn) throws SQLException
+   {// actually close the wrapped Connection object 
+      DbUtils.closeQuietly(conn);
+      return conn;
+   }
 
 }



More information about the jboss-svn-commits mailing list