db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Boynes <jboy...@apache.org>
Subject Re: Question about using URLClassLoader and Derby
Date Tue, 15 Nov 2005 16:41:33 GMT
Kathey Marsden wrote:
> This might be reaching too far, but in playing with this this week,
> (before hitting the error log show stopper)
> I was thinking that rather than just providing samples on how to load
> Derby in a classloader, it  would be really
> nice to offer some  sort of API to make it  really simple to load derby
> given an URL[]   and an easy way to get
> DataSources from it.  Might  it  be possible to integrate this  into
> your  an API somehow, perhaps with a set method
> that takes the URL  string specification of the directory where Derby
> is  installed and a DataSourceFactory that is
> initialized with  the server instance?

I think this would be useful if we can find a way around the chicken/egg
problem: how does the class containing that API get loaded and from
which classloader?

Perhaps we could have a very small and stable bootstrap API jar that
contained this factory code and which could be used to bootstrap any
version of the engine. Something like:

public abstract class DataSourceFactory {
    /** Locate the factory as a JAR service */
    public static DataSourceFactory getFactory(String uri) {...}

    /** return true if an impl can handle the requested url */
    public abstract boolean canHandle(String uri) {...}

    /** return a configured DataSource */
    public abstract DataSource getDataSource() {...}

    /** set a property for this source *//
    public abstract void setProperty(String name, String value) {...}

    /* other common initialization methods ... */

 * Implementation that returns a DataSource for an embedded engine
public class EmbeddedDataSourceFactory extends DataSourceFactory {...}

The DataSourceFactory base class would use the JAR service location
mechanism to find an implementation that could handle the supplied URI -
note the URI would identify the implementation and not the actual
database (basically just the protocol bit from the Driver URL).

[[ Random thought, there's nothing here that's Derby specific, perhaps
we should suggest adding something like this to javax.sql? ]]

This still leaves it up to the host environment to add the
implementations to the classpath so that getFactory can locate them
using getResource(). I would argue that is the right separation of concerns.


View raw message