Hi,

>  On one hand I'm using a data source, but it's not obtained via JNDI, but via 
> Spring, so the ConnectionFactory doesn't suit my needs.
>  On the other, we're using branded drivers that need to be unlocked. To cover 
> all cases, it's better
>  to unlock the connections right after creating them rather than when using 
> them. In the case of the
>  DataStore, this has to be done in 
> ConnectionRecoveryManager.setupConnection() which is the method
>  that actually instantiates the connection. The problem is that this method 
> is private.

That sounds complicated. What about if you use a 'wrapper driver' that
allows you to use use the standard way to get a connection? Like this:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Properties;

public class Wrapper implements java.sql.Driver {

    private static final Wrapper INSTANCE = new Wrapper();
    private static final String PREFIX = "jdbc:wrapper:";

    static {
        try {
            DriverManager.registerDriver(INSTANCE);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public boolean acceptsURL(String url) throws SQLException {
        return url != null && url.startsWith(PREFIX);
    }

    public Connection connect(String url, Properties info) throws SQLException {
        if (!acceptsURL(url)) {
            return null;
        }
        url = "jdbc:" + url.substring(PREFIX.length());
        // or open a connection in some other way
        Connection conn = DriverManager.getConnection(url, info);
        // unlock ...
        return conn;
    }

    public int getMajorVersion() {
        return 1;
    }

    public int getMinorVersion() {
        return 0;
    }

    public DriverPropertyInfo[] getPropertyInfo(String url, Properties
prop) throws SQLException {
        return new DriverPropertyInfo[0];
    }

    public boolean jdbcCompliant() {
        return true;
    }

}

Regards,
Thomas

Reply via email to