Page tree
Skip to end of metadata
Go to start of metadata

Introduction

As of Dec 2016, Magnolia CMS has just released our latest version 5.5.0 using Jackrabbit 2.12.4 which is supporting traditional familiar DBMS including Derby, H2, Oracle, Ingres, MySQL, Postgres and MSSQL. There were requests for feature that support Magnolia CMS using MongoDB as its persistence manager.

Since Magnolia mostly depend on Jackrabbit implementation for its persistence manager, only provided version from this documentation were officially supported. Moreover, MongoDB is a NoSQL solution which is, in some aspects, conflict with our traditional RDBMS above.

In order to integrate MongoDB into existing Magnolia CMS, we need to do some tweak and have an adaptor which could 'mediate between two warring sides'. Luckily Jackrabbit 2.x already supported JNDI originally and also we have a stable release of JDBC for MongoDB called JDBC Driver for MongoDB®. I will walk you through our configuration steps of 'our court of conciliation'.

Steps

Prerequisite

Sure we need our 'mgnldb' database with 'myUserAdmin' as username and 'abc123' as password:

use mgnldb
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)


Configuring JNDI for Magnolia CMS on Tomcat 8

A datasource in Tomcat 8 'context.xml' is needed to be configured:

<Resource name="magnolia" auth="Container" type="javax.sql.DataSource"

               maxTotal="100" maxIdle="30" maxWaitMillis="10000"

               username="myUserAdmin" password="abc123" driverClassName="mongodb.jdbc.MongoDriver"

               url="jdbc:mongo://localhost:27017/mgnldb"/>

Then a resource reference in your webapp 'web.xml' file is needed as below:

<resource-ref>

      <description>DB Connection</description>

      <res-ref-name>magnolia</res-ref-name>

      <res-type>javax.sql.DataSource</res-type>

      <res-auth>Container</res-auth>

  </resource-ref>

* Reference to official tomcat 8 JNDI Datasource configuration for more detail and advanced use case.

Configure our repository configuration to use provided JNDI datasource

Sample file in repo-config directory (webapp/WEB-INF/config/repo-conf/jackrabbit-bundle-mongo-search.xml):

jackrabbit-bundle-mongo-search.xml

The point is instead of using provided 'out of the box' implementation from Jackrabbit for dedicated database system, we changed to use a 'generic' one 

org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager and configure it to use our existing container based datasource (JNDI) for example:

<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager">

      <param name="driver" value="javax.naming.InitialContext"/>

      <param name="url" value="java:comp/env/magnolia"/>

      <param name="schemaCheckEnabled" value="false"/>

      <param name="schema" value="mgnldb"/>

      <param name="schemaObjectPrefix" value="pm_${wsp.name}_" />

    </PersistenceManager>

* A small note is that I just disabled 'schemaCheckEnabled' flag to work around a minor bug during Jackrabbit initiation stage. TODO: fix this.

Update your 'webapp/WEB-INF/config/default/magnolia.properties' file to use our created repository config and check your result after successfully bring up your Magnolia instance in our 'About' app.

Verify the result

Hope this helps!

 

  • No labels