Package com.sun.gjc.spi
Class ManagedConnectionImpl
- java.lang.Object
-
- com.sun.gjc.spi.ManagedConnectionImpl
-
- All Implemented Interfaces:
jakarta.resource.spi.DissociatableManagedConnection,jakarta.resource.spi.LazyEnlistableManagedConnection,jakarta.resource.spi.ManagedConnection
public class ManagedConnectionImpl extends Object implements jakarta.resource.spi.ManagedConnection, jakarta.resource.spi.LazyEnlistableManagedConnection, jakarta.resource.spi.DissociatableManagedConnection
ManagedConnectionimplementation for Generic JDBC Connector.- Version:
- 1.0, 02/07/22
- Author:
- Evani Sai Surya Kiran
-
-
Field Summary
Fields Modifier and Type Field Description protected static Logger_loggerprotected ConnectionactualConnectionprotected jakarta.resource.spi.ConnectionEventceprotected intconnectionCountprotected HashtableconnectionHandlesprotected intconnectionTypeprotected booleaninitSqlExecutedstatic StringIS_SLOW_SQL_LOGGING_DISABLEDprotected booleanisCleanprotected booleanisDestroyedstatic intISNOTAPOOLEDCONNECTIONstatic intISPOOLEDCONNECTIONprotected booleanisUsablestatic intISXACONNECTIONprotected intlastTransactionIsolationLevelprotected StatementLeakDetectorleakDetectorprotected jakarta.resource.spi.ConnectionEventListenerlistenerprotected static StringManagerlocalStringsprotected PrintWriterlogWriterprotected ConnectionHoldermyLogicalConnectionprotected jakarta.resource.spi.security.PasswordCredentialpasswdCredentialprotected PooledConnectionpcprotected booleantransactionInProgressprotected XAResourcexar
-
Constructor Summary
Constructors Constructor Description ManagedConnectionImpl(PooledConnection pooledConn, Connection sqlConn, jakarta.resource.spi.security.PasswordCredential passwdCred, jakarta.resource.spi.ManagedConnectionFactory mcf, PoolInfo poolInfo, int statementCacheSize, String statementCacheType, SQLTraceDelegator delegator, long statementLeakTimeout, boolean statementLeakReclaim)Constructor forManagedConnectionImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)Adds a connection event listener to the ManagedConnectionImpl instance.voidassociateConnection(Object connection)Used by the container to change the association of an application-level connection handle with aManagedConnectionImplinstance.voidcheckIfActive(ConnectionHolder ch)This method is called by a Connection Handle to check if it is the active Connection Handle.voidcleanup()Application server calls this method to force any cleanup on theManagedConnectionImplinstance.voidconnectionClosed(Exception e, ConnectionHolder connHolderObject)This method is called by theConnectionHolderwhen its close method is called.voiddecrementCount()voiddestroy()Destroys the physical connection to the underlying resource manager.voiddissociateConnections()DatabaseMetaDatagetCachedDatabaseMetaData()Returns the cachedDatabaseMetaData.ObjectgetConnection(Subject sub, jakarta.resource.spi.ConnectionRequestInfo cxReqInfo)Creates a new connection handle for the underlying physical connection represented by theManagedConnectionImplinstance.protected intgetConnectionType(PooledConnection pooledConn)This method determines the type of the connection being held in thisManagedConnectionImpl.booleangetLastAutoCommitValue()StatementLeakDetectorgetLeakDetector()jakarta.resource.spi.LocalTransactiongetLocalTransaction()Returns anLocalTransactionImplinstance.PrintWritergetLogWriter()Gets the log writer for thisManagedConnectionImplinstance.ManagedConnectionFactoryImplgetManagedConnectionFactory()Returns theManagedConnectionFactoryinstance that created thisManagedConnectioninstance.jakarta.resource.spi.ManagedConnectionFactorygetMcf()jakarta.resource.spi.ManagedConnectionMetaDatagetMetaData()Gets the metadata information for this connection's underlying EIS resource manager instance.intgetStatementTimeout()XAResourcegetXAResource()Returns anXAResourceinstance.voidincrementCount()voidinitializeConnectionType(int _connectionType)sets the connection type of this connection.protected voidinvalidateAllConnectionHandles()This method removes all the connection handles from the table of connection handles and invalidates all of them so that any operation on those connection handles throws an exception.booleanisAborted()BooleanisClientInfoSupported()booleanisTransactionInProgress()Checks if a this ManagedConnection is involved in a transaction or not.voidmarkForRemoval(boolean flag)CallableStatementprepareCachedCallableStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency)CallableStatementprepareCachedCallableStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)PreparedStatementprepareCachedStatement(ConnectionWrapper conWrapper, String sql, int autoGeneratedKeys)PreparedStatementprepareCachedStatement(ConnectionWrapper conWrapper, String sql, int[] columnIndexes)PreparedStatementprepareCachedStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency)PreparedStatementprepareCachedStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)PreparedStatementprepareCachedStatement(ConnectionWrapper conWrapper, String sql, String[] columnNames)voidpurgeStatementFromCache(PreparedStatement preparedStatement)voidremoveConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)Removes an already registered connection event listener from theManagedConnectionImplinstance.voidsetAborted(boolean flag)voidsetClientInfoSupported(Boolean isClientInfoSupported)voidsetLastAutoCommitValue(boolean lastAutoCommitValue)To keep track of last auto commit value.voidsetLastTransactionIsolationLevel(int isolationLevel)voidsetLogWriter(PrintWriter out)Sets the log writer for thisManagedConnectionImplinstance.
-
-
-
Field Detail
-
ISNOTAPOOLEDCONNECTION
public static final int ISNOTAPOOLEDCONNECTION
- See Also:
- Constant Field Values
-
ISPOOLEDCONNECTION
public static final int ISPOOLEDCONNECTION
- See Also:
- Constant Field Values
-
ISXACONNECTION
public static final int ISXACONNECTION
- See Also:
- Constant Field Values
-
isDestroyed
protected boolean isDestroyed
-
isUsable
protected boolean isUsable
-
initSqlExecuted
protected boolean initSqlExecuted
-
connectionCount
protected int connectionCount
-
IS_SLOW_SQL_LOGGING_DISABLED
public static final String IS_SLOW_SQL_LOGGING_DISABLED
- See Also:
- Constant Field Values
-
connectionType
protected int connectionType
-
pc
protected PooledConnection pc
-
actualConnection
protected Connection actualConnection
-
connectionHandles
protected Hashtable connectionHandles
-
logWriter
protected PrintWriter logWriter
-
passwdCredential
protected jakarta.resource.spi.security.PasswordCredential passwdCredential
-
xar
protected XAResource xar
-
myLogicalConnection
protected ConnectionHolder myLogicalConnection
-
lastTransactionIsolationLevel
protected int lastTransactionIsolationLevel
-
isClean
protected boolean isClean
-
transactionInProgress
protected boolean transactionInProgress
-
listener
protected jakarta.resource.spi.ConnectionEventListener listener
-
ce
protected jakarta.resource.spi.ConnectionEvent ce
-
leakDetector
protected StatementLeakDetector leakDetector
-
_logger
protected static final Logger _logger
-
localStrings
protected static final StringManager localStrings
-
-
Constructor Detail
-
ManagedConnectionImpl
public ManagedConnectionImpl(PooledConnection pooledConn, Connection sqlConn, jakarta.resource.spi.security.PasswordCredential passwdCred, jakarta.resource.spi.ManagedConnectionFactory mcf, PoolInfo poolInfo, int statementCacheSize, String statementCacheType, SQLTraceDelegator delegator, long statementLeakTimeout, boolean statementLeakReclaim) throws jakarta.resource.ResourceException
Constructor forManagedConnectionImpl. The pooledConn parameter is expected to be null and sqlConn parameter is the actual connection in case where the actual connection is got from a non pooled datasource object. The pooledConn parameter is expected to be non null and sqlConn parameter is expected to be null in the case where the datasource object is a connection pool datasource or an xa datasource.- Parameters:
pooledConn-PooledConnectionobject in case the physical connection is to be obtained from a pooledDataSource; null otherwisesqlConn-java.sql.Connectionobject in case the physical connection is to be obtained from a non pooledDataSource; null otherwisepasswdCred- object conatining the user and password for allocating the connection- Throws:
jakarta.resource.ResourceException- if theManagedConnectionFactoryobject that created thisManagedConnectionImplobject is not the same as returned byPasswordCredentialobject passed
-
-
Method Detail
-
getLeakDetector
public StatementLeakDetector getLeakDetector()
-
addConnectionEventListener
public void addConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)
Adds a connection event listener to the ManagedConnectionImpl instance.- Specified by:
addConnectionEventListenerin interfacejakarta.resource.spi.ManagedConnection- Parameters:
listener-ConnectionEventListener- See Also:
removeConnectionEventListener(jakarta.resource.spi.ConnectionEventListener)
-
associateConnection
public void associateConnection(Object connection) throws jakarta.resource.ResourceException
Used by the container to change the association of an application-level connection handle with aManagedConnectionImplinstance.- Specified by:
associateConnectionin interfacejakarta.resource.spi.ManagedConnection- Parameters:
connection-ConnectionHolderto be associated with thisManagedConnectionImplinstance- Throws:
jakarta.resource.ResourceException- if the physical connection is no more valid or the connection handle passed is null
-
cleanup
public void cleanup() throws jakarta.resource.ResourceExceptionApplication server calls this method to force any cleanup on theManagedConnectionImplinstance. This method calls the invalidate method on all ConnectionHandles associated with thisManagedConnectionImpl.- Specified by:
cleanupin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.ResourceException- if the physical connection is no more valid
-
invalidateAllConnectionHandles
protected void invalidateAllConnectionHandles() throws jakarta.resource.ResourceExceptionThis method removes all the connection handles from the table of connection handles and invalidates all of them so that any operation on those connection handles throws an exception.- Throws:
jakarta.resource.ResourceException- if there is a problem in retrieving the connection handles
-
destroy
public void destroy() throws jakarta.resource.ResourceExceptionDestroys the physical connection to the underlying resource manager.- Specified by:
destroyin interfacejakarta.resource.spi.ManagedConnection- Throws:
jakarta.resource.ResourceException- if there is an error in closing the physical connection
-
getConnection
public Object getConnection(Subject sub, jakarta.resource.spi.ConnectionRequestInfo cxReqInfo) throws jakarta.resource.ResourceException
Creates a new connection handle for the underlying physical connection represented by theManagedConnectionImplinstance.- Specified by:
getConnectionin interfacejakarta.resource.spi.ManagedConnection- Parameters:
sub-Subjectparameter needed for authenticationcxReqInfo-ConnectionRequestInfocarries the user and password required for getting this connection.- Returns:
- Connection the connection handle
Object - Throws:
jakarta.resource.ResourceException- if there is an error in allocating the physical connection from the pooled connectionjakarta.resource.spi.SecurityException- if there is a mismatch between the password credentials or reauthentication is requested
-
getLocalTransaction
public jakarta.resource.spi.LocalTransaction getLocalTransaction() throws jakarta.resource.ResourceExceptionReturns anLocalTransactionImplinstance. TheLocalTransactionImplinterface is used by the container to manage local transactions for a RM instance.- Specified by:
getLocalTransactionin interfacejakarta.resource.spi.ManagedConnection- Returns:
LocalTransactionImplinstance- Throws:
jakarta.resource.ResourceException- if the physical connection is not valid
-
getLogWriter
public PrintWriter getLogWriter() throws jakarta.resource.ResourceException
Gets the log writer for thisManagedConnectionImplinstance.- Specified by:
getLogWriterin interfacejakarta.resource.spi.ManagedConnection- Returns:
PrintWriterinstance associated with thisManagedConnectionImplinstance- Throws:
jakarta.resource.ResourceException- if the physical connection is not valid- See Also:
setLogWriter
-
getMetaData
public jakarta.resource.spi.ManagedConnectionMetaData getMetaData() throws jakarta.resource.ResourceExceptionGets the metadata information for this connection's underlying EIS resource manager instance.- Specified by:
getMetaDatain interfacejakarta.resource.spi.ManagedConnection- Returns:
ManagedConnectionMetaDatainstance- Throws:
jakarta.resource.ResourceException- if the physical connection is not valid
-
getXAResource
public XAResource getXAResource() throws jakarta.resource.ResourceException
Returns anXAResourceinstance.- Specified by:
getXAResourcein interfacejakarta.resource.spi.ManagedConnection- Returns:
XAResourceinstance- Throws:
jakarta.resource.ResourceException- if the physical connection is not valid or there is an error in allocating theXAResourceinstancejakarta.resource.NotSupportedException- if underlying datasource is not anXADataSource
-
removeConnectionEventListener
public void removeConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)
Removes an already registered connection event listener from theManagedConnectionImplinstance.- Specified by:
removeConnectionEventListenerin interfacejakarta.resource.spi.ManagedConnection- Parameters:
listener-ConnectionEventListenerto be removed- See Also:
addConnectionEventListener(jakarta.resource.spi.ConnectionEventListener)
-
isTransactionInProgress
public boolean isTransactionInProgress()
Checks if a this ManagedConnection is involved in a transaction or not.
-
setLogWriter
public void setLogWriter(PrintWriter out) throws jakarta.resource.ResourceException
Sets the log writer for thisManagedConnectionImplinstance.- Specified by:
setLogWriterin interfacejakarta.resource.spi.ManagedConnection- Parameters:
out-PrintWriterto be associated with thisManagedConnectionImplinstance- Throws:
jakarta.resource.ResourceException- if the physical connection is not valid- See Also:
getLogWriter
-
getConnectionType
protected int getConnectionType(PooledConnection pooledConn)
This method determines the type of the connection being held in thisManagedConnectionImpl.- Parameters:
pooledConn-PooledConnection- Returns:
- connection type
-
getManagedConnectionFactory
public ManagedConnectionFactoryImpl getManagedConnectionFactory()
Returns theManagedConnectionFactoryinstance that created thisManagedConnectioninstance.- Returns:
ManagedConnectionFactoryinstance that created thisManagedConnectioninstance
-
connectionClosed
public void connectionClosed(Exception e, ConnectionHolder connHolderObject) throws SQLException
This method is called by theConnectionHolderwhen its close method is called. ThisManagedConnectioninstance invalidates the connection handle and sends a CONNECTION_CLOSED event to all the registered event listeners.- Parameters:
e- Exception that may have occured while closing the connection handleconnHolderObject-ConnectionHolderthat has been closed- Throws:
SQLException- in case closing the sql connection got out ofgetConnectionon the underlyingPooledConnectionthrows an exception
-
checkIfActive
public void checkIfActive(ConnectionHolder ch) throws SQLException
This method is called by a Connection Handle to check if it is the active Connection Handle. If it is not the active Connection Handle, this method throws an SQLException. Else, it returns setting the active Connection Handle to the calling Connection Handle object to this object if the active Connection Handle is null.- Parameters:
ch-ConnectionHolderthat requests thisManagedConnectioninstance whether it can be active or not- Throws:
SQLException- in case the physical is not valid or there is already an active connection handle
-
initializeConnectionType
public void initializeConnectionType(int _connectionType)
sets the connection type of this connection. This method is called by the MCF while creating this ManagedConnection. Saves us a costly instanceof operation in the getConnectionType
-
incrementCount
public void incrementCount()
-
decrementCount
public void decrementCount()
-
dissociateConnections
public void dissociateConnections()
- Specified by:
dissociateConnectionsin interfacejakarta.resource.spi.DissociatableManagedConnection
-
getLastAutoCommitValue
public boolean getLastAutoCommitValue()
-
setLastAutoCommitValue
public void setLastAutoCommitValue(boolean lastAutoCommitValue)
To keep track of last auto commit value. Helps to reset the auto-commit-value while giving new connection-handle.- Parameters:
lastAutoCommitValue-
-
markForRemoval
public void markForRemoval(boolean flag)
-
getMcf
public jakarta.resource.spi.ManagedConnectionFactory getMcf()
-
getStatementTimeout
public int getStatementTimeout()
-
setLastTransactionIsolationLevel
public void setLastTransactionIsolationLevel(int isolationLevel)
-
getCachedDatabaseMetaData
public DatabaseMetaData getCachedDatabaseMetaData() throws jakarta.resource.ResourceException
Returns the cachedDatabaseMetaData.- Returns:
DatabaseMetaData- Throws:
jakarta.resource.ResourceException
-
isClientInfoSupported
public Boolean isClientInfoSupported()
-
setClientInfoSupported
public void setClientInfoSupported(Boolean isClientInfoSupported)
-
prepareCachedStatement
public PreparedStatement prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency) throws SQLException
- Throws:
SQLException
-
prepareCachedStatement
public PreparedStatement prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
- Throws:
SQLException
-
prepareCachedStatement
public PreparedStatement prepareCachedStatement(ConnectionWrapper conWrapper, String sql, String[] columnNames) throws SQLException
- Throws:
SQLException
-
prepareCachedStatement
public PreparedStatement prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int[] columnIndexes) throws SQLException
- Throws:
SQLException
-
prepareCachedStatement
public PreparedStatement prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int autoGeneratedKeys) throws SQLException
- Throws:
SQLException
-
prepareCachedCallableStatement
public CallableStatement prepareCachedCallableStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency) throws SQLException
- Throws:
SQLException
-
prepareCachedCallableStatement
public CallableStatement prepareCachedCallableStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
- Throws:
SQLException
-
setAborted
public void setAborted(boolean flag)
-
isAborted
public boolean isAborted()
-
purgeStatementFromCache
public void purgeStatementFromCache(PreparedStatement preparedStatement)
-
-