|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.programix.sql.DriverManagerConnectionSource
public class DriverManagerConnectionSource
An implementation of ConnectionSource that uses
DriverManager to create database Connection's.
Configuration settings are specified by a ValueMap with
settings such as:
sql.connection.driver=org.postgresql.Driver sql.connection.url=jdbc:postgresql://localhost:5432/andrewdb sql.connection.username=someone sql.connection.password=something sql.connection.extras.ssl=true sql.connection.extras.loginTimeout=90
The required and additional settings are retrieved by code equivalent to this:
ValueMap config = // the configuration settings initially passed in Class.forName(config.getString(DRIVER_KEY)); String url = config.getString(URL_KEY); ValueMap conInfo = config.getNestedValueMap(EXTRAS_PREFIX); if ( config.containsKey(USERNAME_KEY) ) { conInfo.put("user", config.getString(USERNAME_KEY); } if ( config.containsKey(PASSWORD_KEY) ) { conInfo.put("password", config.getString(PASSWORD_KEY); } Connection con = DriverManager.getConnection(url, conInfo.getProperties());
| Field Summary | |
|---|---|
static String |
DRIVER_KEY
Required configuration key for the JDBC driver's classname. |
static String |
EXTRAS_PREFIX
Optional configuration key prefix for additional settings to use to connect to the database. |
static String |
PASSWORD_KEY
Optional configuration key for the password to use to connect to the database. |
static String |
URL_KEY
Required configuration key for the URL to use to connect to the database. |
static String |
USERNAME_KEY
Optional configuration key for the username to use to connect to the database. |
| Constructor Summary | |
|---|---|
DriverManagerConnectionSource(ValueMap config)
|
|
| Method Summary | |
|---|---|
Connection |
getConnection()
Returns a Connection (potentially from a shared resource pool). |
Connection |
getConnection(long msTimeout)
Returns a Connection (potentially from a shared resource pool). |
void |
shutdown()
Call this when done with the ConnectionSource to allow any underlying allocated resources to be released. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String DRIVER_KEY
sql.connection.driver
public static final String URL_KEY
sql.connection.url
public static final String USERNAME_KEY
sql.connection.username
public static final String PASSWORD_KEY
sql.connection.password
public static final String EXTRAS_PREFIX
ValueMap conInfo = config.getNestedValueMap(EXTRAS_PREFIX);
The value of this constant is always (note the trailing period):
sql.connection.extras.
| Constructor Detail |
|---|
public DriverManagerConnectionSource(ValueMap config)
throws SQLException
SQLException| Method Detail |
|---|
public Connection getConnection(long msTimeout)
throws SQLTimedOutException,
SQLInterruptedException,
SQLShutdownException,
SQLException
ConnectionSourceConnection (potentially from a shared resource pool).
This connection may be checked out from a shared pool of connections or
may be from some other source. When done with a Connection,
be sure to close it to potentially return it to a pool. Due to
the fact that this Connection might be in a shared pool, you
must ensure that after you have called close, your code does
not do anything more with this Connection or anything it
created (like a Statement, or a ResultSet).
Calls to this method may block while waiting for a Connection if there is a maximum number of connections allowed in an underlying resource pool.
getConnection in interface ConnectionSourcemsTimeout - the maximum amount of time to wait for a connection
to become available.
SQLTimedOutException - if the specific maximum waiting time
is exceeded and still no connection is available.
Only some implementations (ones that support timeout detection)
throw this specific SQLException.
This is a subclass of SQLException so callers can optionally
ignore this specific kind of exception by simply catching
SQLException.
SQLInterruptedException - if calling thread is interrupted while
waiting for a connection to become available.
Only some implementations (ones that support interrupt detection)
throw this specific SQLException.
This is a subclass of SQLException so callers can optionally
ignore this specific kind of exception by simple catching
SQLException.
SQLException - if there is trouble getting a connection.
SQLShutdownException
public Connection getConnection()
throws SQLException
ConnectionSourceConnection (potentially from a shared resource pool).
This connection may be checked out from a shared pool of connections or
may be from some other source. When done with a Connection,
be sure to close it to potentially return it to a pool. Due to
the fact that this Connection might be in a shared pool, you
must ensure that after you have called close, your code does
not do anything more with this Connection or anything it
created (like a Statement, or a ResultSet).
Calls to this method may block while waiting for a Connection if there is a maximum number of connections allowed in an underlying resource pool.
getConnection in interface ConnectionSourceSQLInterruptedException - if calling thread is interrupted while
waiting for a connection to become available.
Only some implementations (ones that support interrupt detection)
throw this specific SQLException.
This is a subclass of SQLException so callers can optionally
ignore this specific kind of exception by simple catching
SQLException.
SQLException - if there is trouble getting a connection.public void shutdown()
ConnectionSource
shutdown in interface ConnectionSource
|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||