eXo Platform 3.5

## Chapter 17. JCR Configuration persister

eXo JCR allows using persister to store configuration. In this chapter, you will understand how to use and configure eXo JCR persister.

## Idea

JCR Repository Service uses `org.exoplatform.services.jcr.config.RepositoryServiceConfiguration` component to read its configuration.

    <component>

        <key>org.exoplatform.services.jcr.config.RepositoryServiceConfiguration</key>

        <type>org.exoplatform.services.jcr.impl.config.RepositoryServiceConfigurationImpl</type>

        <init-params>

          <value-param>

            <name>conf-path</name>

            <description>JCR configuration file</description>

            <value>/conf/standalone/exo-jcr-config.xml</value>

          </value-param>

        </init-params>

      </component>

In the example, Repository Service will read the configuration from the file `/conf/standalone/exo-jcr-config.xml`.

But in some cases, it's required to change the configuration on the fly. And know that the new one will be used. Additionally we wish not to modify the original file.

In this case, we have to use the configuration persister feature which allows to store the configuration in different locations.

## Usage

On startup `RepositoryServiceConfiguration` component checks if a configuration persister was configured. In that case, it uses the provided `ConfigurationPersister` implementation class to instantiate the persister object.

Configuration with persister:

    <component>

        <key>org.exoplatform.services.jcr.config.RepositoryServiceConfiguration</key>

        <type>org.exoplatform.services.jcr.impl.config.RepositoryServiceConfigurationImpl</type>

        <init-params>

          <value-param>

            <name>conf-path</name>

            <description>JCR configuration file</description>

            <value>/conf/standalone/exo-jcr-config.xml</value>

          </value-param>

          <properties-param>

            <name>working-conf</name>

            <description>working-conf</description>

            <property name="source-name" value="jdbcjcr" />

            <property name="dialect" value="mysql" />

            <property name="persister-class-name" value="org.exoplatform.services.jcr.impl.config.JDBCConfigurationPersister" />

          </properties-param>

        </init-params>

      </component>

Where:

- `source-name`: JNDI source name configured in `InitialContextInitializer` component. (`sourceName` prior v.1.9.) Find more in database configuration.

- `dialect`: SQL dialect which will be used with database from `source-name`. Find more in database configuration.

- `persister-class-name` - class name of `ConfigurationPersister` interface implementation. (`persisterClassName` prior v.1.9.)

ConfigurationPersister interface:

    /**

       * Init persister.

       * Used by RepositoryServiceConfiguration on init.

       * @return - config data stream

       */

      void init(PropertiesParam params) throws RepositoryConfigurationException;

      /**

       * Read config data.

       * @return - config data stream

       */

      InputStream read() throws RepositoryConfigurationException;

      /**

       * Create table, write data.

       * @param confData - config data stream

       */

      void write(InputStream confData) throws RepositoryConfigurationException;

      /**

       * Tell if the config exists.

       * @return - flag

       */

      boolean hasConfig() throws RepositoryConfigurationException;

JCR Core implementation contains a persister which stores the repository configuration in the relational database using JDBC calls - `org.exoplatform.services.jcr.impl.config.JDBCConfigurationPersister`.

The implementation will crate and use table JCR_CONFIG in the provided database.

But the developer can implement his own persister for his particular usecase.

Copyright © 2009-2012. All rights reserved. eXo Platform SAS