Package org.eclipse.persistence.sessions
Class DefaultConnector
- java.lang.Object
-
- org.eclipse.persistence.sessions.DefaultConnector
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Connector
- Direct Known Subclasses:
DirectConnector
public class DefaultConnector extends java.lang.Object implements Connector
Purpose:Use this Connector to build a java.sql.Connection in the "standard" fashion, via the DriverManager.
- See Also:
- Serialized Form
- Author:
- Big Country
- Since:
- TOPLink/Java 2.1
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringdatabaseURLprotected java.sql.Driverdrivercache up the instantiated Driver to speed up reconnectsprotected java.lang.ClassdriverClasscache up the driver class to speed up reconnectsprotected java.lang.StringdriverClassNameprotected java.lang.StringdriverURLHeader
-
Constructor Summary
Constructors Constructor Description DefaultConnector()PUBLIC: Construct a Connector with default settings The database URL will still need to be set.DefaultConnector(java.lang.String driverClassName, java.lang.String driverURLHeader, java.lang.String databaseURL)PUBLIC: Construct a Connector with the specified settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearDriverClassAndDriver()INTERNAL: Discard the cached driver class and driver.java.lang.Objectclone()INTERNAL: Clone the connector.java.sql.Connectionconnect(java.util.Properties properties, Session session)INTERNAL: Connect with the specified properties and session.protected java.sql.ConnectiondirectConnect(java.util.Properties properties)INTERNAL: Connect directly - without using DriverManager.java.lang.StringgetConnectionDetails()PUBLIC: Provide the details of my connection information.java.lang.StringgetConnectionString()PUBLIC: Return the JDBC connection string.java.lang.StringgetDatabaseURL()PUBLIC: The database URL is the JDBC URL for the database server.java.lang.StringgetDriverClassName()PUBLIC: The driver class is the name of the Java class for the JDBC driver being used (e.g.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.protected voidinitialize(java.lang.String driverClassName, java.lang.String driverURLHeader, java.lang.String databaseURL)INTERNAL: Initialize the connector with the specified settings.protected voidinstantiateDriver()INTERNAL: Instantiate the Driver.protected voidloadDriverClass(Session session)INTERNAL: Ensure that the driver has been loaded and registered with the DriverManager.voidsetDatabaseURL(java.lang.String databaseURL)PUBLIC: The database URL is the JDBC URL for the database server.voidsetDriverClassName(java.lang.String driverClassName)PUBLIC: The driver class is the name of the Java class for the JDBC driver being used (e.g.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.booleanshouldUseDriverManager(java.util.Properties properties, Session session)INTERNAL: Indicates whether DriverManager should be used.java.lang.StringtoString()PUBLIC: Print connection string.voidtoString(java.io.PrintWriter writer)INTERNAL: Print something useful on the log.
-
-
-
Field Detail
-
driverClassName
protected java.lang.String driverClassName
-
driverURLHeader
protected java.lang.String driverURLHeader
-
databaseURL
protected java.lang.String databaseURL
-
driverClass
protected java.lang.Class driverClass
cache up the driver class to speed up reconnects
-
driver
protected java.sql.Driver driver
cache up the instantiated Driver to speed up reconnects
-
-
Constructor Detail
-
DefaultConnector
public DefaultConnector()
PUBLIC: Construct a Connector with default settings The database URL will still need to be set.
-
DefaultConnector
public DefaultConnector(java.lang.String driverClassName, java.lang.String driverURLHeader, java.lang.String databaseURL)PUBLIC: Construct a Connector with the specified settings.
-
-
Method Detail
-
clone
public java.lang.Object clone()
INTERNAL: Clone the connector.
-
connect
public java.sql.Connection connect(java.util.Properties properties, Session session) throws DatabaseExceptionINTERNAL: Connect with the specified properties and session. Return the Connection.- Specified by:
connectin interfaceConnector- Returns:
- java.sql.Connection
- Throws:
DatabaseException
-
shouldUseDriverManager
public boolean shouldUseDriverManager(java.util.Properties properties, Session session)INTERNAL: Indicates whether DriverManager should be used.- Returns:
- boolean
-
directConnect
protected java.sql.Connection directConnect(java.util.Properties properties) throws DatabaseExceptionINTERNAL: Connect directly - without using DriverManager. Return the Connection.- Returns:
- java.sql.Connection
- Throws:
DatabaseException
-
getConnectionString
public java.lang.String getConnectionString()
PUBLIC: Return the JDBC connection string. This is a combination of the driver-specific URL header and the database URL.
-
getConnectionDetails
public java.lang.String getConnectionDetails()
PUBLIC: Provide the details of my connection information. This is primarily for JMX runtime services.- Specified by:
getConnectionDetailsin interfaceConnector- Returns:
- java.lang.String
-
getDatabaseURL
public java.lang.String getDatabaseURL()
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").
-
getDriverClassName
public java.lang.String getDriverClassName()
PUBLIC: The driver class is the name of the Java class for the JDBC driver being used (e.g. "sun.jdbc.odbc.JdbcOdbcDriver").
-
getDriverURLHeader
public java.lang.String getDriverURLHeader()
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.
-
initialize
protected void initialize(java.lang.String driverClassName, java.lang.String driverURLHeader, java.lang.String databaseURL)INTERNAL: Initialize the connector with the specified settings.
-
loadDriverClass
protected void loadDriverClass(Session session) throws DatabaseException
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.- Throws:
DatabaseException
-
setDatabaseURL
public void setDatabaseURL(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").
-
setDriverClassName
public void setDriverClassName(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").
-
setDriverURLHeader
public void setDriverURLHeader(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.
-
toString
public java.lang.String toString()
PUBLIC: Print connection string.- Overrides:
toStringin classjava.lang.Object
-
toString
public void toString(java.io.PrintWriter writer)
INTERNAL: Print something useful on the log.
-
instantiateDriver
protected void instantiateDriver() throws DatabaseExceptionINTERNAL: Instantiate the Driver.- Throws:
DatabaseException
-
clearDriverClassAndDriver
public void clearDriverClassAndDriver()
INTERNAL: Discard the cached driver class and driver.
-
-