public class MonitoredDataSource extends ResourcePool implements javax.sql.DataSource, javax.sql.ConnectionEventListener, ConnectionStats, atg.service.jdbc.DataSourceShutdownSender
As a child of the ResourcePool class, this DataSource inherits all of that class's resource creation and pooling features. However, the inherited checkout/checkIn methods should never be used. Connections should be obtained from the pool via the DataSource.getConnection() method and returned to the pool by calling Connection.close(). Whereas in previous implentations of a Connection pool it was imperative to never call close on the pooled Connection, use of this implementation requires Connection.close() to be called. Calling Connection.close() does not actually close the Connection. Instead, this is the method defined in the J2EE JDBC extensions for returning pooled Connections to the Connection pool.
This DataSource is designed to only work on top of an XADataSource. Therefore, when used within the scope of a distributed transaction commit(), rollback(), and setAutoCommit() should never be called on Connections obtained from it. Those functions are executed by the TransactionManager. When used in local transaction mode, i.e. outside the scope of a distributed transaction, all of the Connections transactional methods are available for use.
Typical usage of this DataSource might look as follows:
DataSource ds =Note this example assumes a distributed transaction is in place meaning transactioning is handled by JTA and no transactioning methods are called on the Connection itself.; Connection c = null; try { try { c = ds.getConnection(); // Various work without calling c.commit() or c.rollback(). } finally { // Closing of the Connection must always occur or else // Connections will not be returned to the pool properly! if (c != null) c.close(); } } catch (SQLException sqle) { // If something went wrong, we might want to rollback // the transaction. }
All Connections produced by this DataSource are MonitoredConnections, i.e. they are normal Connections wrapped for the purpose of gathering statistics. Because of this, message logging is achievable at a finer granularity. The standard ApplicationLogging interface exists for messages generated by the DataSource proper and a variant of the interface is implemented for the logging of messages generated by Connections. Use the methods loggingSQLInfo(), loggingSQLDebug(), loggingSQLWarning(), and loggingSQLError() to turn off message logging for Connections created by this DataSource.
Modifier and Type | Class and Description |
---|---|
class |
MonitoredDataSource.SQLLogging
A utility class which builds a separate logging interface for SQL
logging to have access to.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string
|
mBlocking, mCheckoutBlockTime, mCreatingResources, mCreationTimeLimit, mFreeResources, mHealthy, mMax, mMaxFree, mMaxPendingCreations, mMaxStartupAttempts, mMin, mPool, mResourceClassName, mStartupSleepTime, mUnusedPoolSlots
SERVICE_INFO_KEY
RESOURCE_BUNDLE, RSRC_blockTimeout, RSRC_ciCreateFailure, RSRC_ciForeignResource, RSRC_ciWrongResource, RSRC_coNonRunning, RSRC_creationLimit, RSRC_creationTimeout, RSRC_failedInitialPopulation, RSRC_hitPoolMax, RSRC_maxResourcePerThread, RSRC_maxThreads, RSRC_misconfiguration, RSRC_nestedCheckout, RSRC_nonOwningThread, RSRC_notImplemented, RSRC_poolDisabled, RSRC_startupFailure, RSRC_usingClosedConnection
DEFAULT_LOG_TRACE_STATUS
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
Constructor and Description |
---|
MonitoredDataSource()
Constructs an uninitialized MonitoredDataSource.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addAdminInfo(javax.servlet.http.HttpServletRequest pRequest,
javax.servlet.http.HttpServletResponse pResponse,
javax.servlet.ServletOutputStream pOut)
Adds to the HTML Admin response any information specific to the
the ResourcePool subclass.
|
void |
addDataSourceShutdownListener(atg.service.jdbc.DataSourceShutdownListener pListener)
Adds the given listener to the shutdown sender's list of
listeners.
|
void |
checkIn(ResourceObject pResource)
Though this class extends ResourcePool, it is not meant to be
used as a ResourcePool is used.
|
ResourceObject |
checkOut(java.lang.String pCheckOutTag)
Though this class extends ResourcePool, it is not meant to be used
as a ResourcePool is used.
|
protected void |
ci(ResourceObject pResource)
Checks a resource into the pool.
|
protected ResourceObject |
co(java.lang.String pCheckOutTag)
The internal resource checkout method.
|
void |
connectionClosed(javax.sql.ConnectionEvent pEvent)
Invoked when the application calls close() on its representation
of the connection.
|
void |
connectionErrorOccurred(javax.sql.ConnectionEvent pEvent)
Invoked when a fatal connection error occurs, just before an
SQLException is thrown to the application.
|
java.lang.Object |
createResource()
Creates a new XAConnection for use by the pool.
|
void |
destroyResource(java.lang.Object pResource)
Destroys the once pooled resource.
|
void |
doStartService()
Things to do when the service starts up.
|
void |
doStopService()
Things to do when the service is stopped.
|
int |
getCommitCount()
Returns the number of times commit() has been called
|
java.sql.Connection |
getConnection()
Returns a Connection that is participating in the current
Transaction.
|
java.sql.Connection |
getConnection(java.lang.String pUsername,
java.lang.String pPassword)
This method is unsupported in this implementation.
|
int |
getCreateStatementCount()
Returns the number of times createStatement() has been called
|
javax.sql.XADataSource |
getDataSource()
Returns property dataSource.
|
java.lang.String |
getDataSourceConnectionInfo()
Return the connection information String for our DataSource.
|
atg.service.jdbc.DataSourceInfoCache |
getDataSourceInfoCache()
Returns property dataSourceInfoCache
|
java.util.Properties |
getDataSourceJNDIEnvironment()
Returns property dataSourceJNDIEnvironment.
|
java.lang.String |
getDataSourceJNDIName()
Returns property dataSourceJNDIName.
|
int |
getErrorCount()
Returns the number of times a SQLException resulted from
calls.
|
int |
getExecuteCount()
Returns the number of times Statement.execute() has been
called
|
int |
getExecuteQueryCount()
Returns the number of times Statement.executeQuery() has been
called
|
int |
getExecuteUpdateCount()
Returns the number of times Statement.executeUpdate() has been
called
|
int |
getGetMoreResultsCount()
Returns the number of times Statement.getMoreResults() has been
called
|
java.lang.String[] |
getInitializingSQL()
Returns property initializingSQL.
|
int |
getLoginTimeout()
Returns property loginTimeout.
|
java.io.PrintWriter |
getLogWriter()
This property from the DataSource interface is ignored.
|
java.lang.Integer |
getMaxFieldSize()
Returns the size of the data that can be returned for any column.
|
java.lang.Integer |
getMaxRows()
Returns the maximum number of rows that can be returned for any query.
|
java.util.logging.Logger |
getParentLogger()
Return the parent Logger of all the Loggers used by this data source.
|
int |
getPrepareCallCount()
Returns the number of times prepareCall() has been called
|
int |
getPrepareStatementCount()
Returns the number of times prepareStatement() has been called
|
java.lang.Integer |
getQueryTimeout()
Returns the maximum number of seconds that the driver will wait for a Statement to execute.
|
int |
getResultSetRowCount()
Returns the number of times ResultSet.next() has been called
|
int |
getRollbackCount()
Returns the number of times rollback() has been called
|
javax.transaction.TransactionManager |
getTransactionManager()
Returns property transactionManager.
|
void |
incrementCommitCount()
Increments the number of times commit() has been called
|
void |
incrementCreateStatementCount()
Increments the number of times createStatement() has been called
|
void |
incrementErrorCount()
Increments the number of times a SQLException resulted from
calls.
|
void |
incrementExecuteCount()
Increments the number of times Statement.execute() has been
called
|
void |
incrementExecuteQueryCount()
Increments the number of times Statement.executeQuery() has been
called
|
void |
incrementExecuteUpdateCount()
Increments the number of times Statement.executeUpdate() has been
called
|
void |
incrementGetMoreResultsCount()
Increments the number of times Statement.getMoreResults() has been
called
|
void |
incrementPrepareCallCount()
Increments the number of times prepareCall() has been called
|
void |
incrementPrepareStatementCount()
Increments the number of times prepareStatement() has been called
|
void |
incrementResultSetRowCount()
Increments the number of times ResultSet.next() has been called
|
void |
incrementRollbackCount()
Increments the number of times rollback() has been called
|
boolean |
isDebugActiveQuery()
Returns property debugActiveQuery.
|
boolean |
isDisableDataSourceInfo()
Whether to disable providing the datasource info property (presumably
for security reasons).
|
boolean |
isEnlistBeforeGet()
Returns property enlistBeforeGet.
|
boolean |
isLogDebugStacktrace()
Returns property logDebugStacktrace.
|
boolean |
isLoggingSQLDebug()
This method returns whether or not an debug log event should be
broadcast for MonitoredConnections.
|
boolean |
isLoggingSQLError()
This method returns whether or not an error log event should be
broadcast for MonitoredConnections.
|
boolean |
isLoggingSQLInfo()
This method returns whether or not an info log event should be
broadcast for MonitoredConnections.
|
boolean |
isLoggingSQLWarning()
This method returns whether or not an warning log event should be
broadcast for MonitoredConnections.
|
boolean |
isWrapperFor(java.lang.Class<?> pInterface)
Returns true if this class implements the pInterface argument
|
protected void |
reclaimResource(ResourceObject pRobj)
Reclaims a resource that is most likely out of the pool.
|
void |
removeDataSourceShutdownListener(atg.service.jdbc.DataSourceShutdownListener pListener)
Removes the given listener from the shutdown sender's list of
shutdown listeners.
|
void |
setDataSource(javax.sql.XADataSource pXADataSource)
Sets the property dataSource.
|
void |
setDataSourceInfoCache(atg.service.jdbc.DataSourceInfoCache pDataSourceInfoCache)
Sets the data source info cache, which is used to extract
human readable information.
|
void |
setDataSourceJNDIEnvironment(java.util.Properties pDataSourceJNDIEnvironment)
Sets property dataSourceJNDIEnvironment.
|
void |
setDataSourceJNDIName(java.lang.String pDataSourceJNDIName)
Sets property dataSourceJNDIName.
|
void |
setDebugActiveQuery(boolean pDebugActiveQuery)
Sets property debugActiveQuery.
|
void |
setDisableDataSourceInfo(boolean pDisableDataSourceInfo)
Set whether to disable providing the datasource info property (presumably
for security reasons).
|
void |
setEnlistBeforeGet(boolean pEnlistBeforeGet)
Sets property enlistBeforeGet.
|
void |
setInitializingSQL(java.lang.String[] pInitializingSQL)
Sets property initializingSQL.
|
void |
setLogDebugStacktrace(boolean pLogDebugStacktrace)
Sets property logDebugStacktrace.
|
void |
setLoggingSQLDebug(boolean pLogging)
Sets whether or not error log events should be logged for MonitoredConnections.
|
void |
setLoggingSQLError(boolean pLogging)
Sets whether or not error log events should be logged for MonitoredConnections.
|
void |
setLoggingSQLInfo(boolean pLogging)
Sets whether or not info log events should be logged for MonitoredConnections.
|
void |
setLoggingSQLWarning(boolean pLogging)
Sets whether or not warning log events should be logged for MonitoredConnections.
|
void |
setLoginTimeout(int pLoginTimeout)
Sets property loginTimeout.
|
void |
setLogWriter(java.io.PrintWriter pLogWriter)
This property from the DataSource interface is ignored.
|
void |
setMaxFieldSize(java.lang.Integer pMaxFieldSize)
Sets the size of the data that can be returned for any column.
|
void |
setMaxRows(java.lang.Integer pMaxRows)
Sets the maximum number of rows that can be returned for any query.
|
void |
setQueryTimeout(java.lang.Integer pQueryTimeout)
Sets the maximum number of seconds that the driver will wait for a Statement to execute.
|
void |
setTransactionManager(javax.transaction.TransactionManager pValue) |
<T> T |
unwrap(java.lang.Class<T> pInterface)
Returns an object that implements the given interface
|
boolean |
verifyResourceValidity(ResourceObject pRobj)
In the non-J2EE world, connections were verified by seeing if
they had been closed by someone.
|
block, createAdminServlet, finalize, getAverageResourceCreationTime, getBlocking, getCheckoutBlockTime, getCreationTimeLimit, getCurrentStack, getDebugConnections, getLastError, getMax, getMaxConcurrentResourcesPerThread, getMaxConcurrentThreads, getMaxFree, getMaxIdleAge, getMaxPendingCreations, getMaxResourceAge, getMaxResourcesPerThread, getMaxSimultaneousResourcesOut, getMaxThreadsWithResourcesOut, getMin, getNumCheckedOutResources, getNumFreeResources, getNumTotalResources, getResourceClassName, getStartupAttempts, getStartupFailureSleepTime, invalidateAllResources, isEnabled, isWarnOnNestedCheckouts, populateSlot, pruneFreeResources, resetMaxConcurrentResourcesPerThread, resetMaxConcurrentThreads, resetMaxSimultaneousResourcesOut, setBlocking, setCheckoutBlockTime, setCreationTimeLimit, setDebugConnections, setLastError, setMax, setMaxFree, setMaxIdleAge, setMaxPendingCreations, setMaxResourceAge, setMaxResourcesPerThread, setMaxThreadsWithResourcesOut, setMin, setResourceClassName, setStartupAttempts, setStartupFailureSleepTime, setWarnOnNestedCheckouts, unblock
addLogListener, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
public MonitoredDataSource()
public void setDataSourceJNDIName(java.lang.String pDataSourceJNDIName)
pDataSourceJNDIName
- new value to setpublic java.lang.String getDataSourceJNDIName()
public void setDataSourceJNDIEnvironment(java.util.Properties pDataSourceJNDIEnvironment)
pDataSourceJNDIEnvironment
- new value to setpublic java.util.Properties getDataSourceJNDIEnvironment()
public void setDataSource(javax.sql.XADataSource pXADataSource)
pXADataSource
- new value to setpublic javax.sql.XADataSource getDataSource()
public void setTransactionManager(javax.transaction.TransactionManager pValue)
public javax.transaction.TransactionManager getTransactionManager()
public boolean isLoggingSQLInfo()
public void setLoggingSQLInfo(boolean pLogging)
public boolean isLoggingSQLWarning()
public void setLoggingSQLWarning(boolean pLogging)
public boolean isLoggingSQLError()
public void setLoggingSQLError(boolean pLogging)
public boolean isLoggingSQLDebug()
public void setLoggingSQLDebug(boolean pLogging)
public java.lang.Integer getMaxFieldSize()
public void setMaxFieldSize(java.lang.Integer pMaxFieldSize)
public java.lang.Integer getMaxRows()
public void setMaxRows(java.lang.Integer pMaxRows)
public java.lang.Integer getQueryTimeout()
public void setQueryTimeout(java.lang.Integer pQueryTimeout)
public void setInitializingSQL(java.lang.String[] pInitializingSQL)
pInitializingSQL
- new value to setpublic java.lang.String[] getInitializingSQL()
public void setEnlistBeforeGet(boolean pEnlistBeforeGet)
pEnlistBeforeGet
- new value to setpublic boolean isEnlistBeforeGet()
public void setLogDebugStacktrace(boolean pLogDebugStacktrace)
pLogDebugStacktrace
- new value to setpublic boolean isLogDebugStacktrace()
public void setDebugActiveQuery(boolean pDebugActiveQuery)
This should not be used except when debugging as more overhead will be generated from this feature.
pDebugActiveQuery
- new value to setpublic boolean isDebugActiveQuery()
This should not be used except when debugging as more overhead will be generated from this feature.
public void setLoginTimeout(int pLoginTimeout)
setLoginTimeout
in interface javax.sql.CommonDataSource
pLoginTimeout
- new value to setpublic int getLoginTimeout()
getLoginTimeout
in interface javax.sql.CommonDataSource
public void setLogWriter(java.io.PrintWriter pLogWriter)
setLogWriter
in interface javax.sql.CommonDataSource
public java.io.PrintWriter getLogWriter()
getLogWriter
in interface javax.sql.CommonDataSource
public void setDataSourceInfoCache(atg.service.jdbc.DataSourceInfoCache pDataSourceInfoCache)
public atg.service.jdbc.DataSourceInfoCache getDataSourceInfoCache()
public void setDisableDataSourceInfo(boolean pDisableDataSourceInfo)
public boolean isDisableDataSourceInfo()
public java.lang.String getDataSourceConnectionInfo()
public void doStartService() throws ServiceException
doStartService
in class ResourcePool
ServiceException
- if an error occurred during the operationpublic void doStopService() throws ServiceException
doStopService
in class ResourcePool
ServiceException
- if an error occurred during the operationpublic java.lang.Object createResource() throws ResourcePoolException
createResource
in class ResourcePool
ResourcePoolException
- if there was a problem creating
the XAConnectionpublic void destroyResource(java.lang.Object pResource)
destroyResource
in class ResourcePool
pResource
- the Object to destroypublic boolean verifyResourceValidity(ResourceObject pRobj)
verifyResourceValidity
in class ResourcePool
pResource
- the ResourceObject to verifypublic ResourceObject checkOut(java.lang.String pCheckOutTag) throws ResourcePoolException
checkOut
in class ResourcePool
ResourcePoolException
- always thrown when calledpublic void checkIn(ResourceObject pResource) throws ResourcePoolException
checkIn
in class ResourcePool
pResource
- a resource checked out from this poolResourcePoolException
- always thrown when calledpublic java.sql.Connection getConnection(java.lang.String pUsername, java.lang.String pPassword) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public void connectionClosed(javax.sql.ConnectionEvent pEvent)
connectionClosed
in interface javax.sql.ConnectionEventListener
pEvent
- an event object describing the source of the eventpublic void connectionErrorOccurred(javax.sql.ConnectionEvent pEvent)
connectionErrorOccurred
in interface javax.sql.ConnectionEventListener
pEvent
- an event object describing the source of the eventpublic void addDataSourceShutdownListener(atg.service.jdbc.DataSourceShutdownListener pListener)
addDataSourceShutdownListener
in interface atg.service.jdbc.DataSourceShutdownSender
pListener
- the listner wanting to know of shutdown eventspublic void removeDataSourceShutdownListener(atg.service.jdbc.DataSourceShutdownListener pListener)
removeDataSourceShutdownListener
in interface atg.service.jdbc.DataSourceShutdownSender
pListener
- the listner wanting of the shutdown listener listpublic void incrementErrorCount()
incrementErrorCount
in interface ConnectionStats
public int getErrorCount()
public void incrementCommitCount()
incrementCommitCount
in interface ConnectionStats
public int getCommitCount()
public void incrementRollbackCount()
incrementRollbackCount
in interface ConnectionStats
public int getRollbackCount()
public void incrementCreateStatementCount()
incrementCreateStatementCount
in interface ConnectionStats
public int getCreateStatementCount()
public void incrementPrepareStatementCount()
incrementPrepareStatementCount
in interface ConnectionStats
public int getPrepareStatementCount()
public void incrementPrepareCallCount()
incrementPrepareCallCount
in interface ConnectionStats
public int getPrepareCallCount()
public void incrementExecuteQueryCount()
incrementExecuteQueryCount
in interface ConnectionStats
public int getExecuteQueryCount()
public void incrementExecuteUpdateCount()
incrementExecuteUpdateCount
in interface ConnectionStats
public int getExecuteUpdateCount()
public void incrementExecuteCount()
incrementExecuteCount
in interface ConnectionStats
public int getExecuteCount()
public void incrementGetMoreResultsCount()
incrementGetMoreResultsCount
in interface ConnectionStats
public int getGetMoreResultsCount()
public void incrementResultSetRowCount()
incrementResultSetRowCount
in interface ConnectionStats
public int getResultSetRowCount()
public <T> T unwrap(java.lang.Class<T> pInterface) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
pInterface
- the interface of the object to returnjava.sql.SQLException
- if no object is found that implements
the given interfacepublic boolean isWrapperFor(java.lang.Class<?> pInterface) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
pInterface
- the interface to testjava.sql.SQLException
- if there's an error determining whether this is
a wrapper for the interfacepublic java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
getParentLogger
in interface javax.sql.CommonDataSource
java.sql.SQLFeatureNotSupportedException
- if the data source does not use java.util.logging.
protected ResourceObject co(java.lang.String pCheckOutTag) throws ResourcePoolException
ResourcePoolException
- if an error occurred during the
operationprotected void ci(ResourceObject pResource) throws ResourcePoolException
pResource
- a resource checked out from this poolResourcePoolException
- if an error occurred during the
operationprotected void reclaimResource(ResourceObject pRobj) throws ResourcePoolException
reclaimResource
in class ResourcePool
ResourcePoolException
protected void addAdminInfo(javax.servlet.http.HttpServletRequest pRequest, javax.servlet.http.HttpServletResponse pResponse, javax.servlet.ServletOutputStream pOut) throws javax.servlet.ServletException, java.io.IOException
addAdminInfo
in class ResourcePool
javax.servlet.ServletException
java.io.IOException