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

DefaultConnector

public class DefaultConnector extends Object implements Connector

Purpose:Use this Connector to build a java.sql.Connection in the "standard" fashion, via the DriverManager.

author
Big Country
since
TOPLink/Java 2.1

Fields Summary
protected String
driverClassName
protected String
driverURLHeader
protected String
databaseURL
Constructors Summary
public DefaultConnector()
PUBLIC: Construct a Connector with default settings (Sun JDBC-ODBC bridge). The database URL will still need to be set.

        this("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:", "");
    
public DefaultConnector(String driverClassName, String driverURLHeader, String databaseURL)
PUBLIC: Construct a Connector with the specified settings.

        this.initialize(driverClassName, driverURLHeader, databaseURL);
    
Methods Summary
public java.lang.Objectclone()
INTERNAL: Clone the connector.

        try {
            return super.clone();
        } catch (Exception exception) {
            throw new InternalError("Clone failed");
        }
    
public java.sql.Connectionconnect(java.util.Properties properties)
INTERNAL: Connect with the specified properties and return the Connection.

return
java.sql.Connection

        this.loadDriver();// ensure the driver has been loaded and registered
        try {
            return DriverManager.getConnection(this.getConnectionString(), properties);
        } catch (SQLException exception) {
            throw DatabaseException.sqlException(exception);
        }
    
public java.lang.StringgetConnectionDetails()
PUBLIC: Provide the details of my connection information. This is primarily for JMX runtime services.

return
java.lang.String

        return this.getConnectionString();
    
public java.lang.StringgetConnectionString()
PUBLIC: Return the JDBC connection string. This is a combination of the driver-specific URL header and the database URL.

        return this.getDriverURLHeader() + this.getDatabaseURL();
    
public java.lang.StringgetDatabaseURL()
PUBLIC: The database URL is the JDBC URL for the database server. The driver header is not be included in this URL (e.g. "dbase files"; not "jdbc:odbc:dbase files").

        return databaseURL;
    
public java.lang.StringgetDriverClassName()
PUBLIC: The driver class is the name of the Java class for the JDBC driver being used (e.g. "sun.jdbc.odbc.JdbcOdbcDriver").

        return driverClassName;
    
public java.lang.StringgetDriverURLHeader()
PUBLIC: The driver URL header is the string predetermined by the JDBC driver to be part of the URL connection string, (e.g. "jdbc:odbc:"). This is required to connect to the database.

        return driverURLHeader;
    
protected voidinitialize(java.lang.String driverClassName, java.lang.String driverURLHeader, java.lang.String databaseURL)
INTERNAL: Initialize the connector with the specified settings.

        this.setDriverClassName(driverClassName);
        this.setDriverURLHeader(driverURLHeader);
        this.setDatabaseURL(databaseURL);
    
protected java.lang.ClassloadDriver()
INTERNAL: Ensure that the driver has been loaded and registered with the DriverManager. Just loading the class should cause the static initialization code to do the necessary registration. Return the loaded driver Class.

        // CR#... The correct class loader must be used to load the class,
        // not that Class.forName must be used to initialize the class a simple loadClass may not.
        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    return (Class)AccessController.doPrivileged(new PrivilegedClassForName(this.getDriverClassName(), true, ConversionManager.getDefaultManager().getLoader()));
                } catch (PrivilegedActionException exception) {
                    throw DatabaseException.configurationErrorClassNotFound(this.getDriverClassName());                }
            } else {
                return oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(this.getDriverClassName(), true, ConversionManager.getDefaultManager().getLoader());
            }
        } catch (ClassNotFoundException exception) {
            throw DatabaseException.configurationErrorClassNotFound(this.getDriverClassName());
        }
    
public voidsetDatabaseURL(java.lang.String databaseURL)
PUBLIC: The database URL is the JDBC URL for the database server. The driver header is not be included in this URL (e.g. "dbase files"; not "jdbc:odbc:dbase files").

        this.databaseURL = databaseURL;
    
public voidsetDriverClassName(java.lang.String driverClassName)
PUBLIC: The driver class is the name of the Java class for the JDBC driver being used (e.g. "sun.jdbc.odbc.JdbcOdbcDriver").

        this.driverClassName = driverClassName;
    
public voidsetDriverURLHeader(java.lang.String driverURLHeader)
PUBLIC: The driver URL header is the string predetermined by the JDBC driver to be part of the URL connection string, (e.g. "jdbc:odbc:"). This is required to connect to the database.

        this.driverURLHeader = driverURLHeader;
    
public java.lang.StringtoString()
PUBLIC: Print connection string.

        return oracle.toplink.essentials.internal.helper.Helper.getShortClassName(getClass()) + "(" + getConnectionString() + ")";
    
public voidtoString(java.io.PrintWriter writer)
INTERNAL: Print something useful on the log.

        writer.println(ToStringLocalization.buildMessage("datasource_URL", (Object[])null) + "=> \"" + this.getConnectionString() + "\"");