FileDocCategorySizeDatePackage
DirectConnector.javaAPI DocGlassfish v2 API5320Tue May 22 16:54:52 BST 2007oracle.toplink.essentials.sessions

DirectConnector

public class DirectConnector extends DefaultConnector

Purpose:Use this Connector to build a java.sql.Connection by directly instantiating the Driver, as opposed to using the DriverManager.

author
Big Country
since
TOPLink/Java 2.1

Fields Summary
protected Driver
cachedInstance
cache up the instantiated Driver to speed up reconnects
Constructors Summary
public DirectConnector()
PUBLIC: Construct a Connector with default settings (Sun JDBC-ODBC bridge). Although this does not really make sense for a "direct" Connector - the Sun JdbcOdbcDriver works fine with the DriverManager.

        super();
    
public DirectConnector(String driverClassName, String driverURLHeader, String databaseURL)
PUBLIC: Construct a Connector with the specified settings.

        super(driverClassName, driverURLHeader, databaseURL);
    
Methods Summary
public java.sql.Connectionconnect(java.util.Properties properties)
INTERNAL: Connect with the specified properties and return the Connection.

return
java.sql.Connection

        try {
            return this.instantiateDriver(this.loadDriver()).connect(this.getConnectionString(), properties);
        } catch (SQLException exception) {
            throw DatabaseException.sqlException(exception);
        }
    
protected java.sql.DriverinstantiateDriver(java.lang.Class driverClass)
INTERNAL: Instantiate the Driver if necessary.

return
java.sql.Driver

        if (cachedInstance != null) {
            return cachedInstance;
        }

        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    cachedInstance = (Driver)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(driverClass));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof InstantiationException) {
                        throw DatabaseException.configurationErrorNewInstanceInstantiationException((InstantiationException)throwableException, driverClass);
                    } else {
                        throw DatabaseException.configurationErrorNewInstanceIllegalAccessException((IllegalAccessException)throwableException, driverClass);
                    }
                }
            } else {
                cachedInstance = (Driver)PrivilegedAccessHelper.newInstanceFromClass(driverClass);
            }
            return cachedInstance;
        } catch (InstantiationException ie) {
            throw DatabaseException.configurationErrorNewInstanceInstantiationException(ie, driverClass);
        } catch (IllegalAccessException iae) {
            throw DatabaseException.configurationErrorNewInstanceIllegalAccessException(iae, driverClass);
        }