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
ManagedConnection
implementation 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
_logger
protected Connection
actualConnection
protected jakarta.resource.spi.ConnectionEvent
ce
protected int
connectionCount
protected Hashtable
connectionHandles
protected int
connectionType
protected boolean
initSqlExecuted
static String
IS_SLOW_SQL_LOGGING_DISABLED
protected boolean
isClean
protected boolean
isDestroyed
static int
ISNOTAPOOLEDCONNECTION
static int
ISPOOLEDCONNECTION
protected boolean
isUsable
static int
ISXACONNECTION
protected int
lastTransactionIsolationLevel
protected StatementLeakDetector
leakDetector
protected jakarta.resource.spi.ConnectionEventListener
listener
protected static StringManager
localStrings
protected PrintWriter
logWriter
protected ConnectionHolder
myLogicalConnection
protected jakarta.resource.spi.security.PasswordCredential
passwdCredential
protected PooledConnection
pc
protected boolean
transactionInProgress
protected XAResource
xar
-
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 void
addConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)
Adds a connection event listener to the ManagedConnectionImpl instance.void
associateConnection(Object connection)
Used by the container to change the association of an application-level connection handle with aManagedConnectionImpl
instance.void
checkIfActive(ConnectionHolder ch)
This method is called by a Connection Handle to check if it is the active Connection Handle.void
cleanup()
Application server calls this method to force any cleanup on theManagedConnectionImpl
instance.void
connectionClosed(Exception e, ConnectionHolder connHolderObject)
This method is called by theConnectionHolder
when its close method is called.void
decrementCount()
void
destroy()
Destroys the physical connection to the underlying resource manager.void
dissociateConnections()
DatabaseMetaData
getCachedDatabaseMetaData()
Returns the cachedDatabaseMetaData
.Object
getConnection(Subject sub, jakarta.resource.spi.ConnectionRequestInfo cxReqInfo)
Creates a new connection handle for the underlying physical connection represented by theManagedConnectionImpl
instance.protected int
getConnectionType(PooledConnection pooledConn)
This method determines the type of the connection being held in thisManagedConnectionImpl
.boolean
getLastAutoCommitValue()
StatementLeakDetector
getLeakDetector()
jakarta.resource.spi.LocalTransaction
getLocalTransaction()
Returns anLocalTransactionImpl
instance.PrintWriter
getLogWriter()
Gets the log writer for thisManagedConnectionImpl
instance.ManagedConnectionFactoryImpl
getManagedConnectionFactory()
Returns theManagedConnectionFactory
instance that created thisManagedConnection
instance.jakarta.resource.spi.ManagedConnectionFactory
getMcf()
jakarta.resource.spi.ManagedConnectionMetaData
getMetaData()
Gets the metadata information for this connection's underlying EIS resource manager instance.int
getStatementTimeout()
XAResource
getXAResource()
Returns anXAResource
instance.void
incrementCount()
void
initializeConnectionType(int _connectionType)
sets the connection type of this connection.protected void
invalidateAllConnectionHandles()
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.boolean
isAborted()
Boolean
isClientInfoSupported()
boolean
isTransactionInProgress()
Checks if a this ManagedConnection is involved in a transaction or not.void
markForRemoval(boolean flag)
CallableStatement
prepareCachedCallableStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency)
CallableStatement
prepareCachedCallableStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
PreparedStatement
prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int autoGeneratedKeys)
PreparedStatement
prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int[] columnIndexes)
PreparedStatement
prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency)
PreparedStatement
prepareCachedStatement(ConnectionWrapper conWrapper, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
PreparedStatement
prepareCachedStatement(ConnectionWrapper conWrapper, String sql, String[] columnNames)
void
purgeStatementFromCache(PreparedStatement preparedStatement)
void
removeConnectionEventListener(jakarta.resource.spi.ConnectionEventListener listener)
Removes an already registered connection event listener from theManagedConnectionImpl
instance.void
setAborted(boolean flag)
void
setClientInfoSupported(Boolean isClientInfoSupported)
void
setLastAutoCommitValue(boolean lastAutoCommitValue)
To keep track of last auto commit value.void
setLastTransactionIsolationLevel(int isolationLevel)
void
setLogWriter(PrintWriter out)
Sets the log writer for thisManagedConnectionImpl
instance.
-
-
-
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
-PooledConnection
object in case the physical connection is to be obtained from a pooledDataSource
; null otherwisesqlConn
-java.sql.Connection
object 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 theManagedConnectionFactory
object that created thisManagedConnectionImpl
object is not the same as returned byPasswordCredential
object 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:
addConnectionEventListener
in 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 aManagedConnectionImpl
instance.- Specified by:
associateConnection
in interfacejakarta.resource.spi.ManagedConnection
- Parameters:
connection
-ConnectionHolder
to be associated with thisManagedConnectionImpl
instance- 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.ResourceException
Application server calls this method to force any cleanup on theManagedConnectionImpl
instance. This method calls the invalidate method on all ConnectionHandles associated with thisManagedConnectionImpl
.- Specified by:
cleanup
in interfacejakarta.resource.spi.ManagedConnection
- Throws:
jakarta.resource.ResourceException
- if the physical connection is no more valid
-
invalidateAllConnectionHandles
protected void invalidateAllConnectionHandles() throws jakarta.resource.ResourceException
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.- Throws:
jakarta.resource.ResourceException
- if there is a problem in retrieving the connection handles
-
destroy
public void destroy() throws jakarta.resource.ResourceException
Destroys the physical connection to the underlying resource manager.- Specified by:
destroy
in 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 theManagedConnectionImpl
instance.- Specified by:
getConnection
in interfacejakarta.resource.spi.ManagedConnection
- Parameters:
sub
-Subject
parameter needed for authenticationcxReqInfo
-ConnectionRequestInfo
carries 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.ResourceException
Returns anLocalTransactionImpl
instance. TheLocalTransactionImpl
interface is used by the container to manage local transactions for a RM instance.- Specified by:
getLocalTransaction
in interfacejakarta.resource.spi.ManagedConnection
- Returns:
LocalTransactionImpl
instance- Throws:
jakarta.resource.ResourceException
- if the physical connection is not valid
-
getLogWriter
public PrintWriter getLogWriter() throws jakarta.resource.ResourceException
Gets the log writer for thisManagedConnectionImpl
instance.- Specified by:
getLogWriter
in interfacejakarta.resource.spi.ManagedConnection
- Returns:
PrintWriter
instance associated with thisManagedConnectionImpl
instance- Throws:
jakarta.resource.ResourceException
- if the physical connection is not valid- See Also:
setLogWriter
-
getMetaData
public jakarta.resource.spi.ManagedConnectionMetaData getMetaData() throws jakarta.resource.ResourceException
Gets the metadata information for this connection's underlying EIS resource manager instance.- Specified by:
getMetaData
in interfacejakarta.resource.spi.ManagedConnection
- Returns:
ManagedConnectionMetaData
instance- Throws:
jakarta.resource.ResourceException
- if the physical connection is not valid
-
getXAResource
public XAResource getXAResource() throws jakarta.resource.ResourceException
Returns anXAResource
instance.- Specified by:
getXAResource
in interfacejakarta.resource.spi.ManagedConnection
- Returns:
XAResource
instance- Throws:
jakarta.resource.ResourceException
- if the physical connection is not valid or there is an error in allocating theXAResource
instancejakarta.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 theManagedConnectionImpl
instance.- Specified by:
removeConnectionEventListener
in interfacejakarta.resource.spi.ManagedConnection
- Parameters:
listener
-ConnectionEventListener
to 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 thisManagedConnectionImpl
instance.- Specified by:
setLogWriter
in interfacejakarta.resource.spi.ManagedConnection
- Parameters:
out
-PrintWriter
to be associated with thisManagedConnectionImpl
instance- 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 theManagedConnectionFactory
instance that created thisManagedConnection
instance.- Returns:
ManagedConnectionFactory
instance that created thisManagedConnection
instance
-
connectionClosed
public void connectionClosed(Exception e, ConnectionHolder connHolderObject) throws SQLException
This method is called by theConnectionHolder
when its close method is called. ThisManagedConnection
instance 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
-ConnectionHolder
that has been closed- Throws:
SQLException
- in case closing the sql connection got out ofgetConnection
on the underlyingPooledConnection
throws 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
-ConnectionHolder
that requests thisManagedConnection
instance 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:
dissociateConnections
in 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)
-
-