eXo Platform 3.5

## Chapter 63. TransactionService

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

getTransactionManager() | Get used TransactionManager
getUserTransaction() | Get UserTransaction on TransactionManager
getDefaultTimeout() | Return default TimeOut
setTransactionTimeout(int seconds) | Set TimeOut in second
enlistResource(XAResource xares) | Enlist XA resource in TransactionManager
delistResource(XAResource xares) | Delist XA resource from TransactionManager

## Existing TransactionService implementations

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

### JOTM in standalone mode

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

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

### Generic TransactionService based on the TransactionManagerLookup of JBoss Cache

If you intend to use JBoss Cache, 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:

       <!-- Configuration of the TransactionManagerLookup -->
       <component>
          <key>org.jboss.cache.transaction.TransactionManagerLookup</key>
          <type>org.jboss.cache.transaction.GenericTransactionManagerLookup</type>
       </component>
       <!-- Configuration of the TransactionService -->
       <component>
          <key>org.exoplatform.services.transaction.TransactionService</key>
          <type>org.exoplatform.services.transaction.jbosscache.GenericTransactionService</type>
          <!-- Uncomment the lines below if you want to set default transaction timeout that is expressed in seconds -->
          <!--init-params>
             <value-param>
                <name>timeout</name>
                <value>60</value>
             </value-param>
          </init-params-->
       </component>

### Specific GenericTransactionService for JBoss Cache and Arjuna

If you intend to use JBoss Cache 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:

       <!-- Configuration of the TransactionManagerLookup -->
       <component>
          <key>org.jboss.cache.transaction.TransactionManagerLookup</key>
          <type>org.jboss.cache.transaction.JBossStandaloneJTAManagerLookup</type>
       </component>
       <!-- Configuration of the TransactionService -->
       <component>
          <key>org.exoplatform.services.transaction.TransactionService</key>
          <type>org.exoplatform.services.transaction.jbosscache.JBossTransactionsService</type>
          <!-- Uncomment the lines below if you want to set default transaction timeout that is expressed in seconds -->
          <!--init-params>
             <value-param>
                <name>timeout</name>
                <value>60</value>
             </value-param>
          </init-params-->
       </component>

### Generic TransactionService based on the TransactionManagerLookup of Infinispan

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:

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

### Specific GenericTransactionService for Infinispan and Arjuna

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:

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

### A very specific TransactionService for JBoss AS

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

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

### TransactionsEssentials in standalone mode

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

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

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