OpenEJB and TomEE provide default factories for datasources allowing to define easily by configuration JTA or not datasource pooled by a configurable pool implementation (dbcp, tomcat-jdbc, bonecp…).
But sometimes it is not enough. You want to take the control of the datasource (if you want to use native driver pooling, read the config from a custom source etc…).
For non jta datasource no issue, but for JTA you need to know some internals.
To avoid it we added in OpenEJB a new factory usable as resource to let you define custom JTA datasource.
First define your datasource as you want. For instance:
<Resource id="myDs" type="DataSource" class-name="org.superbiz.MyDataSourceFactory" factory-name="create"> url = ... anotherAttribute = ... </Resource>
Then wrap it using new JTADataSourceWrapperFacory:
<Resource id="myJTADataSource" type="DataSource" class-name="org.apache.openejb.resource.jdbc.managed.JTADataSourceWrapperFactory" factory-name="create"> Delegate = myDs </Resource>
Then simply use myJTADataSource instead of myDs in your application (jpa, @Resource…)