incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Sling Website > Jackrabbit Persistence
Date Tue, 15 Jun 2010 08:25:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Jackrabbit+Persistence">Jackrabbit
Persistence</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
        <br/>
                         <h4>Changes (15)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >$ mv postgresql-8.4-701.jdbc3.bar
postgresql-8.4-701.jdbc3-bnd.jar <br>{code} <br></td></tr>
            <tr><td class="diff-changed-lines" ># Deploy the driver to your local
Maven 2 Repository (Required if adding the JDBC driver to <span class="diff-added-words"style="background-color:
#dfd;">a Maven build, e.g. using</span> the Sling <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">build)</span>
<span class="diff-added-words"style="background-color: #dfd;">Launchpad Plugin)</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br>$ mvn install:install-file
-DgroupId=postgresql -DartifactId=postgresql -Dversion=8.4.701.jdbc3 \ <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h2. Replace Derby in a running Sling
Instance <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">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}}). <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">To
replace Derby in a running Sling instance follow these steps (e.g. through the Web Console
at {{/system/console}}): <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
# Uninstall the Apache Derby bundle <br> # Install the JDBC bundle prepared in the first
step <br> # Stop the Jackrabbit Embedded Repository bundle\ <br>This needs to
be reconfigured and restarted anyway. So lets just stop it to prevent failures in the next
step. <br> # Refresh the packages (click the _Refresh Packages_ button) <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h2.
Replace Derby in the Sling Build <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Alternatively,
you may wish to stop Sling after uninstalling Derby and installing the JDBC bundle. Technically,
this is not required, though. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">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. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Look
for the Derby database section: <br> <br>{code} <br>&lt;bundle&gt;
<br>    &lt;groupId&gt;org.apache.derby&lt;/groupId&gt; <br> 
  &lt;artifactId&gt;derby&lt;/artifactId&gt; <br>    &lt;version&gt;10.5.3.0_1&lt;/version&gt;
<br>&lt;/bundle&gt; <br>{code} <br> <br>and replace this section
by the Maven 2 reference to your JDBC driver. <br> <br>For example, for the PostgreSQL
JDBC driver bundle prepared in the prepared in the previous step replace the Derby reference
with this: <br> <br>{code} <br>&lt;bundle&gt; <br>    &lt;groupId&gt;postgresql&lt;/groupId&gt;
<br>    &lt;artifactId&gt;postgresql&lt;/artifactId&gt; <br> 
  &lt;version&gt;8.4.701.jdbc3&lt;/version&gt; <br>&lt;/bundle&gt;
<br>{code} <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Reconfiguring Jackrabbit <br>
<br></td></tr>
            <tr><td class="diff-changed-lines" >To actually use a persistence
manager other than the default (Derby) persistence manager, you have to configure Jackrabbit
to use it. <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">There
are two options: You can modify the build or you can create</span> <span class="diff-added-words"style="background-color:
#dfd;">Create</span> a {{repository.xml}} file in the {{sling/jackrabbit}} folder
before starting Sling for the first time. <span class="diff-added-words"style="background-color:
#dfd;">If the repository was already started, you can also modify the existing file.</span>
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h3.
Prepare repository.xml File <br> <br></td></tr>
            <tr><td class="diff-unchanged" >To prepare a repository.xml file before
first startup, use the {{[repository.xml|http://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/jackrabbit-server/src/main/resources/repository.xml]}}
as a template and modify it by replacing the {{&lt;PersistenceManager&gt;}} elements
to refer to the selected persistence manager. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If
the file already exists, you can modifiy this existing file and there is no need to get the
original from the SVN repository. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >For example to use PostgreSQL instead
of Derby modify the {{&lt;PersistenceManager&gt;}} elements as follows: <br>
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Modify the {{url}}, {{user}}, and
{{password}} parameters to match your database setup. <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If
you reconfigure Jackrabbit to use the new persistence manager, the existing repository data
in the {{sling/jackrabbit}} directory, except the {{repository.xml}} file, of course, should
now be removed. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h3.
Modify the Build <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">Finally
either start Sling or start the Jackrabbit Embedded Repository bundle. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">To
modify the build apply above changes directly to the {{src/main/resources/repository.xml}}
file in the Embedded Jackrabbit Server bundle source. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Credits <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="JackrabbitPersistence-JackrabbitPersistence"></a>Jackrabbit
Persistence</h1>

<p>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.</p>

<p>This page is based on the journey of Tony Giaccone to get Sling running with a PostgreSQL
based Jackrabbit instance.</p>


<h2><a name="JackrabbitPersistence-ManagementSummary"></a>Management Summary</h2>

<p>To replace Derby as the persistence manager for Jackrabbit the following steps are
required:</p>

<ol>
	<li>Provide a JDBC driver for your database as an OSGi bundle</li>
	<li>Reconfigure Jackrabbit to use your database</li>
	<li>(Re-) Start the Embedded Jackrabbit bundle</li>
</ol>


<p>When you are not using the Derby persistence manager, you may safely remove the Derby
bundle from your Sling instance.</p>


<h2><a name="JackrabbitPersistence-JDBCDriver"></a>JDBC Driver</h2>

<p>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 <a href="http://www.springsource.com/repository/"
class="external-link" rel="nofollow">http://www.springsource.com/repository/</a>.</p>

<p>Another option is to create the bundle on your own using Peter Kriens' <a href="http://www.aqute.biz/Code/Bnd"
class="external-link" rel="nofollow">BND Tool</a>:</p>

<ol>
	<li>Get the JDBC driver for your database from the driver provider</li>
	<li>Wrap the JDBC driver library into an OSGi bundle:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
# Example <span class="code-keyword">for</span> 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
</pre>
</div></div></li>
	<li>Deploy the driver to your local Maven 2 Repository (Required if adding the JDBC
driver to a Maven build, e.g. using the Sling Launchpad Plugin)
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
$ mvn install:install-file -DgroupId=postgresql -DartifactId=postgresql -Dversion=8.4.701.jdbc3
\
		-Dpackaging=jar -Dfile=postgresql-8.4-701.jdbc3-bnd.jar 
</pre>
</div></div></li>
</ol>


<p>Tony reports no success with the Spring Source bundle, whily the BND approach worked
for the PostgreSQL JDBC driver.</p>


<h2><a name="JackrabbitPersistence-ReplaceDerbyinarunningSlingInstance"></a>Replace
Derby in a running Sling Instance</h2>

<p>To replace Derby in a running Sling instance follow these steps (e.g. through the
Web Console at <tt>/system/console</tt>):</p>

<ol>
	<li>Uninstall the Apache Derby bundle</li>
	<li>Install the JDBC bundle prepared in the first step</li>
	<li>Stop the Jackrabbit Embedded Repository bundle\<br/>
This needs to be reconfigured and restarted anyway. So lets just stop it to prevent failures
in the next step.</li>
	<li>Refresh the packages (click the <em>Refresh Packages</em> button)</li>
</ol>


<p>Alternatively, you may wish to stop Sling after uninstalling Derby and installing
the JDBC bundle. Technically, this is not required, though.</p>


<h2><a name="JackrabbitPersistence-ReconfiguringJackrabbit"></a>Reconfiguring
Jackrabbit</h2>

<p>To actually use a persistence manager other than the default (Derby) persistence
manager, you have to configure Jackrabbit to use it. Create a <tt>repository.xml</tt>
file in the <tt>sling/jackrabbit</tt> folder before starting Sling for the first
time. If the repository was already started, you can also modify the existing file.</p>

<p>To prepare a repository.xml file before first startup, use the <tt><a href="http://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/jackrabbit-server/src/main/resources/repository.xml"
class="external-link" rel="nofollow">repository.xml</a></tt> as a template
and modify it by replacing the <tt>&lt;PersistenceManager&gt;</tt> elements
to refer to the selected persistence manager.</p>

<p>If the file already exists, you can modifiy this existing file and there is no need
to get the original from the SVN repository.</p>

<p>For example to use PostgreSQL instead of Derby modify the <tt>&lt;PersistenceManager&gt;</tt>
elements as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;Repository&gt;
    ...
    &lt;Workspace name=<span class="code-quote">"${wsp.name}"</span>&gt;
        ...
        &lt;PersistenceManager class=<span class="code-quote">"org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager"</span>&gt;
            &lt;param name=<span class="code-quote">"driver"</span> value=<span
class="code-quote">"org.postgresql.Driver"</span>/&gt;
            &lt;param name=<span class="code-quote">"url"</span> value=<span
class="code-quote">"jdbc:postgresql:<span class="code-comment">//localhost:5432/YOUR_DB_NAME_HERE"</span>/&gt;
</span>            &lt;param name=<span class="code-quote">"schema"</span>
value=<span class="code-quote">"postgresql"</span>/&gt;
            &lt;param name=<span class="code-quote">"user"</span> value=<span
class="code-quote">"YOUR_USER_HERE"</span>/&gt;
            &lt;param name=<span class="code-quote">"password"</span> value=<span
class="code-quote">"YOUR_PASSWORD_HERE"</span>/&gt;
            &lt;param name=<span class="code-quote">"schemaObjectPrefix"</span>
value=<span class="code-quote">"jcr_${wsp.name}_"</span>/&gt;
            &lt;param name=<span class="code-quote">"externalBLOBs"</span>
value=<span class="code-quote">"<span class="code-keyword">false</span>"</span>/&gt;
        &lt;/PersistenceManager&gt;
        ...
    &lt;/Workspace&gt;

    &lt;Versioning rootPath=<span class="code-quote">"${rep.home}/version"</span>&gt;
        ...
        &lt;PersistenceManager class=<span class="code-quote">"org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager"</span>&gt;
            &lt;param name=<span class="code-quote">"driver"</span> value=<span
class="code-quote">"org.postgresql.Driver"</span>/&gt;
            &lt;param name=<span class="code-quote">"url"</span> value=<span
class="code-quote">"jdbc:postgresql:<span class="code-comment">//localhost:5432/YOUR_DB_NAME_HERE"</span>/&gt;
</span>            &lt;param name=<span class="code-quote">"schema"</span>
value=<span class="code-quote">"postgresql"</span>/&gt;
            &lt;param name=<span class="code-quote">"user"</span> value=<span
class="code-quote">"YOUR_USER_HERE"</span>/&gt;
            &lt;param name=<span class="code-quote">"password"</span> value=<span
class="code-quote">"YOUR_PASSWORD_HERE"</span>/&gt;
            &lt;param name=<span class="code-quote">"schemaObjectPrefix"</span>
value=<span class="code-quote">"version_"</span>/&gt;
            &lt;param name=<span class="code-quote">"externalBLOBs"</span>
value=<span class="code-quote">"<span class="code-keyword">false</span>"</span>/&gt;
        &lt;/PersistenceManager&gt;
    &lt;/Versioning&gt;
    ...
&lt;/Repository&gt;
</pre>
</div></div>

<p>Modify the <tt>url</tt>, <tt>user</tt>, and <tt>password</tt>
parameters to match your database setup.</p>

<p>If you reconfigure Jackrabbit to use the new persistence manager, the existing repository
data in the <tt>sling/jackrabbit</tt> directory, except the <tt>repository.xml</tt>
file, of course, should now be removed.</p>

<p>Finally either start Sling or start the Jackrabbit Embedded Repository bundle.</p>


<h2><a name="JackrabbitPersistence-Credits"></a>Credits</h2>

<p>This description is based on Tony Giaccone's description <a href="http://markmail.org/message/wlbfrukmjjsl33hh"
class="external-link" rel="nofollow">Swapping Postgres for Derby</a> sent to the
Sling Users mailing list.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Jackrabbit+Persistence">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=22315341&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Jackrabbit+Persistence?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message