de.mathema.pride
Class ResourceAccessorWeb
java.lang.Object
de.mathema.pride.AbstractResourceAccessor
de.mathema.pride.ResourceAccessorJ2EE
de.mathema.pride.ResourceAccessorWeb
- All Implemented Interfaces:
- ResourceAccessor, SQLFormatter
public class ResourceAccessorWeb
- extends ResourceAccessorJ2EE
ResourceAccessor
for servlet engines.
This implementation is somehow a mixture of what is done by ResourceAccessorJ2EE
and ResourceAccessorJ2SE
. It fetches database connections from a
DataSource
but keeps it alive in a ThreadLocal until it is explicitely
released.
- Author:
- Jan Lessner
Constructor Summary |
ResourceAccessorWeb(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
ResourceAccessorWeb
public ResourceAccessorWeb(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.
- Throws:
java.lang.Exception
getConnection
public java.sql.Connection getConnection(java.lang.String db)
throws java.sql.SQLException,
javax.naming.NamingException
- Return a JDBC database connection.
The passed database name is interpreted as a JNDI name used to
lookup a
DataSource
to get a connection from. If the JNDI
name doesn't start with "java:comp/env", it is extended accordingly.
The lookup is performed only once and the DataSource is stored as
a member variable for reuse in subsequent calls of getConnection
.
- Specified by:
getConnection
in interface ResourceAccessor
- Overrides:
getConnection
in class ResourceAccessorJ2EE
- Throws:
java.sql.SQLException
javax.naming.NamingException
releaseConnection
public void releaseConnection()
throws java.sql.SQLException
- Close the current thread's connection.
This function must be explicitely called at the top-level of the call
chain before the servlet end up its job. This is the same thing like in
J2SE environments.
- Specified by:
releaseConnection
in interface ResourceAccessor
- Overrides:
releaseConnection
in class ResourceAccessorJ2EE
- Throws:
java.sql.SQLException
releaseConnection
public void releaseConnection(java.sql.Connection con)
throws java.sql.SQLException
- Does nothing at all. Although working with a data source and
a pooled connection, the servlet engine by default does not perform
any transaction management and would place the connection back into
the pool and abort the current work. So we keep it alive.
- Specified by:
releaseConnection
in interface ResourceAccessor
- Overrides:
releaseConnection
in class ResourceAccessorJ2EE
- Throws:
java.sql.SQLException