Tag Archives: datasource

OpenEJB/TomEE custom DataSource JTA integration

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…).

Continue reading

TomEE/OpenEJB and failover of datasources

Defining a DataSource in TomEE is quite easy, the most common way to do so is to define a Resource block in tomee.xml:

<Resource id="jdbc/ds" type="DataSource">
   JdbcUrl = jdbc:mysql://datasourcehost:3306/tomee

When you have multiple hosts you often use datasourcehost (in the previous sample) as a service host (or IP) to delegate then to real hosts. But sometimes it is not possible or too complicated. For such needs TomEE now provides a basic failover feature.

The idea is to reuse dynamic datasource feature of tomee to handle it.

Continue reading

Sharing a single datasource between multiple persistence units with TomEE and OpenEJB

In JavaEE a datasource generally means a pool. So if you have two persistence units using the same physical datasource it can be very interesting to be able to use the same pool (easier to configure the pool size for instance).

Continue reading

Avoid properties conflict when configuring TomEE DataSource

TomEE now supports to switch the connection pooling implementation (commons-dbcp, tomcat-jdbc, bonecp…). However it tries to convert dbcp properties to the other implementation if these properties are found (mainly for compatibility reasons).

In some cases it can be hard.

Here some small tips to make it easier :).

Continue reading

Switching Datasource connection pooling in TomEE/OpenEJB

DataSource Pooling

Pooling its datasource connection in a real application is very important to respect its SLA.

OpenEJB (and by the way TomEE) uses commons-dbcp since many years. It works well if well configured, but suffers from an old design. What’s more, some other libraries are today interesting and are good alternatives.

Two famous of them are tomcat-jdbc (a fork from commons-dbcp) and BoneCP. Both promises great performances (particulary in high load).

Many refactoring has been done in OpenEJB to allow switching pool library keeping the JTA management (supported by commons-dbcp but no others). The result is mainly a “magic” abstract class called org.apache.openejb.resource.jdbc.pool.PoolDataSourceCreator. Its API obliges you to implement a way to pool a provided datasource, to create a pooled datasource and to destroy what you created.

But in a user life, you don’t need it, and you can simply use what is already done through configuration :).

Continue reading