<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<section id="JCR.MultiDBSchemaSupport">
  <title>How to host several JCR instances on the same database
  instance?</title>

  <para>Frequently, a single database instance must be shared by several other
  applications. But some of our customers have also asked for a way to host
  several JCR instances in the same database instance. To fulfill this need,
  we had to review our queries and scope them to the current schema; it is now
  possible to have one JCR instance per DB schema instead of per DB instance.
  To benefit of the work done for this feature you will need to apply the
  configuration changes described below.</para>

  <section id="JCR.MultiDBSchemaSupport.LockManager_Config">
    <title>LockManager configuration</title>

    <para>To enable this feature you need to replace
    org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore with
    org.exoplatform.services.jcr.infinispan.JdbcStringBasedCacheStore in
    Infinispan configuration file.</para>

    <para>Here is an example of this very part of the configuration:</para>

    <programlisting language="xml">&lt;infinispan
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="urn:infinispan:config:5.2 http://www.infinispan.org/schemas/infinispan-config-5.2.xsd"
      xmlns="urn:infinispan:config:5.2"&gt;

    &lt;global&gt;
      &lt;evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory"&gt;
        &lt;properties&gt;
          &lt;property name="threadNamePrefix" value="EvictionThread"/&gt;
        &lt;/properties&gt;
      &lt;/evictionScheduledExecutor&gt;

      &lt;globalJmxStatistics jmxDomain="exo" enabled="true" allowDuplicateDomains="true"/&gt;
    &lt;/global&gt;

    &lt;default&gt;
      &lt;locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500" useLockStriping="false"/&gt;
      &lt;transaction transactionManagerLookupClass="org.exoplatform.services.transaction.infinispan.JBossStandaloneJTAManagerLookup" syncRollbackPhase="true" syncCommitPhase="true" transactionMode="TRANSACTIONAL"/&gt;
      &lt;jmxStatistics enabled="true"/&gt;
      &lt;eviction strategy="NONE"/&gt;

      &lt;loaders passivation="false" shared="true" preload="true"&gt;
        &lt;store class="<emphasis role="bold">org.exoplatform.services.jcr.infinispan.JdbcStringBasedCacheStore</emphasis>" fetchPersistentState="true" ignoreModifications="false" purgeOnStartup="false"&gt;
          &lt;properties&gt;
             &lt;property name="stringsTableNamePrefix" value="${infinispan-cl-cache.jdbc.table.name}"/&gt;
             &lt;property name="idColumnName" value="${infinispan-cl-cache.jdbc.id.column}"/&gt;
             &lt;property name="dataColumnName" value="${infinispan-cl-cache.jdbc.data.column}"/&gt;
             &lt;property name="timestampColumnName" value="${infinispan-cl-cache.jdbc.timestamp.column}"/&gt;
             &lt;property name="idColumnType" value="${infinispan-cl-cache.jdbc.id.type}"/&gt;
             &lt;property name="dataColumnType" value="${infinispan-cl-cache.jdbc.data.type}"/&gt;
             &lt;property name="timestampColumnType" value="${infinispan-cl-cache.jdbc.timestamp.type}"/&gt;
             &lt;property name="dropTableOnExit" value="${infinispan-cl-cache.jdbc.table.drop}"/&gt;
             &lt;property name="createTableOnStart" value="${infinispan-cl-cache.jdbc.table.create}"/&gt;
             &lt;property name="connectionFactoryClass" value="${infinispan-cl-cache.jdbc.connectionFactory}"/&gt;
             &lt;property name="datasourceJndiLocation" value="${infinispan-cl-cache.jdbc.datasource}"/&gt;
          &lt;/properties&gt;
          &lt;async enabled="false"/&gt;
        &lt;/store&gt;
      &lt;/loaders&gt;
   &lt;/default&gt;

&lt;/infinispan&gt;</programlisting>

    <para>You can also obtain file example from <ulink
    url="https://github.com/exoplatform/jcr/tree/stable/1.16.x/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-infinispan-lock.xml">GitHub</ulink>.</para>
  </section>

  <section id="JCR.MultiDBSchemaSupport.HibernateService_Configuration">
    <title>HibernateService configuration</title>

    <para>If you use HibernateService for JDBC connections management you will
    need to specify explicitly the default schema by setting
    "hibernate.default_schema" property in the configuration of
    HibernateService.</para>

    <para>Here is an example:</para>

    <programlisting language="xml">&lt;component&gt;
    &lt;key&gt;org.exoplatform.services.database.HibernateService&lt;/key&gt;
    &lt;jmx-name&gt;database:type=HibernateService&lt;/jmx-name&gt;
    &lt;type&gt;org.exoplatform.services.database.impl.HibernateServiceImpl&lt;/type&gt;
    &lt;init-params&gt;
      &lt;properties-param&gt;
        &lt;name&gt;hibernate.properties&lt;/name&gt;
        &lt;description&gt;Default Hibernate Service&lt;/description&gt;
        ...........
        <emphasis role="bold">&lt;property name="hibernate.default_schema" value="${gatein.idm.datasource.schema:}"/&gt;</emphasis>
      &lt;/properties-param&gt;
    &lt;/init-params&gt;
&lt;/component&gt;</programlisting>
  </section>
</section>
