In this post, I’ll explain how to store content with Apache Oak over MongoDB. It can be useful to understand how Apache Oak works internally, how nodes are stored in MongoDB and how it can prove a good start for a POC focused on scalability.
With the evolution of needs in user expectations, applications architecture and hardware design, Apache Oak has been developed on top of Apache Jackrabbit to answer to these demands (for more information about Apache Jackrabbit content repository implementation, see http://jackrabbit.apache.org)
Apache Oak allows implementing scalable and performant hierarchical content repository over a storage system like MongoDB, TarPM, In Memory or simply on the file system.
Oak can be started through the command line that offers different launch options:
- With a MicroKernel (for Mongo based deployment)
- To run a benchmark
- On a server mode
- For an upgrade
- For a backup
- With TarMK (for standalone and performant deployment)
In this example we’ll use MongoDB microkernel. I’ll assume you have one already running on your localhost on port 27017.
The first step is to create a connection to MongoDB using the java driver provided by MongoDB (with some help of Oak tools):
MongoConnection connection = new MongoConnection("127.0.0.1", 27017, "Adobe-MongoDB");
DB db = connection.getDB();
Then, the interesting part: the MongoDB Microkernel (MongoMK)
MongoMK.Builder m = new MongoMK.Builder();
MongoMK kernel = m.setMongoDB(db).open();
The Microkernel is the main class that manages the trees of nodes and provides much more functionality. You can find a good description of the design goals and principles on the Javadoc of this class .
The next step is to create the repository. I’m using the Jcr class  to keep the code simple as this class help to initialize a lot of Oak’s parameters.
Repository repo = new Jcr(kernel).createRepository();
Which is the same code as…
Repository repo = new Oak(kernel).createRepository();
…without parameters initialization.
And finally our last step is the common code that you can recognize if you already used Jackrabbit (open a session, get a node, create a new one and save):
Session session = repo.login(new SimpleCredentials(“admin”, “admin”.toCharArray()));
Node rootNode = session.getRootNode();
Using a tool like MongoHub (on MacOS, for others see MongoDB website )
For more information, see: