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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 9 14:02:43 EST 2010


Author: whitingjr
Date: 2010-12-09 14:02:43 -0500 (Thu, 09 Dec 2010)
New Revision: 36321

Modified:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java
Log:
Updated implementation.

Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java	2010-12-09 19:01:50 UTC (rev 36320)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java	2010-12-09 19:02:43 UTC (rev 36321)
@@ -63,12 +63,6 @@
    {
       Connection connectionA = null;
       Connection connectionB = null;
-      PreparedStatement pStatementARead = null;
-      PreparedStatement  pStatementAWrite = null;
-      PreparedStatement pStatementBRead = null;
-      PreparedStatement  pStatementBWrite = null;
-      ResultSet resultA = null;
-      ResultSet resultB = null;
       boolean completed = false;
       boolean resAOK = false;
       try
@@ -78,52 +72,44 @@
          {
             begin();
             connectionA = getTaskConfiguration().getConnectionHandler().getConnectionA();
-            pStatementARead = connectionA.prepareStatement("SELECT USER_ID , OBJ_VERSION FROM USERS WHERE USER_ID=?");
-            resultA = findUsingResourceA(pStatementARead, this.getTaskConfiguration().getTestConfiguration().getThreadIdentity(), NumberUtils.INTEGER_ZERO);
-            //Assert.assertTrue(resultA.next());
-            resultA.next();
-            int version = resultA.getInt(2);
-            
-            if (this.isOptionalWriteEnabled)
+            Integer readA = findUsingResourceA("SELECT USER_ID , OBJ_VERSION FROM USERS WHERE USER_ID=?", connectionA, this.getTaskConfiguration().getTestConfiguration().getThreadIdentity());
+            if (null != readA)
             {
-               pStatementAWrite = connectionA.prepareStatement("update USERS set FIRSTNAME=?, OBJ_VERSION=? where USER_ID=? and OBJ_VERSION=?");
-               writeUsingResourceA(pStatementAWrite, time, version);
+               if (this.isOptionalWriteEnabled)
+               {
+                  writeUsingResourceA("update USERS set FIRSTNAME=?, OBJ_VERSION=? where USER_ID=? and OBJ_VERSION=?", connectionA, time, readA);
+                  resAOK = true;
+               }
+               else 
+               {
+                  resAOK = true;
+               }
             }
-            resAOK = true;
          }
          catch (Exception e) {
             logger.error(e.getMessage(), e);
          }
          finally
          {
-            DbUtils.closeQuietly(resultA);
-            DbUtils.closeQuietly(pStatementARead) ;
-            DbUtils.closeQuietly(pStatementAWrite);
             this.getTaskConfiguration().getConnectionHandler().closeQuietly(connectionA);
          }
          if (resAOK)
          {
             try
             {
-               connectionB= getTaskConfiguration().getConnectionHandler().getConnectionB();
-               pStatementBRead = connectionB.prepareStatement("SELECT USER_ID, OBJ_VERSION FROM USERS WHERE USER_ID=?");
-               resultB = findUsingResourceB(pStatementBRead,this.getTaskConfiguration().getTestConfiguration().getThreadIdentity(), NumberUtils.INTEGER_ONE);
-               //Assert.assertTrue(resultB.next());
-               resultB.next();
-               int version = resultB.getInt(2);
-               
-               pStatementBWrite = connectionB.prepareStatement("update USERS set FIRSTNAME=?, OBJ_VERSION=? where USER_ID=? and OBJ_VERSION=?");
-               writeUsingResourceB(pStatementBWrite, time, version);
-               completed = true;
+               connectionB = getTaskConfiguration().getConnectionHandler().getConnectionB();
+               Integer readB = findUsingResourceB("SELECT USER_ID, OBJ_VERSION FROM USERS WHERE USER_ID=?", connectionB,this.getTaskConfiguration().getTestConfiguration().getThreadIdentity());
+               if (null != readB)
+               {
+                  writeUsingResourceB("update USERS set FIRSTNAME=?, OBJ_VERSION=? where USER_ID=? and OBJ_VERSION=?", connectionB, time, readB);
+                  completed = true;
+               }
             }
             catch (Exception e) {
                logger.error(e.getMessage(), e);
             }
             finally
             {
-               DbUtils.closeQuietly(resultB);
-               DbUtils.closeQuietly(pStatementBRead) ;
-               DbUtils.closeQuietly(pStatementBWrite);
                this.getTaskConfiguration().getConnectionHandler().closeQuietly(connectionB);
             }
          }
@@ -133,44 +119,64 @@
          commit(completed);
       }
    }
-   public ResultSet findUsingResourceA(final PreparedStatement pStatement, final Long id, final int A)
+   public Integer findUsingResourceA(final String statement, final Connection conn, final Long id)
       throws SQLException
    {
-      return findUsingResource(pStatement, id);
+      return findUsingResource(statement, conn, id);
    }
-   public ResultSet findUsingResourceB(final PreparedStatement pStatement, final Long id, final int B)
+   public Integer findUsingResourceB(final String statement, final Connection conn, final Long id)
    throws SQLException
    {
-      return findUsingResource(pStatement, id);
+      return findUsingResource(statement, conn, id);
    }
-   private ResultSet findUsingResource(final PreparedStatement pStatement, final Long id)
+   private Integer findUsingResource(final String statement, final Connection conn, final Long id)
       throws SQLException
    {
+      Integer returnValue = null; 
+      PreparedStatement pStatement = conn.prepareStatement(statement);
       pStatement.setLong(1, id);
-      return pStatement.executeQuery();
+      try
+      {
+         ResultSet result  = pStatement.executeQuery();
+         Assert.assertTrue(result.next());
+         returnValue = result.getInt(2);
+      }
+      finally
+      {
+         DbUtils.closeQuietly( pStatement);
+      }
+      return returnValue;
    }
    
-   public void writeUsingResourceA(final PreparedStatement pStatement, long time, int version)
+   public void writeUsingResourceA(final String statement, final Connection conn, long time, int version)
       throws SQLException
    {
-      writeUsingResource(pStatement, time, version);
+      writeUsingResource(statement, conn, time, version);
    }
    
-   public void writeUsingResourceB(final PreparedStatement pStatement, long time, int version)
+   public void writeUsingResourceB(final String statement, final Connection conn, long time, int version)
       throws SQLException
    {
-      writeUsingResource(pStatement, time, version);
+      writeUsingResource(statement, conn, time, version);
    }
    
-   private void writeUsingResource(final PreparedStatement pStatement, long time, int version)
+   private void writeUsingResource(final String statement, final Connection conn, long time, int version)
       throws SQLException
    {
-      pStatement.setString(1, String.format("Ben%1$d", time));
-      pStatement.setInt(2, (version+1));
-      pStatement.setInt(3, this.getTaskConfiguration().getTestConfiguration().getThreadIdentity().intValue());
-      pStatement.setInt(4, version);
-//      Assert.assertEquals(pStatement.executeUpdate(), 1) ;
-      pStatement.executeUpdate();
+      PreparedStatement pStatement = null;
+      try
+      {
+         pStatement = conn.prepareStatement(statement);
+         pStatement.setString(1, String.format("Ben%1$d", time));
+         pStatement.setInt(2, (version+1));
+         pStatement.setInt(3, this.getTaskConfiguration().getTestConfiguration().getThreadIdentity().intValue());
+         pStatement.setInt(4, version);
+         Assert.assertEquals(pStatement.executeUpdate(), 1) ;
+      }
+      finally
+      {
+         DbUtils.closeQuietly(pStatement);
+      }
    }
    public void begin() 
       throws Exception
@@ -191,4 +197,27 @@
           Assert.fail("The test case had a problem and the transaction was rolled back.");
        }
    }
+   
+   class CompositeReadResult {
+      PreparedStatement statement = null;
+      int version = 0;
+      public PreparedStatement getStatement()
+      {
+         return statement;
+      }
+      public void setStatement(PreparedStatement statement)
+      {
+         this.statement = statement;
+      }
+      public int getVersion()
+      {
+         return version;
+      }
+      public void setVersion(int version)
+      {
+         this.version = version;
+      }
+      
+      
+   }
 }
\ No newline at end of file



More information about the jboss-svn-commits mailing list