-
1. Re: Best practice for deploying a database connection pool to ServiceMix 4
ffang Dec 7, 2010 10:18 PM (in response to benhough)Hi,
A general solution is make your jdbc driver bundle as fragment bundle and attach it to commons-dbcp, so that the class in jdbc driver bundle is available for commons-dbcp.
Freeman
-
2. Re: Best practice for deploying a database connection pool to ServiceMix 4
marc.lebeau Dec 8, 2010 5:44 AM (in response to benhough)Maybe it is not the ultimate solution, but here is how I deployed it :
1. Create a class that initialises the driver as soon as possible:
public class InitialisingBasicDataSource extends org.apache.commons.dbcp.BasicDataSource implements InitializingBean {bq. // This is just so that the Database Driver is initialised when the Spring ClassLoader is used.
public void afterPropertiesSet() throws Exception {bq. Connection conn = getConnection();
String vq = this.getValidationQuery();
if (vq == null) {
vq = "SELECT 1";}
conn.nativeSQL(vq);
conn.close();
}
}
2. Expose it as a service to all the other bundles :
<bean id="el1DSImpl" class="be.lampiris.esb.el1DS.InitialisingBasicDataSource"
destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="url" value="${dataSource.el1.URL};domain=${dataSource.el1.domain}"/>
<property name="username" value="${dataSource.el1.user}"/>
<property name="password" value="${dataSource.el1.password}"/>
<property name="validationQuery" value="SELECT 1"/>
<property name="maxActive" value="${dataSource.el1.maxActive}"/>
</bean>
<osgi:service id="el1DS" interface="javax.sql.DataSource" ref="el1DSImpl"/>
Hoping this will help you.
-
3. Re: Best practice for deploying a database connection pool to ServiceMix 4
benhough Dec 10, 2010 6:30 PM (in response to ffang)Ok, so I was thinking that attaching a fragment involved repackaging the MySQL driver in a new bundle and re-deploying the whole thing... but when I realized that I could create a tiny fragment bundle that does nothing but import the vanilla MySQL package to the commons-dbcp ServiceMix bundle, it made a whole lot more sense.
I've attached my resulting setup in case it helps anyone. If anyone knows of a better setup, I welcome your comments.
Note that this setup depends on the following non-default bundles:
ServiceMix bundles commons-dbcp (osgi:install -s mvn:org.apache.servicemix.bundles/commons-dbcp/1.2.2_6)
MySQL JDBC driver (osgi:install -s mvn:mysql/mysql-connector-java/5.1.13)
Thanks to each of you.
-Ben
Attached:
dbcp-mysql-fragment.zip: a commons-dbcp fragment project that imports com.mysql.jdbc
common-mysql-pool.zip: a dbcp pool project with Spring configuration, and MBean export.
-
common-mysql-pool.zip 4.1 KB
-
dbcp-mysql-fragment.zip 1.2 KB
-
-
4. Re: Best practice for deploying a database connection pool to ServiceMix 4
ffang Dec 10, 2010 8:57 PM (in response to benhough)Hi Ben,
Thanks so much to share your solution.
And yeah, a tiny fragment bundle which only expose necessary resource make more sense here.
Freeman
-
5. Re: Best practice for deploying a database connection pool to ServiceMix 4
sterlingsmith Dec 11, 2010 1:36 PM (in response to benhough)I recently had the exact same issue with a NoClassDefFoundError on my Postgres database. Like you, the drivers were not included as part of my bundle for OSGI and had to be included.
Including this as a stand-alone fragment is probably better as that way you can re-use this for any component that needs it (by using Import-Package and Export-Package in the Maven POM file)... I decided to use the Embed-Dir tag to include my driver in the package and included the jar in my resources directory.
See code snippet for
I'm still trying to get my code away from legacy (but nicely simple jdbc) to use Spring enabled DAO using Hibernate and I suspect I'll be posting here shortly with similar issues.
Edited by: sterlingsmith on Dec 11, 2010 6:35 PM