If you have a need for distributed transaction management and you are using a servlet container like Tomcat, you will need to install a third-party JTA/XA library. Below are instructions for installing one of two major distributions:

Portal Settings #

JOTM #

1. Download the attached jotm_global.zip and unzip in {tomcat}/lib (or common/lib if you are using 5.5 for some reason)

2. JOTM depends on commons-logging, so you must move commons logging and log4j to the same folder as JOTM, to prevent logging errors.

3. Override the spring.configs property in portal-ext.properties by copying the original in '-ext' and adding the following to the bottom:

META-INF/ext-jotm.xml

4. Edit your tomcat context xml file and comment out your datasource config (if you configured the JDNI datasource there). then go the the global config (context.xml in the root of conf/) and add:

<Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" />

<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="600" />

<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="com.mysql.jdbc.Driver" name="jdbc/LiferayPool" username="root" password="" url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false" />}}}

For Sharding, you will need to add an entry for each shard, like this:

<Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" />

<Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="600" />

<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="com.mysql.jdbc.Driver" name="jdbc/LiferayPool" username="root" password="" url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false" />

<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="com.mysql.jdbc.Driver" name="jdbc/LiferayPool1" username="root" password="" url="jdbc:mysql://localhost/lportal1?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false" />

<Resource auth="Container" type="javax.sql.DataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="com.mysql.jdbc.Driver" name="jdbc/LiferayPool2" username="root" password="" url="jdbc:mysql://localhost/lportal2?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false" />}}}

And change your portal-ext.properties to use JNDI lookup for shards by commenting out all the jdbc.default., jdbc.one., etc. and replace it with:

jdbc.default.jndi.name=jdbc/LiferayPool
jdbc.one.jndi.name=jdbc/LiferayPool1 jdbc.two.jndi.name=jdbc/LiferayPool2}}}

5. Restart and done!

Atomikos #

1a. Download the latest release of Atomikos and install the following jars into {tomcat}/lib:

  • atomikos-util.jar.jar
  • transactions.jar
  • transactions-api.jar
  • transactions-hibernate3.jar
  • transactions-jta.jar
  • transactions-jdbc.jar

1b. From the Atomikos wiki, download and install the following two jars into {tomcat}/lib:

  • atomikos-tomcat-beanfactory.jar
  • atomikos-tomcat-lifecycle.jar

2. Create a file called

transactions.properties
in {tomcat}/lib and add the following properties:

com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
com.atomikos.icatch.automatic_resource_registration=true com.atomikos.icatch.output_dir=../work com.atomikos.icatch.log_base_dir=../work com.atomikos.icatch.enable_logging=true com.atomikos.icatch.console_log_level=INFO}}}

3. Override the spring.configs property in portal-ext.properties by copying the original in '-ext' and adding the following to the bottom:

META-INF/ext-atomikos.xml

4. Edit your tomcat context xml file and comment out your datasource config (if you configured the JDNI datasource there). then go the the global config (context.xml in the root of conf/) and add (Note: You need to include the XA JDBC driver for your specific database, as provided from your vendor):

<Resource auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean"
factory="com.atomikos.tomcat.BeanFactory" maxPoolSize="100" minPoolSize="10" name="jdbc/LiferayPool" uniqueResourceName="jdbc/LiferayPool" xaDataSourceClassName="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" xaProperties.user="root" xaProperties.password="" xaProperties.url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false&amp;pinGlobalTxToPhysicalConnection=true" />}}}

For Sharding, you will need to add an entry for each shard, like this:

<Resource auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean"
factory="com.atomikos.tomcat.BeanFactory" maxPoolSize="100" minPoolSize="10" name="jdbc/LiferayPool" uniqueResourceName="jdbc/LiferayPool" xaDataSourceClassName="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" xaProperties.user="root" xaProperties.password="" xaProperties.url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false&amp;pinGlobalTxToPhysicalConnection=true" />

<Resource auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean" factory="com.atomikos.tomcat.BeanFactory" maxPoolSize="100" minPoolSize="10" name="jdbc/LiferayPool1" uniqueResourceName="jdbc/LiferayPool1" xaDataSourceClassName="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" xaProperties.user="root" xaProperties.password="" xaProperties.url="jdbc:mysql://localhost/lportal1?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false&amp;pinGlobalTxToPhysicalConnection=true" />

<Resource auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean" factory="com.atomikos.tomcat.BeanFactory" maxPoolSize="100" minPoolSize="10" name="jdbc/LiferayPool2" uniqueResourceName="jdbc/LiferayPool2" xaDataSourceClassName="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" xaProperties.user="root" xaProperties.password="" xaProperties.url="jdbc:mysql://localhost/lportal2?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false&amp;pinGlobalTxToPhysicalConnection=true" />}}}

And change your portal-ext.properties to use JNDI lookup for shards by commenting out all the jdbc.default., jdbc.one., etc. and replace it with:

jdbc.default.jndi.name=jdbc/LiferayPool
jdbc.one.jndi.name=jdbc/LiferayPool1 jdbc.two.jndi.name=jdbc/LiferayPool2}}}

5. Edit your {tomcat}/conf/server.xml and, after the various <Listener /> entries, add the following:

<Listener className="com.atomikos.tomcat.AtomikosLifecycleListener" />

6. Restart and done!

Note: Atomikos has documented a series of known bugs, including additional settings for several JDBC drivers. In particular, MySQL requires the addtion of

pinGlobalTxToPhysicalConnection=true
in the url, as described above.

Portlet Settings #

Now that you have your portal working with JTA, you must make sure that your deployable portlet is using JTA and not hibernate.

In hibernate.xml, change:

<bean id="liferayTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource" ref="liferayDataSource" />
<property name="globalRollbackOnParticipationFailure" value="false" />
<property name="sessionFactory" ref="liferayHibernateSessionFactory" />
</bean>

to:

<bean id="liferayTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="allowCustomIsolationLevels" value="true"/>
<property name="globalRollbackOnParticipationFailure" value="false" />
</bean> 

JNDI Parameters #

Be aware that when you are using JOTM or Atomikos, you are no longer using your defaulted datasource pools. You are either using XAPool (with JOTM) or Atomikos' built-in mechanism.

The following is a listing of the parameters that are available when configuring your datasource.

JOTM #

These are based on DataSourceFactory.java.

Parameter Notes
auth Must always be
Container
type Must always be
javax.sql.DataSource
factory Must always be
org.objectweb.jotm.datasource.DataSourceFactory
name JNDI lookup name
url The JDBC connection url for connecting to your data source.
driverClassName The fully qualified underlying DataSource class name.
username The username for database connections.
password The password for database connections.
min Minimum size of pool
max Maximum size of pool
maxWait Set the milliseconds the pool can wait for a free object
testStmt SQL string to test JDBC connection before using it
checkLevel Check level of the pooled object before using them. 0 = no special checking; 1 = just a check on an object; 2 = test the object; 3 = just a check on an object (for all the objects); 4 = test the object (for all the objects)

Atomikos #

These are based on AbstractDataSourceBean.java and AtomikosDataSourceBean.java. Note that the xaProperties. entries are datasource specific. Meaning, you need to find the details from the vendor of the driver directly (e.g., MySQL, Oracle, etc.).

Parameter Notes
auth Must always be
Container
type Must always be
com.atomikos.jdbc.AtomikosDataSourceBean
factory Must always be
com.atomikos.tomcat.BeanFactory
name JNDI lookup name
uniqueResourceName An arbitrary user-specified value that identifies this datasource. It must be unique for recovery purposes. (Can simply be the same as the JNDI
name
.)
xaDataSourceClassName The fully qualified underlying XADataSource class name.
maxPoolSize The amount of pooled connections won't go above this value. Defaults to 1.
minPoolSize The amount of pooled connections won't go below that value. The pool will open this amount of connections during initialization. Defaults to 1.
borrowConnectionTimeout Maximum amount of seconds the pool will block waiting for a connection to become available in the pool when it is empty. Zero or negative means no waiting at all. Defaults to 30 seconds.
maxIdleTime Maximum amount of seconds that unused excess connections should stay in the pool. Optional. Note: excess connections are connections that are created above the minPoolSize limit. Note that this value is only an indication; the pool will check regularly as indicated by the maintenanceInterval property. The default is 60 seconds.
reapTimeout The amount of seconds that the connection pool will allow a connection to be in use, before claiming it back. Note that this value is only an indication; the pool will check regularly as indicated by the maintenanceInterval property. Default is 0 (no timeout).
maintenanceInterval Maintenance interval (in seconds) for the pool maintenance thread. If not set or not positive then the pool's default (60 secs) will be used.
testQuery SQL query used to test a connection before returning it. Optional.
loginTimeout Sets the maximum seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.
xaProperties. Datasource vendor-specific properties. Most commonly, you will need at minimum
xaProperties.user
,
xaProperties.password
and
xaProperties.url
. Check vendor documentation for specifics.
3 archivos adjuntos
63213 Accesos
Promedio (1 Votar)
La valoración media es de 4.0 estrellas de 5.
Comentarios