Resource adapters are an awesome way to interact with a container to get services. (see http://blog.dblevins.com/2010/10/ejbnext-connectorbean-api-jax-rs-and.html if you doubt about it). We recently worked on TomEE to make it more powerful and usable than it was before.
First to deploy a resource adapter (rar) on TomEE simply add in conf/tomee.xml the line:
<Deployments file="/path/to/my/super-ra.rar" />
Secondly on TomEE (not sure on other servers) you were able to deploy a resource adapter only once by path (physical location). You can now deploy a resource adapter N times using the system property (put it in conf/system.properties for convenience):
openejb.connector.<id>.aliases = ... openejb.connector.<id>.skip-default = [true|false]
The first property list aliases of this connector. The second configure the fact to keep the default deployment or not. In our case it will look like:
openejb.connector.super-ra.aliases = ra1, ra2, ra3 openejb.connector.super-ra.skip-default = true
It will deploy our resource adapter as ra1, ra2, ra3.
You can still configure the resource adapter instances as before using properties like:
<name>.<property> = <value>
For instance to configure MySQL tranql resource adapter (wraps datasource in resource adapters) you can do:
<?xml version="1.0" encoding="UTF-8"?> <openejb> <Deployments file="tranql-connector-mysql-xa-1.6.rar" /> </openejb>
openejb.connector.tranql-connector-mysql-xa-1.6.aliases = foo, bar openejb.connector.tranql-connector-mysql-xa-1.6.skip-default = true foo.ServerName = localhost foo.UserName = root foo.Password = pwd foo.DatabaseName = test bar.ServerName = localhost bar.UserName = root bar.Password = pwd bar.DatabaseName = test
Finally in the case of tranql you get ManagedConnectionFactories which are javax.sql.DataSource. So you can simply reuse them in you rpersistence-units as jta-data-source (foo, bar…).