Created

Dec 16, 2013

Starting with Apache Oak

Posted by Odyssée Tremoulis

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.

Let’s start!

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[1] (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 [2].

The next step is to create the repository. I’m using the Jcr class [3] 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();

rootNode.addNode("oakrocks", NodeType.NT_UNSTRUCTURED);

session.save();

Using a tool like MongoHub (on MacOS, for others see MongoDB website [4])

MongoDB viewer

COMMENTS

  • By Dịch Vụ seo Top - 8:03 AM on Dec 17, 2013   Reply
    Starting with Apache Oak gives users significant benefits.We can store content more details.In the future, it can be developed perfectly.
  • By Dịch Vụ Seo số 1 - 8:09 AM on Dec 17, 2013   Reply
    With developing of the modern life, the high-technology is more and more expand.And ,Apache Oak applications appear to respond customer's demand.
    • By Dich Vu Seo - 9:28 AM on Dec 19, 2013   Reply
      I look forward to seeing your mobile marketing strategies in next artical.Thank you very much!
      • By qlirim - 10:22 PM on Dec 20, 2013   Reply
        http://www.10minuta.com/video/gezuar-2014
        Gezuar 2014
        Ketu do te gjeni video te humorit shqip si dhe muzika shqip per vitin 2014
        • By rao vặt miễn phí - 7:34 AM on Jan 03, 2014   Reply
          Oak works internally, how nodes are stored in MongoDB and how it can prove a good start for a POC focused on scalability.

          ADD A COMMENT