public class XAOnlyDataSource extends GenericService implements javax.sql.DataSource, javax.sql.ConnectionEventListener, ConnectionStats
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 |
XAOnlyDataSource.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
|
SERVICE_INFO_KEY
DEFAULT_LOG_TRACE_STATUS
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
Constructor and Description |
---|
XAOnlyDataSource()
Constructs an uninitialized XAOnlyDataSource.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
doStartService()
Things to do when the service starts up.
|
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 using the default username and password.
|
java.sql.Connection |
getConnection(java.lang.String pUsername,
java.lang.String pPassword)
Returns a Connection that is participating in the current
Transaction using the given username and password.
|
int |
getCreateStatementCount()
Returns the number of times createStatement() has been called
|
javax.sql.XADataSource |
getDataSource()
Returns property dataSource.
|
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 |
isAssociativeFakeXA()
Returns property associativeFakeXA.
|
boolean |
isEnlistBeforeGet()
Returns property enlistBeforeGet.
|
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
|
void |
setAssociativeFakeXA(boolean pAssociativeFakeXA)
Sets property associativeFakeXA.
|
void |
setDataSource(javax.sql.XADataSource pXADataSource)
Sets the property dataSource.
|
void |
setDataSourceJNDIEnvironment(java.util.Properties pDataSourceJNDIEnvironment)
Sets property dataSourceJNDIEnvironment.
|
void |
setDataSourceJNDIName(java.lang.String pDataSourceJNDIName)
Sets property dataSourceJNDIName.
|
void |
setEnlistBeforeGet(boolean pEnlistBeforeGet)
Sets property enlistBeforeGet.
|
void |
setInitializingSQL(java.lang.String[] pInitializingSQL)
Sets property initializingSQL.
|
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
|
addLogListener, createAdminServlet, doStopService, 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 XAOnlyDataSource()
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 setAssociativeFakeXA(boolean pAssociativeFakeXA)
pAssociativeFakeXA
- new value to setpublic boolean isAssociativeFakeXA()
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 doStartService() throws ServiceException
doStartService
in class GenericService
ServiceException
- if the Service had a problem starting uppublic java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public 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 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 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.