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

      • isDestroyed

        protected boolean isDestroyed
      • isUsable

        protected boolean isUsable
      • initSqlExecuted

        protected boolean initSqlExecuted
      • connectionCount

        protected int connectionCount
      • connectionType

        protected int connectionType
      • actualConnection

        protected Connection actualConnection
      • connectionHandles

        protected Hashtable connectionHandles
      • passwdCredential

        protected jakarta.resource.spi.security.PasswordCredential passwdCredential
      • 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
      • _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 for ManagedConnectionImpl. 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 pooled DataSource; null otherwise
        sqlConn - java.sql.Connection object in case the physical connection is to be obtained from a non pooled DataSource; null otherwise
        passwdCred - object conatining the user and password for allocating the connection
        Throws:
        jakarta.resource.ResourceException - if the ManagedConnectionFactory object that created this ManagedConnectionImpl object is not the same as returned by PasswordCredential object passed
    • Method Detail

      • addConnectionEventListener

        public void addConnectionEventListener​(jakarta.resource.spi.ConnectionEventListener listener)
        Adds a connection event listener to the ManagedConnectionImpl instance.
        Specified by:
        addConnectionEventListener in interface jakarta.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 a ManagedConnectionImpl instance.
        Specified by:
        associateConnection in interface jakarta.resource.spi.ManagedConnection
        Parameters:
        connection - ConnectionHolder to be associated with this ManagedConnectionImpl 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 the ManagedConnectionImpl instance. This method calls the invalidate method on all ConnectionHandles associated with this ManagedConnectionImpl.
        Specified by:
        cleanup in interface jakarta.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 interface jakarta.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 the ManagedConnectionImpl instance.
        Specified by:
        getConnection in interface jakarta.resource.spi.ManagedConnection
        Parameters:
        sub - Subject parameter needed for authentication
        cxReqInfo - 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 connection
        jakarta.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 an LocalTransactionImpl instance. The LocalTransactionImpl interface is used by the container to manage local transactions for a RM instance.
        Specified by:
        getLocalTransaction in interface jakarta.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 this ManagedConnectionImpl instance.
        Specified by:
        getLogWriter in interface jakarta.resource.spi.ManagedConnection
        Returns:
        PrintWriter instance associated with this ManagedConnectionImpl 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 interface jakarta.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 an XAResource instance.
        Specified by:
        getXAResource in interface jakarta.resource.spi.ManagedConnection
        Returns:
        XAResource instance
        Throws:
        jakarta.resource.ResourceException - if the physical connection is not valid or there is an error in allocating the XAResource instance
        jakarta.resource.NotSupportedException - if underlying datasource is not an XADataSource
      • removeConnectionEventListener

        public void removeConnectionEventListener​(jakarta.resource.spi.ConnectionEventListener listener)
        Removes an already registered connection event listener from the ManagedConnectionImpl instance.
        Specified by:
        removeConnectionEventListener in interface jakarta.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 this ManagedConnectionImpl instance.
        Specified by:
        setLogWriter in interface jakarta.resource.spi.ManagedConnection
        Parameters:
        out - PrintWriter to be associated with this ManagedConnectionImpl 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 this ManagedConnectionImpl.
        Parameters:
        pooledConn - PooledConnection
        Returns:
        connection type
      • getManagedConnectionFactory

        public ManagedConnectionFactoryImpl getManagedConnectionFactory()
        Returns the ManagedConnectionFactory instance that created this ManagedConnection instance.
        Returns:
        ManagedConnectionFactory instance that created this ManagedConnection instance
      • connectionClosed

        public void connectionClosed​(Exception e,
                                     ConnectionHolder connHolderObject)
                              throws SQLException
        This method is called by the ConnectionHolder when its close method is called. This ManagedConnection 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 handle
        connHolderObject - ConnectionHolder that has been closed
        Throws:
        SQLException - in case closing the sql connection got out of getConnection on the underlying PooledConnection 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 this ManagedConnection 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 interface jakarta.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 cached DatabaseMetaData.
        Returns:
        DatabaseMetaData
        Throws:
        jakarta.resource.ResourceException
      • isClientInfoSupported

        public Boolean isClientInfoSupported()
      • setClientInfoSupported

        public void setClientInfoSupported​(Boolean isClientInfoSupported)
      • setAborted

        public void setAborted​(boolean flag)
      • isAborted

        public boolean isAborted()
      • purgeStatementFromCache

        public void purgeStatementFromCache​(PreparedStatement preparedStatement)