Jackrabbit Persistence
Out-of-the-box the embedded Jackrabbit repository used by Sling (the Embedded Jackrabbit Repository bundle) uses Derby to persist the JCR nodes and properties. For some applications or environments it may be required or required to replace Derby with another backing store such as PostgreSQL or Oracle.
This page is based on the journey of Tony Giaccone to get Sling running with a PostgreSQL based Jackrabbit instance.
Management Summary
To replace Derby as the persistence manager for Jackrabbit the following steps are required:
- Provide a JDBC driver for your database as an OSGi bundle
- Reconfigure Jackrabbit to use your database
- (Re-) Start the Embedded Jackrabbit bundle
When you are not using the Derby persistence manager, you may safely remove the Derby bundle from your Sling instance.
JDBC Driver
The hardest thing to do is probably getting the JDBC driver for your database. One option is to look at the bundles provided by Spring Source in their repository at http://www.springsource.com/repository/.
Another option is to create the bundle on your own using Peter Kriens' BND Tool:
- Get the JDBC driver for your database from the driver provider
- Wrap the JDBC driver library into an OSGi bundle:
# Example for PostgreSQL JDBC 3 driver 8.4-701
$ java -jar bnd.jar wrap postgresql-8.4-701.jdbc3.jar
$ mv postgresql-8.4-701.jdbc3.bar postgresql-8.4-701.jdbc3-bnd.jar
- Deploy the driver to your local Maven 2 Repository (Required if adding the JDBC driver to the Sling build)
$ mvn install:install-file -DgroupId=postgresql -DartifactId=postgresql -Dversion=8.4.701.jdbc3 \
-Dpackaging=jar -Dfile=postgresql-8.4-701.jdbc3-bnd.jar
Tony reports no success with the Spring Source bundle, whily the BND approach worked for the PostgreSQL JDBC driver.
Replace Derby in a running Sling Instance
To replace Derby in a running Sling instance just uninstall the Derby bundle and install the JDBC driver bundle through the Web Console (at /system/console.
Replace Derby in the Sling Build
To replace Derby (included with Sling by default) with the new JDBC driver, the bundle list file src/main/bundles/list.xml of the Sling Launchpad Builder project can be modified.
Look for the Derby database section:
<bundle>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.5.3.0_1</version>
</bundle>
and replace this section by the Maven 2 reference to your JDBC driver.
For example, for the PostgreSQL JDBC driver bundle prepared in the prepared in the previous step replace the Derby reference with this:
<bundle>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4.701.jdbc3</version>
</bundle>
Reconfiguring Jackrabbit
Two options:
- Reconfigure after first startup
- Reconfigure build
Credits
This description is based on Tony Giaccone's description Swapping Postgres for Derby sent to the Sling Users mailing list.