What we do is to have a service class RepositoryService, which has
an @Autowired Repository oakRepository which will be created with that bean
method in the RepositoryConfiguration class. The RepositoryService class
then has a method which you use when you want to access the repository;

public Session getSession() throws RepositoryException {
  return oakRepository.login(new SimpleCredentials(ADMIN_USER,
ADMIN_USER.toCharArray()));
}

Then make sure you log out the session after use like

 public void someMethod() throws ContentException {
        Session session = null;
        try {
            session = repositoryService.getSession();

            Node node = session.getNodeByIdentifier(id);
            ...

        } catch (RepositoryException e) {
            LOG.error("unable to xxx; ", e);
            throw new IOException("unable to xxx; ", e);
        } finally {
            if (session != null) {
                session.logout();
            }
        }
    }

Also, your RepositoryConfiguration class should implement DisposableBean
and have a method like

@Override
    public void destroy() {
        LOG.info("closing repository");
        if (oakRepository != null) {
            ((RepositoryImpl)oakRepository).shutdown();
            oakRepository = null;
        }
        if (documentNodeStore != null) {
            documentNodeStore.dispose();
        }
        if (mongoClient != null) {
            mongoClient.close();
        }
    }

so that it closes down the mongodb connection.


On 6 April 2017 at 20:57, techie2k <developer.spr...@gmail.com> wrote:

> Thanks for the update.
>
> I got answer partially. Every time I cannot call, createRepository method
> to
> get Repository.
>
> First time, create repository is fine, If I restart MongoDB server or
> Tomcat
> Server, again calling createRepository is  incorrect, I suppose. Already
> repository is all set, why should I call to createRepository to access
> repository?
>
>
>
> --
> View this message in context: http://jackrabbit.510166.n4.
> nabble.com/ContentRepository-handle-tp4666696p4666702.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>



-- 
-Tor

Reply via email to