[jboss-cvs] JBossAS SVN: r101926 - in trunk: tomcat/src/main/java/org/jboss/web/tomcat/service/session/persistent and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 4 22:46:34 EST 2010


Author: bstansberry at jboss.com
Date: 2010-03-04 22:46:34 -0500 (Thu, 04 Mar 2010)
New Revision: 101926

Modified:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java
Log:
[JBAS-7786] don't attempt to continue using a db connection after an exception
[JBAS-7787] overwrite creation time when "re-inserting" a record

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java	2010-03-05 03:45:41 UTC (rev 101925)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java	2010-03-05 03:46:34 UTC (rev 101926)
@@ -516,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: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java	2010-03-05 03:45:41 UTC (rev 101925)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java	2010-03-05 03:46:34 UTC (rev 101926)
@@ -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