How to create repository instance in JackRabbit Oak using MicroKernel

半腔热情 提交于 2019-12-24 02:25:07

问题


According to JackRabbit Oak official documentation, one of the ways of creating Repository instance is to create a MicroKernel object and pass it to JCR's parameterized constructor like this:

MicroKernel kernel = ...;
Repository repository = new Jcr(kernel).createRepository();

But looking at the JCR class javadocs, i can't find any constructor which takes an object of type MicroKernel.
So my questions is :

  • How can we get a repository object using MicroKernel in JackRabbit Oak(not JackRabbit 2.0).

Note: I want a repository which uses normal file system as the content storage medium.


回答1:


The documentations is unfortunately lagging behind in some areas. The MicroKernel interface has been superseded by the NodeStoreinterface in Oak.

For file system persistence you'd use the SegmentNodeStore. Have a look at how the respective test cases set up the repository.

In a nutshell:

File directory = ...
NodeStore store = new FileStore(directory, 1, false);
Jcr jcr = new Jcr(new Oak(new SegmentNodeStore(store)));



回答2:


Try to use the MicroKernelImpl public no-arg constructor to create an in-memory kernel instance:

MicroKernel kernel = new MicroKernelImpl();
Repository repository = new Jcr(kernel).createRepository();

Alternativelly, you can use the OAK class entry to create a Repository:

MicroKernel kernel = new MicroKernelImpl();
Repository repo = new Oak(kernel).createRepository();


来源:https://stackoverflow.com/questions/25681933/how-to-create-repository-instance-in-jackrabbit-oak-using-microkernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!