OSGi vs C3P0

Posted on August 18, 2008 by Tommy McGuire
Labels: eclipse virgo, osgi, java
Continuing the OSGi saga...

The web application framework I am building attempts to leverage an existing configuration framework, which has caused me a bit of a headache. The configuration framework is built around a set of database tables holding the configuration information and provides a one-stop source for all of it, including basic configuration data, JDBC DataSource connections, LDAP connections, etc., etc., etc. (And ultimately including the log tables written from Log4j.)

The one-stop is the initial database connection to get to the configuration data. My headache starts with the framework, which uses a c3p0 JDBC connection pool (see also this), which in turn includes the wondrous JDBC-driver-from-class-name thingy. Coupled with the wondrous OSGi class loader hacks, the result is an almost certain headache. Here is my aspirin:

There may well be a better way of doing this, but the minor configuration bundle attached to c3p0 seems acceptable.

Edit: I just looked at this post and realized I never mentioned why it worked.

Ps. If you need it, this is the MANIFEST.MF of the c3p0 fragment:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: NASA Frameweork Core C3P0 Config Fragment
Bundle-SymbolicName: gov.nasa.common.framework.core.c3p0_0.9.1_config;
singleton:=true
Bundle-Version: 1.0.0
Import-Package: com.microsoft.sqlserver.jdbc;resolution:=optional,com.
mysql.jdbc;version="[3.1.12,3.2.0)";resolution:=optional,oracle.jdbc.
driver;version="[10.2.0.1,10.3)";resolution:=optional,org.apache.derb
y.jdbc
Fragment-Host: c3p0;bundle-version="0.9.1"


Pps. That may not be the c3p0 from the SpringSource repository; modify the bundle symbolic name in the Fragment-Host header as needed.

Comments


I wrap my project in OSGi bundle(just call my first start method from Activator.start()). In my project I use ORM ActiveObjects and c3p0 pool. All of project dependencies (jar librarys) are in class path. If I run my project with c3p0 it is takes about 5 minutes to 1 query to DB. Without c3p0 it is works correctly. In what is a problem? Thanks a lot!

evgeny_k
2010-08-27

To tell you the truth, I am afraid I do not have a whole lot of experience with c3p0. I have used it a bit, but the system that uses the c3p0 pools was written by someone else and all I did was to OSGi-ify it. I also have no idea what an ORM ActiveObject is.

It sounds like you have the right set-up, and if it works at all, then OSGi is probably not the problem. (Now, if you had gotten a ClassNotFound exception....)

I suspect there is a problem in your c3p0 configuration. You might try that configuration without OSGi, or find someone who knows more about c3p0. Sorry.

Tommy McGuire
2010-08-29
active directory applied formal logic ashurbanipal authentication books c c++ comics conference continuations coq data structure digital humanities Dijkstra eclipse virgo electronics emacs goodreads haskell http java job Knuth ldap link linux lisp math naming nimrod notation OpenAM osgi parsing pony programming language protocols python quote quotes R random REST ruby rust SAML scala scheme shell software development system administration theory tip toy problems unix vmware yeti
Member of The Internet Defense League
Site proudly generated by Hakyll.