<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<section id="JCR.JCA">
  <title>The <emphasis>JCA</emphasis> Resource Adapter</title>

    <para>eXo JCR supports <emphasis>J2EE Connector Architecture</emphasis>
    1.5, thus If you would like to delegate the JCR Session lifecycle to your
    application server, you can use the JCA Resource Adapter for eXo JCR if
    your application server supports JCA 1.5. This adapter only supports XA
    Transaction, in other words you cannot use it for local transactions.
    Since the JCR Sessions have not been designed to be shareable, the session
    pooling is simply not covered by the adapter.</para>

  <section id="JCR.JCA.SessionFactory">
    <title>The <emphasis>SessionFactory</emphasis></title>

    <para>The equivalent of the
    <emphasis>javax.resource.cci.ConnectionFactory</emphasis> in JCA
    terminology is
    <emphasis>org.exoplatform.connectors.jcr.adapter.SessionFactory</emphasis>
    in the context of eXo JCR, the resource that you will get thanks to a JNDI
    lookup is of type <emphasis>SessionFactory</emphasis> and provides the
    following methods:</para>

    <programlisting>   /**
    * Get a JCR session corresponding to the repository
    * defined in the configuration and the default workspace.
    * @return a JCR session corresponding to the criteria
    * @throws RepositoryException if the session could not be created
    */
   Session getSession() throws RepositoryException;

   /**
    * Get a JCR session corresponding to the repository
    * defined in the configuration and the default workspace, using
    * the given user name and password.
    * @param userName the user name to use for the authentication
    * @param password the password to use for the authentication
    * @return a JCR session corresponding to the criteria
    * @throws RepositoryException if the session could not be created
    */
   Session getSession(String userName, String password) throws RepositoryException;

   /**
    * Get a JCR session corresponding to the repository
    * defined in the configuration and the given workspace.
    * @param workspace the name of the expected workspace
    * @return a JCR session corresponding to the criteria
    * @throws RepositoryException if the session could not be created
    */
   Session getSession(String workspace) throws RepositoryException;

   /**
    * Get a JCR session corresponding to the repository
    * defined in the configuration and the given workspace, using
    * the given user name and password.
    * @param workspace the name of the expected workspace
    * @param userName the user name to use for the authentication
    * @param password the password to use for the authentication
    * @return a JCR session corresponding to the criteria
    * @throws RepositoryException if the session could not be created
    */
   Session getSession(String workspace, String userName, String password) throws RepositoryException;</programlisting>
  </section>

  <section id="JCR.JCA.Configuration">
    <title>Configuration</title>

    <table>
      <title>Configuration Properties</title>

      <tgroup cols="2">
        <tbody>
          <row>
            <entry><emphasis>PortalContainer</emphasis></entry>

            <entry>In case of the portal mode, if no portal container can be
            found in the context of the request, the adapter will use the
            value of this parameter to get the name of the expected portal
            container to create the JCR sessions. In case of a standalone
            mode, this parameter is not used. This parameter is optional, by
            default the default portal container will be used.</entry>
          </row>

          <row>
            <entry><emphasis>Repository</emphasis></entry>

            <entry>The repository name used to create JCR sessions. This
            parameter is optional, by default the current repository will be
            used.</entry>
          </row>
        </tbody>
      </tgroup>
    </table>
  </section>

  <section id="JCR.JCA.Deployment">
    <title>Deployment</title>

    <para>In case of the standalone mode where the JCR and its dependencies
    are not provided, you will need to deploy the whole ear file corresponding
    to the artifactId <emphasis>exo.jcr.ear</emphasis> and groupId
    <emphasis>org.exoplatform.jcr</emphasis>, the rar file is embedded into
    the ear file. In case the JCR and its dependencies are provided like when
    you use it with gateIn for example, you will need to deploy only the rar
    file corresponding to the artifactId
    <emphasis>exo.jcr.connectors.jca</emphasis> and groupId
    <emphasis>org.exoplatform.jcr</emphasis>.</para>

    <para><emphasis role="bold">To deploy JCA module on standalone mode :</emphasis></para>
    <orderedlist>
       <listitem>
          <para>Run "mvn clean install -DskipTests=true" from the root of the jcr project.</para>
       </listitem>
       <listitem>
          <para>Get/download the JBoss AS 7 bundle.</para>
       </listitem>
       <listitem>
          <para>Deploy the whole ear file corresponding to the artifactId <emphasis>exo.jcr.ear</emphasis> and groupId
              <emphasis>org.exoplatform.jcr</emphasis></para>
       </listitem>
       <listitem>
          <para>Configure the resource adapter in <emphasis>JBOSS_HOME/standalone/configuration/standalone.xml</emphasis>
              , you should replace : </para>
          <programlisting>
              &lt;subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"/&gt;
          </programlisting>
          <para>by :</para>
          <programlisting>
              &lt;subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"&gt;
              &lt;resource-adapters&gt;
              &lt;resource-adapter&gt;
              &lt;archive&gt;exo.jcr.ear.ear#exo-jcr.rar&lt;/archive&gt;
              &lt;transaction-support&gt;XATransaction&lt;/transaction-support&gt;
              &lt;connection-definitions&gt;
              &lt;connection-definition class-name="org.exoplatform.connectors.jcr.impl.adapter.ManagedSessionFactory"
              jndi-name="java:/jcr/Repository"&gt;
              &lt;config-property name="PortalContainer"&gt;portal&lt;/config-property&gt;
              &lt;config-property name="Repository"&gt;repository&lt;/config-property&gt;
              &lt;/connection-definition&gt;
              &lt;/connection-definitions&gt;
              &lt;/resource-adapter&gt;
              &lt;/resource-adapters&gt;
              &lt;/subsystem&gt;
          </programlisting>
       </listitem>
    </orderedlist>

    <para><emphasis role="bold">To deploy JCA module on Platform :</emphasis></para>

    <orderedlist>
      <listitem>
          <para>Get/download the JBoss bundle of platform 4 or higher</para>
      </listitem>
      <listitem>
          <para>Go to folder "exo.jcr.connectors.jca" and run "mvn clean install -Pplatform" command.</para>
      </listitem>
      <listitem>
         <para>Deploy exo.jcr.connectors.jca/target/exo.jcr.connectors.jca-1.16.x-GA.rar in
             <emphasis>PLATFORM_HOME/standalone/deployments/</emphasis> of platform 4 bundle,
              and rename it to exo-jcr.rar</para>
      </listitem>
      <listitem>
          <para>Configure the resource adapter in <emphasis>PLATFORM_HOME/standalone/configuration/standalone-exo.xml</emphasis>
               , you should replace :</para>
          <programlisting>
              &lt;subsystem xmlns="urn:jboss:domain:resource-adapters:1.1"/&gt;
          </programlisting>
          <para>by</para>
          <programlisting>
              &lt;subsystem xmlns="urn:jboss:domain:resource-adapters:1.1"&gt;
              &lt;resource-adapters&gt;
              &lt;resource-adapter&gt;
              &lt;archive&gt;exo-jcr.rar&lt;/archive&gt;
              &lt;transaction-support&gt;XATransaction&lt;/transaction-support&gt;
              &lt;connection-definitions&gt;
              &lt;connection-definition class-name="org.exoplatform.connectors.jcr.impl.adapter.ManagedSessionFactory"
              jndi-name="java:/jcr/Repository"&gt;
              &lt;config-property name="PortalContainer"&gt;portal&lt;/config-property&gt;
              &lt;config-property name="Repository"&gt;repository&lt;/config-property&gt;
              &lt;/connection-definition&gt;
              &lt;/connection-definitions&gt;
              &lt;/resource-adapter&gt;
              &lt;/resource-adapters&gt;
              &lt;/subsystem&gt;
          </programlisting>
      </listitem>
    </orderedlist>

    <para><emphasis role="bold">To deploy JCA module on Gatein/JPP:</emphasis></para>

    <orderedlist>
       <listitem>
          <para>Get/download the JBoss bundle of GateIn 3.5/JPP6 or higher</para>
       </listitem>
       <listitem>
           <para>Go to folder "exo.jcr.connectors.jca" and run "mvn clean install -Pgatein" command.</para>
       </listitem>
       <listitem>
          <para>Deploy exo.jcr.connectors.jca/target/exo.jcr.connectors.jca-1.16.x-GA.rar in
              <emphasis>GATEIN_HOME/standalone/deployments/</emphasis> and rename it to exo-jcr.rar</para>
       </listitem>
       <listitem>
          <para>Configure the resource adapter in <emphasis>GATEIN_HOME/standalone/configuration/standalone.xml</emphasis>
              , you should replace : </para>
          <programlisting>
              &lt;subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"/&gt;
          </programlisting>
          <para>by</para>
          <programlisting>
              &lt;subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"&gt;
              &lt;resource-adapters&gt;
              &lt;resource-adapter&gt;
              &lt;archive&gt;exo-jcr.rar&lt;/archive&gt;
              &lt;transaction-support&gt;XATransaction&lt;/transaction-support&gt;
              &lt;connection-definitions&gt;
              &lt;connection-definition class-name="org.exoplatform.connectors.jcr.impl.adapter.ManagedSessionFactory"
              jndi-name="java:/jcr/Repository"&gt;
              &lt;config-property name="PortalContainer"&gt;portal&lt;/config-property&gt;
              &lt;config-property name="Repository"&gt;repository&lt;/config-property&gt;
              &lt;/connection-definition&gt;
              &lt;/connection-definitions&gt;
              &lt;/resource-adapter&gt;
              &lt;/resource-adapters&gt;
              &lt;/subsystem&gt;
          </programlisting>
       </listitem>
    </orderedlist>
  </section>
</section>
