Package org.eclipse.persistence.sessions
Class DefaultConnector
- java.lang.Object
-
- org.eclipse.persistence.sessions.DefaultConnector
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Connector
- Direct Known Subclasses:
DirectConnector
public class DefaultConnector extends 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 String
databaseURL
protected Driver
driver
cache up the instantiated Driver to speed up reconnectsprotected Class
driverClass
cache up the driver class to speed up reconnectsprotected String
driverClassName
protected String
driverURLHeader
-
Constructor Summary
Constructors Constructor Description DefaultConnector()
PUBLIC: Construct a Connector with default settings The database URL will still need to be set.DefaultConnector(String driverClassName, String driverURLHeader, String databaseURL)
PUBLIC: Construct a Connector with the specified settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearDriverClassAndDriver()
INTERNAL: Discard the cached driver class and driver.Object
clone()
INTERNAL: Clone the connector.Connection
connect(Properties properties, Session session)
INTERNAL: Connect with the specified properties and session.protected Connection
directConnect(Properties properties)
INTERNAL: Connect directly - without using DriverManager.String
getConnectionDetails()
PUBLIC: Provide the details of my connection information.String
getConnectionString()
PUBLIC: Return the JDBC connection string.String
getDatabaseURL()
PUBLIC: The database URL is the JDBC URL for the database server.String
getDriverClassName()
PUBLIC: The driver class is the name of the Java class for the JDBC driver being used (e.g.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.protected void
initialize(String driverClassName, String driverURLHeader, String databaseURL)
INTERNAL: Initialize the connector with the specified settings.protected void
instantiateDriver()
INTERNAL: Instantiate the Driver.protected void
loadDriverClass(Session session)
INTERNAL: Ensure that the driver has been loaded and registered with the DriverManager.void
setDatabaseURL(String databaseURL)
PUBLIC: The database URL is the JDBC URL for the database server.void
setDriverClassName(String driverClassName)
PUBLIC: The driver class is the name of the Java class for the JDBC driver being used (e.g.void
setDriverURLHeader(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.boolean
shouldUseDriverManager(Properties properties, Session session)
INTERNAL: Indicates whether DriverManager should be used.String
toString()
PUBLIC: Print connection string.void
toString(PrintWriter writer)
INTERNAL: Print something useful on the log.
-
-
-
Field Detail
-
driverClassName
protected String driverClassName
-
driverURLHeader
protected String driverURLHeader
-
databaseURL
protected String databaseURL
-
driverClass
protected Class driverClass
cache up the driver class to speed up reconnects
-
driver
protected Driver driver
cache up the instantiated Driver to speed up reconnects
-
-
Method Detail
-
clone
public Object clone()
INTERNAL: Clone the connector.
-
connect
public Connection connect(Properties properties, Session session) throws DatabaseException
INTERNAL: Connect with the specified properties and session. Return the Connection.- Specified by:
connect
in interfaceConnector
- Returns:
- java.sql.Connection
- Throws:
DatabaseException
-
shouldUseDriverManager
public boolean shouldUseDriverManager(Properties properties, Session session)
INTERNAL: Indicates whether DriverManager should be used.- Returns:
- boolean
-
directConnect
protected Connection directConnect(Properties properties) throws DatabaseException
INTERNAL: Connect directly - without using DriverManager. Return the Connection.- Returns:
- java.sql.Connection
- Throws:
DatabaseException
-
getConnectionString
public String getConnectionString()
PUBLIC: Return the JDBC connection string. This is a combination of the driver-specific URL header and the database URL.
-
getConnectionDetails
public String getConnectionDetails()
PUBLIC: Provide the details of my connection information. This is primarily for JMX runtime services.- Specified by:
getConnectionDetails
in interfaceConnector
- Returns:
- java.lang.String
-
getDatabaseURL
public 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 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 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(String driverClassName, String driverURLHeader, 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(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(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(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 String toString()
PUBLIC: Print connection string.
-
toString
public void toString(PrintWriter writer)
INTERNAL: Print something useful on the log.
-
instantiateDriver
protected void instantiateDriver() throws DatabaseException
INTERNAL: Instantiate the Driver.- Throws:
DatabaseException
-
clearDriverClassAndDriver
public void clearDriverClassAndDriver()
INTERNAL: Discard the cached driver class and driver.
-
-