[jboss-cvs] JBossAS SVN: r104487 - in branches/JBPAPP_5_1: testsuite/src/main/org/jboss/test/cluster/web/persistent and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 5 13:32:17 EDT 2010


Author: bstansberry at jboss.com
Date: 2010-05-05 13:32:16 -0400 (Wed, 05 May 2010)
New Revision: 104487

Modified:
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/web/persistent/PersistentStoreTableSetup.java
   branches/JBPAPP_5_1/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java
Log:
[JBPAPP-3843] Don't attempt to continue using a db connection after an exception; overwrite creation time when "re-inserting" a record 

Modified: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java	2010-05-05 16:04:59 UTC (rev 104486)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java	2010-05-05 17:32:16 UTC (rev 104487)
@@ -78,6 +78,7 @@
       {
          if (testee != null && testee.isStarted())
          {
+            testee.clear();
             testee.stop();
          }
       }
@@ -515,6 +516,51 @@
    /**
     * Test method for {@link org.jboss.web.tomcat.service.session.persistent.RDBMSStoreBase#storeSessionData(org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData)}.
     */
+   public void testInsertSessionDataExistingRecord()
+   {
+      testee.start();
+      DistributableSessionMetadata md = new DistributableSessionMetadata();
+      String id = nextId();
+      md.setId(id + ".full");
+      md.setCreationTime(1);
+      md.setNew(true);
+      md.setValid(true);
+      md.setMaxInactiveInterval(30000);
+      Long ts = Long.valueOf(2); 
+      Map<String, Object> attrs = new HashMap<String, Object>();
+      attrs.put("key", "value");
+      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
+      testee.storeSessionData(sessionData);
+      
+      // Don't call md.setNew(false); !! Treat it as a new session
+      DistributableSessionMetadata newmd = new DistributableSessionMetadata();
+      newmd.setId(id + ".full");
+      newmd.setCreationTime(3);
+      newmd.setNew(true);
+      newmd.setValid(true);
+      newmd.setMaxInactiveInterval(30000);
+      newmd.setMaxInactiveInterval(20000);
+      attrs.clear();
+      attrs.put("key", "newvalue");
+      Long newts = Long.valueOf(4); 
+      sessionData = new MockOutgoingSessionData(id, 0, newts, newmd, attrs);
+      testee.storeSessionData(sessionData);
+      
+      IncomingDistributableSessionData incoming = testee.getSessionData(id, true);
+      assertEquals(0, incoming.getVersion());
+      assertEquals(newts.longValue(), incoming.getTimestamp());
+      assertEquals(newmd.getId(), incoming.getMetadata().getId());
+      assertEquals(newmd.getCreationTime(), incoming.getMetadata().getCreationTime());
+      assertEquals(newmd.isNew(), incoming.getMetadata().isNew());
+      assertEquals(newmd.isValid(), incoming.getMetadata().isValid());
+      assertEquals(newmd.getMaxInactiveInterval(), incoming.getMetadata().getMaxInactiveInterval());
+      assertTrue(incoming.providesSessionAttributes());
+      assertEquals(attrs, incoming.getSessionAttributes());
+   }
+
+   /**
+    * Test method for {@link org.jboss.web.tomcat.service.session.persistent.RDBMSStoreBase#storeSessionData(org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData)}.
+    */
    public void testFullUpdateSessionData()
    {
       testee.start();

Modified: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/web/persistent/PersistentStoreTableSetup.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/web/persistent/PersistentStoreTableSetup.java	2010-05-05 16:04:59 UTC (rev 104486)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/web/persistent/PersistentStoreTableSetup.java	2010-05-05 17:32:16 UTC (rev 104487)
@@ -36,7 +36,7 @@
    		"valid CHAR(1) NOT NULL, " +
    		"metadata VARBINARY NULL, " +
    		"attributes LONGVARBINARY NOT NULL " +
-//   		", CONSTRAINT app_id PRIMARY KEY (app, id)" +
+   		", CONSTRAINT app_id PRIMARY KEY (app, id)" +
    		")";
    // --------------------------------------------------------- Instance Fields
    

Modified: branches/JBPAPP_5_1/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java
===================================================================
--- branches/JBPAPP_5_1/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java	2010-05-05 16:04:59 UTC (rev 104486)
+++ branches/JBPAPP_5_1/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java	2010-05-05 17:32:16 UTC (rev 104487)
@@ -170,6 +170,8 @@
    private String fullLoadSql;
 
    private String partialLoadSql;
+   
+   private String reinsertSql;
 
    private String removeSql;
 
@@ -967,9 +969,14 @@
                   {
                      getLogger().trace("Caught SQLException inserting session " + maskId(sessionData), e);
                   }
-                  if (executeGetSessionVersion(_conn, sessionData.getRealId()) != null)
+                  
+                  // The existing connection is no good now; need a new one
+                  cleanup(_conn, null, true);
+                  _conn = null;
+                  _conn = safeGetConnection();
+                  if (obs != null && executeGetSessionVersion(_conn, sessionData.getRealId()) != null)
                   {
-                     executeUpdate(sessionData, obs, _conn);
+                     executeReInsert(sessionData, obs, _conn);
                   }
                   else
                   {
@@ -1445,6 +1452,11 @@
             + getSessionMaxInactiveCol() + " = ?, " + getSessionValidCol() + " = ?, " + getSessionAttributeCol()
             + " = ?" + " WHERE " + getSessionIdCol() + " = ? AND " + getSessionAppCol() + " = ?";
 
+      this.reinsertSql = "UPDATE " + getSessionTable() + " SET " + getSessionVersionCol() + " = ?, "
+            + getSessionLastAccessedCol() + " = ?, " + getSessionFullIdCol() + " = ?, " + getSessionNewCol() + " = ?, "
+            + getSessionMaxInactiveCol() + " = ?, " + getSessionValidCol() + " = ?, " + getSessionAttributeCol()
+            + " = ?, " +  getSessionCreationTimeCol() + " = ? WHERE " + getSessionIdCol() + " = ? AND " + getSessionAppCol() + " = ?";
+
       this.timestampSql = "SELECT " + getSessionLastAccessedCol() + " FROM " + getSessionTable() + " WHERE "
             + getSessionIdCol() + " = ? AND " + getSessionAppCol() + " = ?";
 
@@ -1503,6 +1515,46 @@
       }
    }
 
+   private int executeReInsert(OutgoingSessionGranularitySessionData session, byte[] obs, Connection conn)
+         throws SQLException, IOException
+   {
+      DistributableSessionMetadata metadata = session.getMetadata();
+      int size = obs.length;
+      InputStream in = null;
+      if (obs != null)
+      {
+         ByteArrayInputStream bis = new ByteArrayInputStream(obs);
+         in = new BufferedInputStream(bis, size);
+      }
+
+      try
+      {
+         PreparedStatement preparedUpdateSql = prepareStatement(conn, getReInsertSql());
+         preparedUpdateSql.setInt(1, session.getVersion());
+         preparedUpdateSql.setLong(2, session.getTimestamp());
+         preparedUpdateSql.setString(3, metadata.getId());
+         preparedUpdateSql.setString(4, metadata.isNew() ? "1" : "0");
+         preparedUpdateSql.setInt(5, metadata.getMaxInactiveInterval());
+         preparedUpdateSql.setString(6, metadata.isValid() ? "1" : "0");
+         preparedUpdateSql.setBinaryStream(7, in, size);
+         preparedUpdateSql.setLong(8, metadata.getCreationTime());
+
+         // Add in the WHERE clause params
+         preparedUpdateSql.setString(9, session.getRealId());
+         preparedUpdateSql.setString(10, getName());
+         int count = preparedUpdateSql.executeUpdate();
+
+         return count;
+      }
+      finally
+      {
+         if (in != null)
+         {
+            in.close();
+         }
+      }
+   }
+
    private int executeUpdate(OutgoingSessionGranularitySessionData session, byte[] obs, Connection conn)
          throws SQLException, IOException
    {
@@ -1614,6 +1666,11 @@
       return fullUpdateSql;
    }
 
+   private String getReInsertSql()
+   {
+      return reinsertSql;
+   }
+
    private String getSimpleUpdateSql()
    {
       return simpleUpdateSql;




More information about the jboss-cvs-commits mailing list