de.mathema.pride
Class ResourceAccessorJ2SE
java.lang.Object
de.mathema.pride.AbstractResourceAccessor
de.mathema.pride.ResourceAccessorJ2SE
- All Implemented Interfaces:
- ResourceAccessor, SQLFormatter
public class ResourceAccessorJ2SE
- extends AbstractResourceAccessor
Simple ResourceAccessor
for J2SE environments.
This implementation stores database connections in a ThreadLocal
object, which garuantees fast connection access and multi-threading safety.
However, the connection is kept until the accessor is invoked with a different
database name. It is therefore recommended to work with multiple accessors
if you need to swith rapidly between multiple databases.
- Author:
- Jan Lessner
Constructor Summary |
ResourceAccessorJ2SE(java.util.Properties props)
Constructs a new ResourceAccessor for use in a J2SE environment |
Method Summary |
java.sql.Connection |
getConnection(java.lang.String db)
Return a JDBC database connection. |
void |
releaseConnection()
Close the current thread's connection. |
void |
releaseConnection(java.sql.Connection con)
Does nothing at all |
Methods inherited from class de.mathema.pride.AbstractResourceAccessor |
castJavaUtilDate, commonDateFormat, escape, escapeBackslahes, escapeQuotes, formatBoolean, formatDate, formatEnum, formatOperator, formatPreparedValue, formatTime, formatValue, getAutoFields, getAutoFieldVals, getDBType, getSystime, getTableName, getURL, getUserName, isLogging, setAutoCommit, setLogging, sqlLog, sqlLogError, standardOperator |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
REVISION_ID
public static final java.lang.String REVISION_ID
- See Also:
- Constant Field Values
ResourceAccessorJ2SE
public ResourceAccessorJ2SE(java.util.Properties props)
throws java.lang.Exception
- Constructs a new ResourceAccessor for use in a J2SE environment
- Parameters:
props
- The configuration for the resource accessor. See interface
ResourceAccessor.Config
for available parameters. The property
ResourceAccessor.Config.DRIVER
is mandatory
- Throws:
java.lang.Exception
getConnection
public java.sql.Connection getConnection(java.lang.String db)
throws java.sql.SQLException
- Return a JDBC database connection.
There is one unique connection returned per thread and kept allocated
until this function is invoked with a different database name or
function
releaseConnection()
is explicitely called. The
connection is optained from DriverManager.getConnection() passing
either user and password when specified in the constructor by
properties ResourceAccessor.Config.USER
and ResourceAccessor.Config.USER
or otherwise passing the complete constructor Properties list as is.
- Throws:
java.sql.SQLException
releaseConnection
public void releaseConnection()
throws java.sql.SQLException
- Close the current thread's connection.
It is recommended to explicitely release connections if the associated
thread is about to terminate or sleep for a long time. JDBC's built-in
connection garbage collection is either not working at all or is not
this agile as it may be required.
- Throws:
java.sql.SQLException
releaseConnection
public void releaseConnection(java.sql.Connection con)
throws java.sql.SQLException
- Does nothing at all
- Throws:
java.sql.SQLException