[gatein-commits] gatein SVN: r5136 - in portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state: migration and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 17 04:57:13 EST 2010


Author: chris.laprun at jboss.com
Date: 2010-11-17 04:57:11 -0500 (Wed, 17 Nov 2010)
New Revision: 5136

Modified:
   portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
   portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java
Log:
- Trying to address GTNWSRP-158, GTNWSRP-161, GTNWSRP-163: 
  + Reset the ThreadLocal session holder to null when the session is closed
  + Fail if trying to close a session that wasn't held in the ThreadLocal holder (i.e. attempting to close the session from another thread)
  + Properly close the session in JCRMigrationService.

Modified: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java
===================================================================
--- portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java	2010-11-17 09:19:37 UTC (rev 5135)
+++ portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/JCRPersister.java	2010-11-17 09:57:11 UTC (rev 5136)
@@ -103,7 +103,8 @@
 
    public ChromatticSession getSession()
    {
-      if (sessionHolder.get() == null)
+      ChromatticSession chromatticSession = sessionHolder.get();
+      if (chromatticSession == null)
       {
          ChromatticSession session = chrome.openSession();
          sessionHolder.set(session);
@@ -111,13 +112,13 @@
       }
       else
       {
-         return sessionHolder.get();
+         return chromatticSession;
       }
    }
 
    public void closeSession(boolean save)
    {
-      ChromatticSession session = getSession();
+      ChromatticSession session = getOpenedSessionOrFail();
       if (save)
       {
          synchronized (this)
@@ -126,11 +127,22 @@
          }
       }
       session.close();
+      sessionHolder.set(null);
    }
 
+   private ChromatticSession getOpenedSessionOrFail()
+   {
+      ChromatticSession session = sessionHolder.get();
+      if(session == null)
+      {
+         throw new IllegalStateException("Cannot close the session as it hasn't been opened first!");
+      }
+      return session;
+   }
+
    public synchronized void save()
    {
-      getSession().save();
+      getOpenedSessionOrFail().save();
    }
 
    public <T> boolean delete(T toDelete, StoresByPathManager<T> manager)

Modified: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java
===================================================================
--- portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java	2010-11-17 09:19:37 UTC (rev 5135)
+++ portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/migration/JCRMigrationService.java	2010-11-17 09:57:11 UTC (rev 5136)
@@ -110,13 +110,20 @@
 
       ExportInfoMapping eim = session.findByPath(ExportInfoMapping.class, getPathFor(exportTime));
 
-      if (eim != null)
+      try
       {
-         return eim.toModel(null);
+         if (eim != null)
+         {
+            return eim.toModel(null);
+         }
+         else
+         {
+            return null;
+         }
       }
-      else
+      finally
       {
-         return null;
+         persister.closeSession(false);
       }
    }
 
@@ -128,6 +135,7 @@
       long exportTime = info.getExportTime();
       if (eim != null)
       {
+         persister.closeSession(false);
          throw new IllegalArgumentException("An ExportInfo with export time "
             + exportTime + " already exists!");
       }
@@ -164,6 +172,7 @@
          ChromatticSession session = persister.getSession();
          ExportInfosMapping mappings = getExportInfosMapping(session);
          exportInfosCount = mappings.getExportInfos().size();
+         persister.closeSession(false);
       }
 
       return exportInfosCount == 0;



More information about the gatein-commits mailing list