<?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="Kernel.TransactionService">
  <title>TransactionService</title>

  <para>TransactionServices provides access to the TransactionManager and the
  UserTransaction (See JTA specification for details).</para>

  <table>
    <title>List methods</title>

    <tgroup cols="2">
      <tbody>
        <row>
          <entry>getTransactionManager()</entry>

          <entry>Get used TransactionManager</entry>
        </row>

        <row>
          <entry>getUserTransaction()</entry>

          <entry>Get UserTransaction on TransactionManager</entry>
        </row>

        <row>
          <entry>getDefaultTimeout()</entry>

          <entry>Return default TimeOut</entry>
        </row>

        <row>
          <entry>setTransactionTimeout(int seconds)</entry>

          <entry>Set TimeOut in second</entry>
        </row>

        <row>
          <entry>enlistResource(XAResource xares)</entry>

          <entry>Enlist XA resource in TransactionManager</entry>
        </row>

        <row>
          <entry>delistResource(XAResource xares)</entry>

          <entry>Delist XA resource from TransactionManager</entry>
        </row>
      </tbody>
    </tgroup>
  </table>

  <section id="Kernel.TransactionService.ExistingTransactionServiceImplementations">
    <title>Existing TransactionService implementations</title>

    <para>eXo JCR proposes out of the box several implementations, they all
    implement the abstract class
    <emphasis>org.exoplatform.services.transaction.impl.AbstractTransactionService</emphasis>.
    This main class implement the biggest part of all the methods proposed by
    the <emphasis>TransactionService</emphasis>. For each sub-class of
    <emphasis>AbstractTransactionService</emphasis>, you can set the
    transaction timeout by configuration using the value parameter
    <emphasis>timeout</emphasis> that is expressed in seconds.</para>

    <section id="Kernel.TransactionService.ExistingTransactionServiceImplementations.JOTMInStandaloneMode">
      <title>JOTM in standalone mode</title>

      <para>To use JOTM as TransactionManager in standalone mode, simply add
      the following component configuration:</para>

      <programlisting>   &lt;component&gt;
      &lt;key&gt;org.exoplatform.services.transaction.TransactionService&lt;/key&gt;
      &lt;type&gt;org.exoplatform.services.transaction.impl.jotm.TransactionServiceJotmImpl&lt;/type&gt;
      &lt;!-- Uncomment the lines below if you want to set default transaction timeout that is expressed in seconds --&gt;
      &lt;!--init-params&gt;
         &lt;value-param&gt;
            &lt;name&gt;timeout&lt;/name&gt;
            &lt;value&gt;60&lt;/value&gt;
         &lt;/value-param&gt;
      &lt;/init-params--&gt;
   &lt;/component&gt;</programlisting>
    </section>

    <section id="Kernel.TransactionService.ExistingTransactionServiceImplementations.GenericTransactionServiceBasedOnTransactionManagerLookupOfInfinispan">
      <title>Generic TransactionService based on the TransactionManagerLookup
      of Infinispan</title>

      <para>If you intend to use Infinispan, you can use a generic
      TransactionService based on its TransactionManagerLookup which is able
      to automatically find the TransactionManager of several Application
      Servers thanks to a set of JNDI lookups. This generic TransactionService
      covers mainly the TransactionManager lookups, the UserTransaction is
      actually simply the TransactionManager instance that has been wrapped.
      See below an example of configuration:</para>

      <programlisting>   &lt;!-- Configuration of the TransactionManagerLookup --&gt;
   &lt;component&gt;
      &lt;key&gt;org.infinispan.transaction.lookup.TransactionManagerLookup&lt;/key&gt;
      &lt;type&gt;org.infinispan.transaction.lookup.GenericTransactionManagerLookup&lt;/type&gt;
   &lt;/component&gt;
   &lt;!-- Configuration of the TransactionService --&gt;
   &lt;component&gt;
      &lt;key&gt;org.exoplatform.services.transaction.TransactionService&lt;/key&gt;
      &lt;type&gt;org.exoplatform.services.transaction.infinispan.GenericTransactionService&lt;/type&gt;
      &lt;!-- Uncomment the lines below if you want to set default transaction timeout that is expressed in seconds --&gt;
      &lt;!--init-params&gt;
         &lt;value-param&gt;
            &lt;name&gt;timeout&lt;/name&gt;
            &lt;value&gt;60&lt;/value&gt;
         &lt;/value-param&gt;
      &lt;/init-params--&gt;
   &lt;/component&gt;</programlisting>
    </section>

    <section id="Kernel.TransactionService.ExistingTransactionServiceImplementations.SpecificGenericTransactionServiceForInfinispanAndArjuna">
      <title>Specific GenericTransactionService for Infinispan and
      Arjuna</title>

      <para>If you intend to use Infinispan with Arjuna, you can use a more
      specific GenericTransactionService, it is mostly interesting in case you
      want to use the real UserTransaction. See below an example of
      configuration:</para>

      <programlisting>   &lt;!-- Configuration of the TransactionManagerLookup --&gt;
   &lt;component&gt;
      &lt;key&gt;org.infinispan.transaction.lookup.TransactionManagerLookup&lt;/key&gt;
      &lt;type&gt;org.exoplatform.services.transaction.infinispan.JBossStandaloneJTAManagerLookup&lt;/type&gt;
   &lt;/component&gt;
   &lt;!-- Configuration of the TransactionService --&gt;
   &lt;component&gt;
      &lt;key&gt;org.exoplatform.services.transaction.TransactionService&lt;/key&gt;
      &lt;type&gt;org.exoplatform.services.transaction.infinispan.JBossTransactionsService&lt;/type&gt;
      &lt;!-- Uncomment the lines below if you want to set default transaction timeout that is expressed in seconds --&gt;
      &lt;!--init-params&gt;
         &lt;value-param&gt;
            &lt;name&gt;timeout&lt;/name&gt;
            &lt;value&gt;60&lt;/value&gt;
         &lt;/value-param&gt;
      &lt;/init-params--&gt;
   &lt;/component&gt;</programlisting>
    </section>

    <section id="Kernel.TransactionService.ExistingTransactionServiceImplementations.VerySpecificTransactionServiceForJBossAS">
      <title>A very specific TransactionService for JBoss AS</title>

      <para>If you intend to use JBoss AS with Infinispan, you can use a very
      specific TransactionService for JBoss AS. See below an example of
      configuration:</para>

      <programlisting>   &lt;component&gt;
      &lt;key&gt;org.exoplatform.services.transaction.TransactionService&lt;/key&gt;
      &lt;type&gt;org.exoplatform.services.transaction.impl.jboss.JBossTransactionService&lt;/type&gt;
      &lt;!-- Uncomment the lines below if you want to set default transaction timeout that is expressed in seconds --&gt;
      &lt;!--init-params&gt;
         &lt;value-param&gt;
            &lt;name&gt;timeout&lt;/name&gt;
            &lt;value&gt;60&lt;/value&gt;
         &lt;/value-param&gt;
      &lt;/init-params--&gt;
   &lt;/component&gt;</programlisting>
    </section>

    <section id="Kernel.TransactionService.ExistingTransactionServiceImplementations.TransactionsEssentialsInStandaloneMode">
      <title>TransactionsEssentials in standalone mode</title>

      <para>To use TransactionsEssentials as TransactionManager in standalone
      mode, simply add the following component configuration:</para>

      <programlisting>   &lt;component&gt;
      &lt;key&gt;org.exoplatform.services.transaction.TransactionService&lt;/key&gt;
      &lt;type&gt;org.exoplatform.services.transaction.impl.atomikos.TransactionsEssentialsTransactionService&lt;/type&gt;
      &lt;!-- Uncomment the lines below if you want to set default transaction timeout that is expressed in seconds --&gt;
      &lt;!--init-params&gt;
         &lt;value-param&gt;
            &lt;name&gt;timeout&lt;/name&gt;
            &lt;value&gt;60&lt;/value&gt;
         &lt;/value-param&gt;
      &lt;/init-params--&gt;
   &lt;/component&gt;</programlisting>
    </section>
  </section>
</section>
