Author: mputz
Date: 2012-11-22 12:06:12 -0500 (Thu, 22 Nov 2012)
New Revision: 8968
Modified:
epp/portal/branches/EPP_5_2_1_GA_BZ879258/wsrp-integration/extension-component/src/main/java/org/gatein/integration/wsrp/jcr/JCRPersister.java
Log:
Bug 879341 - Backport of commit 8966 to fix JCRPersister
Modified:
epp/portal/branches/EPP_5_2_1_GA_BZ879258/wsrp-integration/extension-component/src/main/java/org/gatein/integration/wsrp/jcr/JCRPersister.java
===================================================================
---
epp/portal/branches/EPP_5_2_1_GA_BZ879258/wsrp-integration/extension-component/src/main/java/org/gatein/integration/wsrp/jcr/JCRPersister.java 2012-11-22
16:10:39 UTC (rev 8967)
+++
epp/portal/branches/EPP_5_2_1_GA_BZ879258/wsrp-integration/extension-component/src/main/java/org/gatein/integration/wsrp/jcr/JCRPersister.java 2012-11-22
17:06:12 UTC (rev 8968)
@@ -23,30 +23,20 @@
package org.gatein.integration.wsrp.jcr;
-import org.chromattic.api.Chromattic;
import org.chromattic.api.ChromatticBuilder;
-import org.chromattic.api.ChromatticSession;
import org.chromattic.api.format.FormatterContext;
import org.chromattic.api.format.ObjectFormatter;
import org.chromattic.spi.jcr.SessionLifeCycle;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.container.component.ComponentRequestLifecycle;
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.ext.common.SessionProvider;
-import org.gatein.common.util.ParameterValidation;
import org.gatein.wsrp.jcr.BaseChromatticPersister;
-import org.gatein.wsrp.jcr.mapping.BaseMapping;
import javax.jcr.Credentials;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -76,12 +66,12 @@
}
}
- public static class WSRPSessionLifeCycle implements SessionLifeCycle
+ public static abstract class AbstractSessionLifeCycle implements SessionLifeCycle
{
private ManageableRepository repository;
- private SessionProvider provider;
+ private ThreadLocal<SessionProvider> provider = new
ThreadLocal<SessionProvider>();
- public WSRPSessionLifeCycle()
+ public AbstractSessionLifeCycle()
{
try
{
@@ -93,15 +83,22 @@
{
throw new RuntimeException(e);
}
-
- provider = SessionProvider.createSystemProvider();
}
public Session login() throws RepositoryException
{
- return provider.getSession(WSRP_WORKSPACE_NAME, repository);
+ SessionProvider sessionProvider = provider.get();
+ if (sessionProvider == null)
+ {
+ sessionProvider = SessionProvider.createSystemProvider();
+ provider.set(sessionProvider);
+ }
+
+ return sessionProvider.getSession(getWorkspaceName(), repository);
}
+ protected abstract String getWorkspaceName();
+
public Session login(String s) throws RepositoryException
{
throw new UnsupportedOperationException();
@@ -128,56 +125,22 @@
}
}
- public static class PortletStatesSessionLifeCycle implements SessionLifeCycle
+ public static class WSRPSessionLifeCycle extends AbstractSessionLifeCycle
{
- private ManageableRepository repository;
- private SessionProvider provider;
-
- public PortletStatesSessionLifeCycle()
+ @Override
+ protected String getWorkspaceName()
{
- try
- {
- ExoContainer container = ExoContainerContext.getCurrentContainer();
- RepositoryService repoService =
(RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
- repository = repoService.getRepository(REPOSITORY_NAME);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
-
- provider = SessionProvider.createSystemProvider();
+ return WSRP_WORKSPACE_NAME;
}
+ }
- public Session login() throws RepositoryException
+ public static class PortletStatesSessionLifeCycle extends AbstractSessionLifeCycle
+ {
+ @Override
+ protected String getWorkspaceName()
{
- return provider.getSession(PORTLET_STATES_WORKSPACE_NAME, repository);
+ return PORTLET_STATES_WORKSPACE_NAME;
}
-
- public Session login(String s) throws RepositoryException
- {
- throw new UnsupportedOperationException();
- }
-
- public Session login(Credentials credentials, String s) throws RepositoryException
- {
- throw new UnsupportedOperationException();
- }
-
- public Session login(Credentials credentials) throws RepositoryException
- {
- throw new UnsupportedOperationException();
- }
-
- public void save(Session session) throws RepositoryException
- {
- session.save();
- }
-
- public void close(Session session)
- {
- session.logout();
- }
}
public static class QNameFormatter implements ObjectFormatter
@@ -245,4 +208,4 @@
return s.replace(SLASH, SLASH_REPLACEMENT);
}
}
-}
+}
\ No newline at end of file
Show replies by date