Class DriverManager
- java.lang.Object
-
- de.aristaflow.adept2.base.dbaccess.drivermanager.DriverManager
-
public abstract class DriverManager extends Object
Thejava.sql.DriverManager
uses a native method to retrieve the classloader from the calling class which keeps the calling class (including its classloader) from being garbage collected. Therefore all accesses to the driver manager have to be encapsulated by a shared class (this class). Additionally, all JDBC-drivers have to be provided to the system classloader (and not to the component classloaders).- Author:
- Ulrich Kreher
- See Also:
DriverManager
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DriverManager()
package protected constructor -> we provide the only implementation
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Connection
getConnection(String url)
Attempts to establish a connection to the given database URL.abstract Connection
getConnection(String url, String user, String password)
Attempts to establish a connection to the given database URL.abstract Connection
getConnection(String url, Properties info)
Attempts to establish a connection to the given database URL.abstract Driver
getDriver(String url)
Attempts to locate a driver that understands the given URL.abstract Enumeration<Driver>
getDrivers()
Retrieves an Enumeration with all of the currently loaded JDBC drivers to which the current caller has access.static DriverManager
getInstance(String libDir)
Returns the instance of the JDBC driver manager for the designated directory.abstract int
getLoginTimeout()
Gets the maximum time in seconds that a driver can wait when attempting to log in to a database.abstract void
loadDriver(String className)
Gets the class with the designated name.
-
-
-
Method Detail
-
loadDriver
public abstract void loadDriver(String className) throws DriverNotFoundException
Gets the class with the designated name. This method has to be used instead of the usualClass.forName(className)
to enforce the initialisation of the corresponding driver class.- Parameters:
className
- The name of the class providing the JDBC-driver which should be registered.- Throws:
DriverNotFoundException
- If the driver could not be loaded. Examine cause for more information.
-
getConnection
public abstract Connection getConnection(String url, Properties info) throws SQLException
Attempts to establish a connection to the given database URL. TheDriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.- Parameters:
url
- a database url of the formjdbc:subprotocol:subname
info
- a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included- Returns:
- a Connection to the URL
- Throws:
SQLException
- if a database access error occurs
-
getConnection
public abstract Connection getConnection(String url, String user, String password) throws SQLException
Attempts to establish a connection to the given database URL. TheDriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.- Parameters:
url
- a database url of the formjdbc:subprotocol:subname
user
- the database user on whose behalf the connection is being madepassword
- the user's password- Returns:
- a connection to the URL
- Throws:
SQLException
- if a database access error occurs
-
getConnection
public abstract Connection getConnection(String url) throws SQLException
Attempts to establish a connection to the given database URL. TheDriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.- Parameters:
url
- a database url of the formjdbc:subprotocol:subname
- Returns:
- a connection to the URL
- Throws:
SQLException
- if a database access error occurs
-
getDriver
public abstract Driver getDriver(String url) throws SQLException
Attempts to locate a driver that understands the given URL. TheDriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.- Parameters:
url
- a database URL of the formjdbc:subprotocol:subname
- Returns:
- a
Driver
object representing a driver that can connect to the given URL - Throws:
SQLException
- if a database access error occurs
-
getDrivers
public abstract Enumeration<Driver> getDrivers()
Retrieves an Enumeration with all of the currently loaded JDBC drivers to which the current caller has access.Note: The classname of a driver can be found using
d.getClass().getName()
- Returns:
- the list of JDBC Drivers loaded by the caller's class loader
-
getLoginTimeout
public abstract int getLoginTimeout()
Gets the maximum time in seconds that a driver can wait when attempting to log in to a database.- Returns:
- the driver login time limit in seconds
-
getInstance
public static DriverManager getInstance(String libDir)
Returns the instance of the JDBC driver manager for the designated directory.- Parameters:
libDir
- The library directory containing the JDBC drivers (actually the directory above a directory 'jdbc4' containing the JDBC drivers).- Returns:
- The singleton instance of the JDBC driver manager
-
-