[gatein-commits] gatein SVN: r2106 - in portal/trunk/component/common/src: test/java/org/exoplatform/commons/chromattic and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Mar 10 09:23:13 EST 2010


Author: julien_viet
Date: 2010-03-10 09:23:12 -0500 (Wed, 10 Mar 2010)
New Revision: 2106

Added:
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java
Removed:
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/GlobalContext.java
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LifeCycleContext.java
Modified:
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticImpl.java
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/PortalSessionLifeCycle.java
   portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java
   portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
   portal/trunk/component/common/src/test/resources/conf/exo.portal.component.common-configuration.xml
Log:
removing LifeCycleContext to simplify a bit the chromattic / jcr integration


Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticImpl.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticImpl.java	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticImpl.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -48,7 +48,7 @@
       //
       if (sessionContext == null)
       {
-         sessionContext = configurator.openGlobalContext();
+         sessionContext = configurator.openSynchronizedContext();
       }
 
       //

Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/ChromatticLifeCycle.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -23,9 +23,12 @@
 import org.exoplatform.container.component.BaseComponentPlugin;
 import org.exoplatform.container.xml.InitParams;
 import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.jcr.core.ManageableRepository;
 import org.gatein.common.logging.Logger;
 import org.gatein.common.logging.LoggerFactory;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import java.util.*;
 
 /**
@@ -136,6 +139,20 @@
       return manager;
    }
 
+   LoginContext getLoginContext()
+   {
+      Synchronization sync = manager.getSynchronization();
+
+      //
+      if (sync != null)
+      {
+         return sync;
+      }
+
+      //
+      return currentContext.get();
+   }
+
    /**
     * Returns <code>#getContext(false)</code>.
     *
@@ -162,7 +179,7 @@
       if (sync != null)
       {
          log.trace("Found synchronization about to get the current context for chromattic " + domainName);
-         GlobalContext context = sync.getContext(domainName);
+         SynchronizedContext context = sync.getContext(domainName);
 
          //
          if (context == null && !peek)
@@ -188,22 +205,8 @@
       return localContext;
    }
 
-   LoginContext getLoginContext()
+   final SessionContext openSynchronizedContext()
    {
-      Synchronization sync = manager.getSynchronization();
-
-      //
-      if (sync != null)
-      {
-         return sync;
-      }
-
-      //
-      return currentContext.get();
-   }
-
-   final SessionContext openGlobalContext()
-   {
       log.trace("Opening a global context");
       AbstractContext context = (AbstractContext)getContext(true);
 
@@ -299,6 +302,29 @@
    {
    }
 
+   Session doLogin() throws RepositoryException
+   {
+      LoginContext loginContext = getLoginContext();
+
+      //
+      if (loginContext == null)
+      {
+         throw new IllegalStateException("Could not obtain a login context");
+      }
+
+      //
+      ManageableRepository repo = manager.repositoryService.getCurrentRepository();
+
+      //
+      Session session = repo.getSystemSession(workspaceName);
+
+      //
+      loginContext.loggedIn(session);
+
+      //
+      return session;
+   }
+
    public final void start() throws Exception
    {
       log.debug("About to setup Chromattic life cycle " + domainName);
@@ -315,7 +341,7 @@
       }
 
       // Set up boot context
-      LifeCycleContext.bootContext.set(new LifeCycleContext(this, manager, workspaceName));
+      PortalSessionLifeCycle.bootContext.set(this);
 
       //
       try
@@ -344,7 +370,7 @@
       }
       finally
       {
-         LifeCycleContext.bootContext.set(null);
+         PortalSessionLifeCycle.bootContext.set(null);
       }
    }
 

Deleted: portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/GlobalContext.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/GlobalContext.java	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/GlobalContext.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -1,40 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.commons.chromattic;
-
-/**
- * The global context is associated with a {@link org.exoplatform.commons.chromattic.Synchronization} object.
- *
- * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public class GlobalContext extends AbstractContext
-{
-
-   /** The related global synchronization when it is not null. */
-   final Synchronization synchronization;
-
-   public GlobalContext(ChromatticLifeCycle configurator, Synchronization synchronization)
-   {
-      super(configurator);
-
-      //
-      this.synchronization = synchronization;
-   }
-}

Deleted: portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LifeCycleContext.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LifeCycleContext.java	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/LifeCycleContext.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -1,74 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.commons.chromattic;
-
-import org.exoplatform.services.jcr.core.ManageableRepository;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-/**
- * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public class LifeCycleContext
-{
-
-   /** . */
-   static final ThreadLocal<LifeCycleContext> bootContext = new ThreadLocal<LifeCycleContext>();
-
-   /** . */
-   private final String workspaceName;
-
-   /** . */
-   private final ChromatticManager manager;
-
-   /** . */
-   private final ChromatticLifeCycle configurator;
-
-   public LifeCycleContext(ChromatticLifeCycle configurator, ChromatticManager manager, String repositoryName)
-   {
-      this.configurator = configurator;
-      this.manager = manager;
-      this.workspaceName = repositoryName;
-   }
-
-   public Session doLogin() throws RepositoryException
-   {
-      LoginContext loginContext = configurator.getLoginContext();
-
-      //
-      if (loginContext == null)
-      {
-         throw new IllegalStateException();
-      }
-
-      //
-      ManageableRepository repo = manager.repositoryService.getCurrentRepository();
-
-      //
-      Session session = repo.getSystemSession(workspaceName);
-
-      //
-      loginContext.loggedIn(session);
-
-      //
-      return session;
-   }
-}

Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/PortalSessionLifeCycle.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/PortalSessionLifeCycle.java	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/PortalSessionLifeCycle.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -27,23 +27,28 @@
 
 /**
  * The implementation of the {@link org.chromattic.spi.jcr.SessionLifeCycle} chromattic interface that
- * delegates all the job to a {@link org.exoplatform.commons.chromattic.LifeCycleContext} interface
- * that is obtained at build time. The life cycle context is obtained by invoking the <code>get</code> method
- * on the {@link org.exoplatform.commons.chromattic.LifeCycleContext#bootContext} thread local. That
- * thread local is setup by the {@link org.exoplatform.commons.chromattic.ChromatticLifeCycle} object
- * around the invocation of the {@link org.chromattic.api.ChromatticBuilder#build()} method.
- *
+ * delegates all the job to a {@link org.exoplatform.commons.chromattic.ChromatticLifeCycle#doLogin()} method.
+ * 
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
  */
 public class PortalSessionLifeCycle implements SessionLifeCycle
 {
+
    /** . */
-   LifeCycleContext context = LifeCycleContext.bootContext.get();
+   static final ThreadLocal<ChromatticLifeCycle> bootContext = new ThreadLocal<ChromatticLifeCycle>();
 
+   /** . */
+   private final ChromatticLifeCycle chromatticLifeCycle;
+
+   public PortalSessionLifeCycle()
+   {
+      chromatticLifeCycle = bootContext.get();
+   }
+
    public final Session login() throws RepositoryException
    {
-      return context.doLogin();
+      return chromatticLifeCycle.doLogin();
    }
 
    public void save(Session session) throws RepositoryException

Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/Synchronization.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -35,7 +35,7 @@
    private final Map<String, Session> repositorySessions = new HashMap<String, Session>();
    
    /** . */
-   private final Map<String, GlobalContext> contexts = new HashMap<String, GlobalContext>();
+   private final Map<String, SynchronizedContext> contexts = new HashMap<String, SynchronizedContext>();
 
    /** . */
    private boolean saveOnClose = true;
@@ -46,7 +46,7 @@
     * @param name the global context name
     * @return the global context or null if no such context exists
     */
-   public GlobalContext getContext(String name)
+   public SynchronizedContext getContext(String name)
    {
       if (name == null)
       {
@@ -62,19 +62,19 @@
     * @return the global context related to life cycle
     * @throws IllegalStateException if a context is already created for the specified life cycle
     */
-   public GlobalContext openContext(ChromatticLifeCycle lifeCycle) throws IllegalStateException
+   public SynchronizedContext openContext(ChromatticLifeCycle lifeCycle) throws IllegalStateException
    {
       if (lifeCycle == null)
       {
          throw new NullPointerException();
       }
       String name = lifeCycle.getDomainName();
-      GlobalContext context = contexts.get(name);
+      SynchronizedContext context = contexts.get(name);
       if (context != null)
       {
          throw new IllegalStateException();
       }
-      context = new GlobalContext(lifeCycle, this);
+      context = new SynchronizedContext(lifeCycle, this);
       contexts.put(name, context);
       lifeCycle.onOpenSession(context);
       return context;
@@ -88,7 +88,7 @@
    public void close(boolean save)
    {
       // First save all global contexts (sessions)
-      for (GlobalContext context : contexts.values())
+      for (SynchronizedContext context : contexts.values())
       {
          context.close(save);
       }

Copied: portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java (from rev 2086, portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/GlobalContext.java)
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java	                        (rev 0)
+++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/chromattic/SynchronizedContext.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -0,0 +1,40 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.commons.chromattic;
+
+/**
+ * The synchronized context is associated with a {@link org.exoplatform.commons.chromattic.Synchronization} object.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class SynchronizedContext extends AbstractContext
+{
+
+   /** The related synchronization when it is not null. */
+   final Synchronization synchronization;
+
+   public SynchronizedContext(ChromatticLifeCycle configurator, Synchronization synchronization)
+   {
+      super(configurator);
+
+      //
+      this.synchronization = synchronization;
+   }
+}

Modified: portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
===================================================================
--- portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java	2010-03-10 14:23:12 UTC (rev 2106)
@@ -38,9 +38,12 @@
 {
 
    /** . */
-   private ChromatticLifeCycle testLF;
+   private ChromatticLifeCycle test1LF;
 
    /** . */
+   private ChromatticLifeCycle test2LF;
+
+   /** . */
    private ChromatticManager chromatticManager;
 
    public ChromatticIntegrationTestCase()
@@ -52,15 +55,16 @@
    {
       PortalContainer container = PortalContainer.getInstance();
       chromatticManager = (ChromatticManager)container.getComponent(ChromatticManager.class);
-      testLF = chromatticManager.getLifeCycle("test");
+      test1LF = chromatticManager.getLifeCycle("test1");
+      test2LF = chromatticManager.getLifeCycle("test2");
    }
 
    public void testConfiguratorInitialized() throws Exception
    {
-      assertNotNull(testLF);
-      assertEquals("portal-test", testLF.getWorkspaceName());
-      assertNotNull(testLF.getChromattic());
-      assertSame(chromatticManager, testLF.getManager());
+      assertNotNull(test1LF);
+      assertEquals("portal-test", test1LF.getWorkspaceName());
+      assertNotNull(test1LF.getChromattic());
+      assertSame(chromatticManager, test1LF.getManager());
    }
 
    public void testCannotInitiateMoreThanOneRequest()
@@ -98,7 +102,7 @@
    {
       try
       {
-         testLF.getChromattic().openSession();
+         test1LF.getChromattic().openSession();
          fail();
       }
       catch (IllegalStateException e)
@@ -111,10 +115,10 @@
       Session jcrSession;
 
       //
-      SessionContext context = testLF.openContext();
+      SessionContext context = test1LF.openContext();
       try
       {
-         ChromatticSession session = testLF.getChromattic().openSession();
+         ChromatticSession session = test1LF.getChromattic().openSession();
          FooEntity foo = session.create(FooEntity.class);
          assertEquals("portal-test", foo.getWorkspace());
          jcrSession = session.getJCRSession();
@@ -127,7 +131,7 @@
       }
       finally
       {
-         testLF.closeContext(false);
+         test1LF.closeContext(false);
       }
 
       // Assert JCR session was properly closed
@@ -136,8 +140,8 @@
 
    public void testLocalRequestNoSessionAccess()
    {
-      SessionContext context = testLF.openContext();
-      testLF.closeContext(false);
+      SessionContext context = test1LF.openContext();
+      test1LF.closeContext(false);
    }
 
    public void testGlobalSession() throws Exception
@@ -151,16 +155,16 @@
       chromatticManager.beginRequest();
       try
       {
-         Chromattic chromattic = testLF.getChromattic();
+         Chromattic chromattic = test1LF.getChromattic();
 
          // No context should be open
-         assertNull(testLF.getContext(true));
+         assertNull(test1LF.getContext(true));
 
          // Opens a session with the provided Chromattic
          ChromatticSession session = chromattic.openSession();
 
          // Now we should have a context
-         SessionContext context = testLF.getContext(true);
+         SessionContext context = test1LF.getContext(true);
          assertNotNull(context);
 
          // Register synchronzation with event queue
@@ -201,11 +205,11 @@
       chromatticManager.beginRequest();
       try
       {
-         SessionContext context = testLF.getContext(true);
+         SessionContext context = test1LF.getContext(true);
          assertNull(context);
 
          //
-         context = testLF.getContext(false);
+         context = test1LF.getContext(false);
          assertNotNull(context);
       }
       finally
@@ -217,20 +221,31 @@
    public void testPersistence() throws Exception {
 
       chromatticManager.beginRequest();
-      ChromatticSession session = testLF.getChromattic().openSession();
+      ChromatticSession session = test1LF.getChromattic().openSession();
       FooEntity foo = session.create(FooEntity.class);
       String fooId = session.persist(foo, "testPersistence");
       session.save();
       chromatticManager.endRequest(true);
 
       chromatticManager.beginRequest();
-      session = testLF.getChromattic().openSession();
+      session = test1LF.getChromattic().openSession();
       foo = session.findById(FooEntity.class, fooId);
       session.close();
       chromatticManager.endRequest(false);
 
       assertNotNull(foo);
+   }
 
+   public void testTwoLifeCycleWithSameRepository() {
+      chromatticManager.beginRequest();
+
+      SessionContext ctx1 = test1LF.openContext();
+      Session session1 = ctx1.getSession().getJCRSession();
+      SessionContext ctx2 = test2LF.openContext();
+      Session session2 = ctx2.getSession().getJCRSession();
+//      assertSame(session1, session2);
+
+      chromatticManager.endRequest(false);
    }
 
 }

Modified: portal/trunk/component/common/src/test/resources/conf/exo.portal.component.common-configuration.xml
===================================================================
--- portal/trunk/component/common/src/test/resources/conf/exo.portal.component.common-configuration.xml	2010-03-10 14:20:33 UTC (rev 2105)
+++ portal/trunk/component/common/src/test/resources/conf/exo.portal.component.common-configuration.xml	2010-03-10 14:23:12 UTC (rev 2106)
@@ -27,6 +27,7 @@
     <key>org.exoplatform.commons.chromattic.ChromatticManager</key>
     <type>org.exoplatform.commons.chromattic.ChromatticManager</type>
   </component>
+
   <external-component-plugins>
     <target-component>org.exoplatform.commons.chromattic.ChromatticManager</target-component>
     <component-plugin>
@@ -36,7 +37,7 @@
       <init-params>
         <value-param>
           <name>domain-name</name>
-          <value>test</value>
+          <value>test1</value>
         </value-param>
         <value-param>
           <name>workspace-name</name>
@@ -48,5 +49,24 @@
         </values-param>
       </init-params>
     </component-plugin>
+    <component-plugin>
+      <name>chromattic</name>
+      <set-method>addLifeCycle</set-method>
+      <type>org.exoplatform.commons.chromattic.ChromatticLifeCycle</type>
+      <init-params>
+        <value-param>
+          <name>domain-name</name>
+          <value>test2</value>
+        </value-param>
+        <value-param>
+          <name>workspace-name</name>
+          <value>portal-test</value>
+        </value-param>
+        <values-param>
+          <name>entities</name>
+        </values-param>
+      </init-params>
+    </component-plugin>
   </external-component-plugins>
+
 </configuration>



More information about the gatein-commits mailing list