While not strictly related to performance I did come across an interesting tidbit today that I think is worth sharing. I have been working with JPA based application that has a persistence.xml that is set up to provide the person deploying the application with some flexibility when defining the data sources.
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="Order">
<jta-data-source>jdbc/OrderDS</jta-data-source>
<class>foo.bar.orders.Customer</class>
<class>foo.bar.orders.Order</class>
<class>foo.bar.orders.OrderLine</class>
</persistence-unit>
<persistence-unit name="Mfg">
<jta-data-source>jdbc/MfgDS</jta-data-source>
<class>foo.bar.mfg.Assembly</class>
<class>foo.bar.mfg.Component</class>
<class>foo.bar.mfg.Inventory</class>
<class>foo.bar.mfg.WorkOrder</class>
</persistence-unit>
</persistence>
The first reaction when confronted with this descriptor might be to deploy multiple connection pools one for each persistence unit. This may even be appropriate in some cases because if could be that you are actually going to different back end systems.
If you happen to know that you are actually hitting the same back end database you may think that your only choice is to modify the persistence.xml to point them to a common data source. Fortunately, WLS provides the flexibility of providing multiple jndi names for each data source.
<jdbc-data-source xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>specjds-jdbc</name>
<jdbc-driver-params>
<url>@DATABASE_URI@</url>
<driver-name>@DATABASE_DRIVER@</driver-name>
<properties>
<property>
<name>user</name>
<value>@DATABASE_USER@</value>
</property>
<property>
<name>password</name>
<value>@DATABASE_PASSWORD@</value>
</property>
</jdbc-driver-params>
<jdbc-connection-pool-params>
<initial-capacity>32</initial-capacity>
<max-capacity>64</max-capacity>
<capacity-increment>4</capacity-increment>
<statement-cache-size>128</statement-cache-size>
</jdbc-connection-pool-params>
<jdbc-data-source-params>
<jndi-name>jdbc/OrderDS</jndi-name>
<jndi-name>jdbc/MfgDS</jndi-name>
</jdbc-data-source-params>
</jdbc-data-source>
This is a handy way of mapping from JPA onto your database configuration without having to perform any manipulation of the descriptors that are embedded inside the application archive.