-
1. Re: Using exo jcr as common data storage
g_sebert Apr 9, 2010 5:09 AM (in response to hauch)Hi,
We are currently using the gatein JCR to store bussiness data from our portlet.
This is some hints to do it:
- For jcr configuration, we create a new workspace in the default repository (you can also create a new repository) to store data.
The config file for jcr is repository-configuration.xml file located in gatein.ear/02portal.war/web-inf/conf/jcr.
Just take a existing workspace as template to create a new one.
- To access to the JCR from your portlet :
import javax.jcr.RepositoryException;
import javax.jcr.Session;import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.ext.app.SessionProviderService;
public class testJCRConnection {
/** WORK_SPACE_NAME */
private static final String WORK_SPACE_NAME = "myworkspace";/** repositoryService */
private RepositoryService repositoryService;
/** repository */
private ManageableRepository repository;
/** session */
private Session session;
/** session provider*/
private SessionProviderService sessionProviderService ;
public void connectRepository(String repositoryName)
{try {
ExoContainer container = new ExoContainer();
container = ExoContainerContext.getCurrentContainer();
repositoryService = (RepositoryService) container
.getComponentInstanceOfType(RepositoryService.class);
repository = repositoryService.getRepository(repositoryName);
sessionProviderService = (SessionProviderService) container
.getComponentInstanceOfType(SessionProviderService.class);
session = sessionProviderService.getSessionProvider(null).getSession(
WORK_SPACE_NAME, repository);
//Do your JCR JOB} catch (RepositoryException e) {
e.printStackTrace();} catch (RepositoryConfigurationException e) {
e.printStackTrace();
} finally {
if (session != null)
session.logout();
}
}}
Regards,
Grégory
-
2. Re: Using exo jcr as common data storage
claprun Apr 9, 2010 7:42 AM (in response to g_sebert)You could also look into Chromattic to help with dealing with JCR: http://code.google.com/p/chromattic/
-
3. Re: Using exo jcr as common data storage
hauch Apr 14, 2010 9:32 AM (in response to g_sebert)Thanks a lot. This was very helpfull.
Unfortunately I am unable to get a SessionProvider using:
session = sessionProviderService.getSessionProvider(null);
I guess the reason might be that the repository is secured - and the gateIn user is not propagated to this context (and in my understanding the method above uses current user (null)).
So my next question is:
How can I get my gateIn/JAAS user propagated to the exo jcr context?
Any help is appreciated.
/Morten
-
4. Re: Using exo jcr as common data storage
hauch Apr 15, 2010 8:44 AM (in response to hauch)This did it:
SessionProvider sp = new SessionProvider(ConversationState.getCurrent()); -
5. Re: Using exo jcr as common data storage
g_sebert Apr 15, 2010 9:23 AM (in response to hauch)Yes, sorry for the mistake in the sample code.