On 19/12/2007, Damian Gołda <[EMAIL PROTECTED]> wrote:
>
> I have question, not regarding OPS4J but you are OSGi experts ...
>
> In many libraries, especially providing database connection pools,
> there is used DriverManager for instantiation of JDBC Driver.
> I can't  force DriverManager to work in OSGi - it always cannot find
> class with driver. I've looked in its source code and find weird way
> to find "correct" classloader, which actually is unuseful, because
> doesn't use bundle classloader or context classloader.


yeah, I'm looking into the JDBC area at the moment...

for initial drivers (set with "jdbc.drivers" system property) they're
typically
loaded with the system classloader - unless they use the ServiceLoader
mechanism (META-INF/services/java.sql.Driver) in which case it uses the
TCCL (thread context classloader)

other drivers can be loaded by yourself and registered with registerDriver

however... it seems the DriverManager will filter the initial and registered
drivers to only include driver classes that match those loaded from the
"caller classloader" (ie. in the same class space)

( "caller classloader" is the classloader of the class of the calling
method,
  which is found using an internal JVM method - if the calling classloader
is
  null, it uses the thread context classloader )

in OSGi the calling classloader is typically the bundle classloader, which
means that at the moment I believe you either need to import the driver
class (if provided by another bundle) or register it in the same bundle

of course, if the calling code is actually in another bundle (ie. a wrapped
library) then it can get more complicated, as the calling and registering
bundles need to get the driver class from the same class space...

Do you have any solutions, how to solve that problem?


well, I'm still investigating possible solutions :)

Only solution working for me is to modify source code of connection
> pool, to not use DriverManager. But I hate it...
> I try to use C3P0.


have you tried using Dynamic-ImportPackage in the various bundles as a
workaround?

--
> Damian
>
> _______________________________________________
> general mailing list
> [email protected]
> http://lists.ops4j.org/mailman/listinfo/general
>



-- 
Cheers, Stuart
_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to