de.mathema.pride
Class ResourceAccessorWeb

java.lang.Object
  extended by de.mathema.pride.AbstractResourceAccessor
      extended by de.mathema.pride.ResourceAccessorJ2EE
          extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from interface de.mathema.pride.ResourceAccessor
ResourceAccessor.AutoKeyMode, ResourceAccessor.Config, ResourceAccessor.DBType
 
Field Summary
static java.lang.String REVISION_ID
           
 
Fields inherited from class de.mathema.pride.ResourceAccessorJ2EE
globalDataSource, LOCAL_JNDI_CONTEXT
 
Fields inherited from class de.mathema.pride.AbstractResourceAccessor
autoKeyMode, dateFormat, dbPassword, dbSystime, dbType, dbUser, props, timeFormat
 
Fields inherited from interface de.mathema.pride.ResourceAccessor
SYSTIME_DEFAULT
 
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
 

Field Detail

REVISION_ID

public static final java.lang.String REVISION_ID
See Also:
Constant Field Values
Constructor Detail

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
Method Detail

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