In this post, I’ll explain how to store con­tent with Apache Oak over Mon­goDB. It can be use­ful to under­stand how Apache Oak works inter­nally, how nodes are stored in Mon­goDB and how it can prove a good start for a POC focused on scalability.

With the evo­lu­tion of needs in user expec­ta­tions, appli­ca­tions archi­tec­ture and hard­ware design, Apache Oak has been devel­oped on top of Apache Jackrab­bit to answer to these demands (for more infor­ma­tion about Apache Jackrab­bit con­tent repos­i­tory imple­men­ta­tion, see http://​jackrab​bit​.apache​.org)

Apache Oak allows imple­ment­ing scal­able and per­for­mant hier­ar­chi­cal con­tent repos­i­tory over a stor­age sys­tem like Mon­goDB, TarPM, In Mem­ory or sim­ply on the file system.

Let’s start!

Oak can be started through the com­mand line that offers dif­fer­ent launch options:

  • With a Micro­Ker­nel (for Mongo based deployment)
  • To run a benchmark
  • On a server mode
  • For an upgrade
  • For a backup
  • With TarMK (for stand­alone and per­for­mant deployment)

In this exam­ple we’ll use Mon­goDB micro­ker­nel. I’ll assume you have one already run­ning on your local­host on port 27017.

The first step is to cre­ate a con­nec­tion to Mon­goDB using the java dri­ver pro­vided 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 inter­est­ing part: the Mon­goDB Micro­ker­nel (MongoMK)

MongoMK.Builder m = new MongoMK.Builder();

MongoMK kernel = m.setMongoDB(db).open();

The Micro­ker­nel is the main class that man­ages the trees of nodes and pro­vides much more func­tion­al­ity. You can find a good descrip­tion of the design goals and prin­ci­ples on the Javadoc of this class [2].

The next step is to cre­ate the repos­i­tory. I’m using the Jcr class [3] to keep the code sim­ple as this class help to ini­tial­ize a lot of Oak’s parameters.

Repository repo = new Jcr(kernel).createRepository();

Which is the same code as…

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

…with­out para­me­ters initialization.

And finally our last step is the com­mon code that you can rec­og­nize if you already used Jackrab­bit (open a ses­sion, get a node, cre­ate a new one and save):

Ses­sion ses­sion = repo.login(new SimpleCredentials(“admin”, “admin”.toCharArray()));

Node rootN­ode =  session.getRootNode();

rootNode.addNode(“oakrocks”, Node­Type.NT_UNSTRUCTURED);

session.save();

Using a tool like Mon­go­Hub (on MacOS, for oth­ers see Mon­goDB web­site [4])

For more infor­ma­tion, see:

Oak overview: http://​jackrab​bit​.apache​.org/​o​a​k​/​d​o​c​s​/​i​n​d​e​x​.​h​tml

OAK API: http://​jackrab​bit​.apache​.org/​o​a​k​/​d​o​c​s​/​a​p​i​d​o​c​s​/​i​n​d​e​x​.​h​tml

[1] http://​docs​.mon​godb​.org/​e​c​o​s​y​s​t​e​m​/​d​r​i​v​e​r​s​/​j​a​va/

[2] http://​jackrab​bit​.apache​.org/​o​a​k​/​d​o​c​s​/​a​p​i​d​o​c​s​/​o​r​g​/​a​p​a​c​h​e​/​j​a​c​k​r​a​b​b​i​t​/​m​k​/​a​p​i​/​M​i​c​r​o​K​e​r​n​e​l​.​h​tml

[3] org.apache.jackrabbit.oak.jcr.Jcr.class

[4] http://​docs​.mon​godb​.org/​e​c​o​s​y​s​t​e​m​/​t​o​o​l​s​/​a​d​m​i​n​i​s​t​r​a​t​i​o​n​-​i​n​t​e​r​f​a​c​es/