tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <>
Subject Re: How do I configure an alternate transaction manager?
Date Wed, 09 Dec 2009 12:52:57 GMT

On Nov 25, 2009, at 10:15 PM, Stephen Connolly wrote:

> How do I configure OpenEJB to use an alternate transaction manager
> (e.g. atomikos)?
> I'vre tried pre-binding the atomikos transaction manager to
> openejb:TransactionManager but the logs do not show any difference.
> OpenEJB 3.1
> Jetty 6.1.16
> Seam 2.0.1.GA
> Hibernate 3.3.1.GA
> Derby

I looked around the Atomikos site for a good half hour and couldn't  
find any straight answers.  Seems they have a unique "transaction  
manager" class for just about every integration and no javadoc so it's  
nearly impossible to figure out what is the  
javax.transaction.TransactionManager impl that should be used.

So... here's a mocked up example.

In a jar in the openejb/lib/ directory, there is a file like so:

   <?xml version="1.0" encoding="UTF-8"?>

         someString  = Blah
         someInt     = 10
         someBoolean = false


The factory looks like so:

     package org.superbiz;

     import javax.transaction.TransactionManager;

     public class TxManagerFactory {

         private String someString;
         private int someInt;
         private boolean someBoolean;

         public void setSomeString(String someString) {
             this.someString = someString;

         public void setSomeInt(int someInt) {
             this.someInt = someInt;

         public void setSomeBoolean(boolean someBoolean) {
             this.someBoolean = someBoolean;

         public TransactionManager create() {
             // Use someString, someInt, and someBoolean
             // as needed to construct the TransactionManager instance
             // and any any objects it requires.

             return ...

And it can be declared in an openejb.xml like so:

   <?xml version="1.0" encoding="UTF-8"?>
     <TransactionManager id="bar"  

       someInt = 20



When looking at the Atomikos documentation it seems like they might  
also want to control the DataSource creation, in which case you can  
use the same technique as above to create a "DataSource" serivce  

   <?xml version="1.0" encoding="UTF-8"?>

           types="javax.sql.DataSource, DataSource"

         JtaManaged  = true
         someInt     = 10
         someBoolean = false


And the DataSourceFactory looks like:

     package org.superbiz;
     import javax.sql.DataSource;

     public class DataSourceFactory {
         public static DataSource create(boolean managed){
             if (managed){
                 return new BasicManagedDataSource();
             } else {
                 return new BasicDataSource();

In this case there are more properties than the DataSourceFactory  
accepts directly, so we'll attempt to "roll them over" and inject them  
into the object passed out of the create method: so in the above  
example we can presume that BasicDataSource and BasicManagedDataSource  
both have a someInt and someBoolean property.  If they don't, we'll  
simply issue warnings that the properties were ignored.

And these can be declared in the openejb.xml like so:

   <?xml version="1.0" encoding="UTF-8"?>
     <Resource id="MyManagedDataSource"  

     <Resource id="MyUnmanagedDataSource"  
         JtaManaged = false


Note, you do not have to support a 'JtaManaged' property on your  
DataSource service provider, but if you do you get a lot of extra bang  
for your buck as OpenEJB will look for that property when trying to  
auto match up DataSources to go with the <jta-data-source> and <non- 
jta-data-source> in any persistence.xml

Anyway, I hope this helps.  I've heard good things about Atomikos and  
would be very interested in seeing it work.  If it really is as good  
as they say, we might even want to use it as the primary Tx Manager  
and DataSource provider in some future release -- or at least make it  
so it works easily out of the box.


View raw message