Reputation: 55
I want to use oak in my project as embedded.For a start I wrote a test method. In my method I use the same code from this example here https://jackrabbit.apache.org/oak/docs/construct.html The code runs just fine but it does not terminate unless I shutdown repository:
((RepositoryImpl) repo).shutdown();
So in my project, not for the first time but ever time when I want to connect to repository I call
mongoClient = new MongoClient(host, port);
DB db = mongoClient.getDB(dbName);
Builder builder = new DocumentMK.Builder();
builder.setMongoDB(db);
ns = builder.getNodeStore();
Oak oak = new Oak(ns);
Jcr jcr = new Jcr(oak);
repo = jcr.createRepository();
try {
session = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
}
catch (LoginException e) {
...
}
and in the end
session.logout();
((RepositoryImpl) repo).shutdown();
ns.dispose();
mongoClient.close();
Do I have to call createRepository() every time or just for the first time and then use another method to connect repository.
Is shuting down the repository needed?
Upvotes: 1
Views: 342
Reputation: 63
Do I have to call createRepository() every time or just for the first time and then use another method to connect repository.
You will have to create the repository for the first time and use the same for login thereon, provided you keep the repository object. In case you lose the repository, as in you shut down, you will have to start from the beginning.
Is shutting down the repository needed?
As given in the documentation, we need to do this for releasing the resources and persisting changes if any.
Upvotes: 1