Class ClientConnection

    • Field Detail

      • agent_

        public Agent agent_
      • openStatements_

        final java.util.WeakHashMap<ClientStatement,​java.lang.Void> openStatements_
      • CommitAndRollbackListeners_

        final java.util.WeakHashMap<UnitOfWorkListener,​java.lang.Void> CommitAndRollbackListeners_
      • user_

        protected final java.lang.String user_
      • retrieveMessageText_

        boolean retrieveMessageText_
      • jdbcReadOnly_

        private boolean jdbcReadOnly_
      • holdability

        private int holdability
        Holdabilty for created statements. Only access through the holdability method to ensure the correct value is returned for an XA connection.
      • databaseName_

        public java.lang.String databaseName_
      • productID_

        public java.lang.String productID_
      • isolationLevelPreparedStmts

        private final java.util.HashMap<java.lang.String,​ClientPreparedStatement> isolationLevelPreparedStmts
      • open_

        protected boolean open_
      • aborting_

        private boolean aborting_
      • availableForReuse_

        private boolean availableForReuse_
      • TRANSACTION_UNKNOWN

        private static final int TRANSACTION_UNKNOWN
        Constant indicating that isolation_ has not been updated through piggy-backing, (or that the previously stored value was invalidated, e.g. by an XA state change).
        See Also:
        Constant Field Values
      • isolation_

        private int isolation_
        Cached copy of the isolation level. Kept in sync with server through piggy-backing.
      • defaultIsolation

        private int defaultIsolation
        The default isolation level, enforced on connection resets.

        Note that this value may be changed upon connection initialization in the future, as the server can piggy-back the isolation level.

      • currentSchemaName_

        private java.lang.String currentSchemaName_
        Cached copy of the schema name. Updated through piggy-backing and used to implement statement caching.
      • autoCommit_

        public boolean autoCommit_
      • inUnitOfWork_

        protected boolean inUnitOfWork_
      • accumulated440ForMessageProcFailure_

        private boolean accumulated440ForMessageProcFailure_
      • accumulated444ForMessageProcFailure_

        private boolean accumulated444ForMessageProcFailure_
      • transactionID_

        private int transactionID_
      • isXAConnection_

        protected boolean isXAConnection_
      • XA_T0_NOT_ASSOCIATED

        public static final int XA_T0_NOT_ASSOCIATED
        XA_T0_NOT_ASSOCIATED This connection is not currently associated with an XA transaction In this state commits will flow in autocommit mode.
        See Also:
        Constant Field Values
      • XA_T1_ASSOCIATED

        public static final int XA_T1_ASSOCIATED
        XA_T1_ASSOCIATED In this state commits will not flow in autocommit mode.
        See Also:
        Constant Field Values
      • xaState_

        private int xaState_
      • xaHostVersion_

        public int xaHostVersion_
      • loginTimeout_

        private int loginTimeout_
      • serverNameIP_

        public java.lang.String serverNameIP_
      • portNumber_

        public int portNumber_
      • clientSSLMode_

        private int clientSSLMode_
      • clientCursorNameCache_

        java.util.Hashtable<java.lang.String,​java.lang.String> clientCursorNameCache_
      • commBufferSize_

        public int commBufferSize_
      • resetConnectionAtFirstSql_

        public boolean resetConnectionAtFirstSql_
      • DERBY_TRANSACTION_REPEATABLE_READ

        private static java.lang.String DERBY_TRANSACTION_REPEATABLE_READ
      • DERBY_TRANSACTION_SERIALIZABLE

        private static java.lang.String DERBY_TRANSACTION_SERIALIZABLE
      • DERBY_TRANSACTION_READ_COMMITTED

        private static java.lang.String DERBY_TRANSACTION_READ_COMMITTED
      • DERBY_TRANSACTION_READ_UNCOMMITTED

        private static java.lang.String DERBY_TRANSACTION_READ_UNCOMMITTED
      • dncGeneratedSavepointId_

        private int dncGeneratedSavepointId_
      • dncGeneratedSavepointNamePrefix__

        private static final java.lang.String dncGeneratedSavepointNamePrefix__
        See Also:
        Constant Field Values
      • lobProcs

        private CallableLocatorProcedures lobProcs
        Reference to object with prepared statements for calling the locator procedures. Makes it possible to reuse prepared statements within the connection.
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • createStatement

        public java.sql.Statement createStatement()
                                           throws java.sql.SQLException
        Specified by:
        createStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql)
                                                    throws java.sql.SQLException
        Specified by:
        prepareStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareCall

        public java.sql.CallableStatement prepareCall​(java.lang.String sql)
                                               throws java.sql.SQLException
        Specified by:
        prepareCall in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • nativeSQL

        public java.lang.String nativeSQL​(java.lang.String sql)
                                   throws java.sql.SQLException
        Specified by:
        nativeSQL in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • allowLocalCommitRollback_

        protected abstract boolean allowLocalCommitRollback_()
                                                      throws SqlException
        Throws:
        SqlException
      • setAutoCommit

        public void setAutoCommit​(boolean autoCommit)
                           throws java.sql.SQLException
        Specified by:
        setAutoCommit in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getAutoCommit

        public boolean getAutoCommit()
                              throws java.sql.SQLException
        Specified by:
        getAutoCommit in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • commit

        public void commit()
                    throws java.sql.SQLException
        Specified by:
        commit in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • checkForInvalidXAStateOnCommitOrRollback

        private void checkForInvalidXAStateOnCommitOrRollback()
                                                       throws SqlException
        Throws:
        SqlException
      • rollback

        public void rollback()
                      throws java.sql.SQLException
        Specified by:
        rollback in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • close

        public void close()
                   throws java.sql.SQLException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • checkForTransactionInProgress

        void checkForTransactionInProgress()
                                    throws SqlException
        Check if the transaction is in progress and the connection cannot be closed.
        Throws:
        SqlException - if the connection cannot be closed because the transaction is active
      • transactionInProgress

        public boolean transactionInProgress()
        Check if there are uncommitted operations in the current transaction that prevent us from closing the connection.
        Returns:
        true if the connection cannot be closed due to uncommitted operations in the transaction
      • closeX

        private void closeX()
                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • closeResources

        public void closeResources()
                            throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • closeResourcesX

        private void closeResourcesX()
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • isGlobalPending_

        protected abstract boolean isGlobalPending_()
      • markClosed_

        protected abstract void markClosed_()
      • markClosed

        private void markClosed​(boolean statementPooling)
      • markClosedForReuse

        private void markClosedForReuse​(boolean statementPooling)
      • markStatementsClosed

        private void markStatementsClosed()
      • isPhysicalConnClosed

        public boolean isPhysicalConnClosed()
        Return true if the physical connection is still open. Might be logically closed but available for reuse.
        Returns:
        true if physical connection still open
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface java.sql.Connection
      • isClosedX

        public boolean isClosedX()
      • setTransactionIsolation

        public void setTransactionIsolation​(int level)
                                     throws java.sql.SQLException
        Specified by:
        setTransactionIsolation in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setTransactionIsolationX

        private void setTransactionIsolationX​(int level)
                                       throws SqlException
        Set the transaction isolation level as specified.

        If this method is called during a transaction, the result is implementation-defined.

        Information about Derby specific isolation level handling:

        • REPEATABLE_READ = JDBC: TRANSACTION_SERIALIZABLE, DERBY: RR, PROTOCOL: repeatable read
        • READ_STABILITY = JDBC: TRANSACTION_REPEATABLE_READ, DERBY: RS, PROTOCOL: All
        • CURSOR_STABILITY = JDBC: TRANSACTION_READ_COMMITTED, DERBY: CS, PROTOCOL: Cursor stability
        • UNCOMMITTED_READ = JDBC: TRANSACTION_READ_UNCOMMITTED, DERBY: UR, PROTOCOL: Change
        • NO_COMMIT = JDBC: TRANSACTION_NONE, DERBY: NC, PROTOCOL: No commit
        Throws:
        SqlException
      • supportsSessionDataCaching

        protected abstract boolean supportsSessionDataCaching()
        Finds out if the underlaying database connection supports session data caching.
        Returns:
        true if sessionData is supported
      • serverSupportsLocators

        protected abstract boolean serverSupportsLocators()
        Checks whether the server supports locators for large objects. Note that even though the server supports LOB locators, the database that is accessed through the server may not have the necessary stored procedures to support LOB locators (e.g., because the database is soft upgraded from an earlier version).
        Returns:
        true if LOB locators are supported.
      • serverSupportsTimestampNanoseconds

        protected abstract boolean serverSupportsTimestampNanoseconds()
        Return true if the server supports nanoseconds in timestamps
      • getTransactionIsolation

        public int getTransactionIsolation()
                                    throws java.sql.SQLException
        Specified by:
        getTransactionIsolation in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getTransactionIsolationX

        public int getTransactionIsolationX()
                                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getTransactionID

        public int getTransactionID()
        Returns the ID of the active transaction for this connection.
        Returns:
        the ID of the active transaction
      • getCurrentSchemaName

        public java.lang.String getCurrentSchemaName()
                                              throws java.sql.SQLException
        Returns the current schema (the schema that would be used for compilation. This is not part of the java.sql.Connection interface, and is only intended for use with statement caching.
        Returns:
        the name of the current schema
        Throws:
        java.sql.SQLException
      • translateIsolation

        private int translateIsolation​(java.lang.String isolationStr)
        Translates the isolation level from a SQL string to the JDBC int value
        Parameters:
        isolationStr - SQL isolation string
        Returns:
        isolation level as a JDBC integer value
      • getWarnings

        public java.sql.SQLWarning getWarnings()
                                        throws java.sql.SQLException
        Specified by:
        getWarnings in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • clearWarnings

        public void clearWarnings()
                           throws java.sql.SQLException
        Specified by:
        clearWarnings in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getMetaData

        public java.sql.DatabaseMetaData getMetaData()
                                              throws java.sql.SQLException
        Specified by:
        getMetaData in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
                         throws java.sql.SQLException
        Specified by:
        setReadOnly in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • isReadOnly

        public boolean isReadOnly()
                           throws java.sql.SQLException
        Specified by:
        isReadOnly in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setCatalog

        public void setCatalog​(java.lang.String catalog)
                        throws java.sql.SQLException
        Specified by:
        setCatalog in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getCatalog

        public java.lang.String getCatalog()
                                    throws java.sql.SQLException
        Specified by:
        getCatalog in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • createStatement

        public java.sql.Statement createStatement​(int resultSetType,
                                                  int resultSetConcurrency)
                                           throws java.sql.SQLException
        Specified by:
        createStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                           int resultSetType,
                                                           int resultSetConcurrency)
                                                    throws java.sql.SQLException
        Specified by:
        prepareStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareCall

        public java.sql.CallableStatement prepareCall​(java.lang.String sql,
                                                      int resultSetType,
                                                      int resultSetConcurrency)
                                               throws java.sql.SQLException
        Specified by:
        prepareCall in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • downgradeResultSetType

        private int downgradeResultSetType​(int resultSetType)
      • getTypeMap

        public java.util.Map<java.lang.String,​java.lang.Class<?>> getTypeMap()
                                                                            throws java.sql.SQLException
        Specified by:
        getTypeMap in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setTypeMap

        public void setTypeMap​(java.util.Map map)
                        throws java.sql.SQLException
        Specified by:
        setTypeMap in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setHoldability

        public void setHoldability​(int holdability)
                            throws java.sql.SQLException
        Specified by:
        setHoldability in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getHoldability

        public int getHoldability()
                           throws java.sql.SQLException
        Specified by:
        getHoldability in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setSavepoint

        public java.sql.Savepoint setSavepoint()
                                        throws java.sql.SQLException
        Specified by:
        setSavepoint in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setSavepoint

        public java.sql.Savepoint setSavepoint​(java.lang.String name)
                                        throws java.sql.SQLException
        Specified by:
        setSavepoint in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • rollback

        public void rollback​(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
        Specified by:
        rollback in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • releaseSavepoint

        public void releaseSavepoint​(java.sql.Savepoint savepoint)
                              throws java.sql.SQLException
        Specified by:
        releaseSavepoint in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • createStatement

        public java.sql.Statement createStatement​(int resultSetType,
                                                  int resultSetConcurrency,
                                                  int resultSetHoldability)
                                           throws java.sql.SQLException
        Specified by:
        createStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                           int resultSetType,
                                                           int resultSetConcurrency,
                                                           int resultSetHoldability)
                                                    throws java.sql.SQLException
        Specified by:
        prepareStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareStatementX

        ClientPreparedStatement prepareStatementX​(java.lang.String sql,
                                                  int resultSetType,
                                                  int resultSetConcurrency,
                                                  int resultSetHoldability,
                                                  int autoGeneratedKeys,
                                                  java.lang.String[] columnNames,
                                                  int[] columnIndexes)
                                           throws SqlException
        Throws:
        SqlException
      • prepareCall

        public java.sql.CallableStatement prepareCall​(java.lang.String sql,
                                                      int resultSetType,
                                                      int resultSetConcurrency,
                                                      int resultSetHoldability)
                                               throws java.sql.SQLException
        Specified by:
        prepareCall in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                           int autoGeneratedKeys)
                                                    throws java.sql.SQLException
        Specified by:
        prepareStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                           int[] columnIndexes)
                                                    throws java.sql.SQLException
        Specified by:
        prepareStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                           java.lang.String[] columnNames)
                                                    throws java.sql.SQLException
        Specified by:
        prepareStatement in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • allowCloseInUOW_

        protected abstract boolean allowCloseInUOW_()
      • doCloseStatementsOnClose_

        protected abstract boolean doCloseStatementsOnClose_()
      • newAgent_

        protected abstract Agent newAgent_​(LogWriter logWriter,
                                           int loginTimeout,
                                           java.lang.String serverName,
                                           int portNumber,
                                           int clientSSLMode)
                                    throws SqlException
        Throws:
        SqlException
      • newPreparedStatement_

        protected abstract ClientPreparedStatement newPreparedStatement_​(java.lang.String sql,
                                                                         int type,
                                                                         int concurrency,
                                                                         int holdability,
                                                                         int autoGeneratedKeys,
                                                                         java.lang.String[] columnNames,
                                                                         int[] columnIndexes)
                                                                  throws SqlException
        Throws:
        SqlException
      • resetPreparedStatement_

        protected abstract void resetPreparedStatement_​(ClientPreparedStatement ps,
                                                        java.lang.String sql,
                                                        int resultSetType,
                                                        int resultSetConcurrency,
                                                        int resultSetHoldability,
                                                        int autoGeneratedKeys,
                                                        java.lang.String[] columnNames,
                                                        int[] columnIndexes)
                                                 throws SqlException
        Throws:
        SqlException
      • resetCallableStatement_

        protected abstract void resetCallableStatement_​(ClientCallableStatement cs,
                                                        java.lang.String sql,
                                                        int resultSetType,
                                                        int resultSetConcurrency,
                                                        int resultSetHoldability)
                                                 throws SqlException
        Throws:
        SqlException
      • completeSpecificRollback

        private void completeSpecificRollback​(UnitOfWorkListener uwl)
        Rollback the specific UnitOfWorkListener.
        Parameters:
        uwl - The UnitOfWorkLitener to be rolled back
      • completeTransactionStart

        void completeTransactionStart()
      • completePiggyBackIsolation

        public void completePiggyBackIsolation​(int pbIsolation)
        Description copied from interface: ConnectionCallbackInterface
        Completes piggy-backing of the new current isolation level by updating the cached copy in am.Connection.
        Specified by:
        completePiggyBackIsolation in interface ConnectionCallbackInterface
        Parameters:
        pbIsolation - new isolation level from the server
      • completeInitialPiggyBackIsolation

        public void completeInitialPiggyBackIsolation​(int pbIsolation)
        Sets the default isolation level of the connection upon connection initialization.

        Note that depending on the server version, the default isolation value may not be piggy-backed on the initialization flow. In that case, the default is assumed / hardcoded to be READ_COMMITTED.

        Parameters:
        pbIsolation - isolation level as specified by java.sql.Connection
      • completePiggyBackSchema

        public void completePiggyBackSchema​(java.lang.String pbSchema)
        Description copied from interface: ConnectionCallbackInterface
        Completes piggy-backing of the new current schema by updating the cached copy in am.Connection.
        Specified by:
        completePiggyBackSchema in interface ConnectionCallbackInterface
        Parameters:
        pbSchema - new current schema from the server
      • completeInitialPiggyBackSchema

        public void completeInitialPiggyBackSchema​(java.lang.String pbSchema)
        Sets the current schema upon connection initialization.
        Parameters:
        pbSchema - the schema name
      • completeReset

        protected void completeReset​(boolean isDeferredReset,
                                     boolean closeStatementsOnClose,
                                     NetXAResource xares)
                              throws SqlException

        NOTE:
        The following comments are valid for the changes done as part of implementing statement caching only (see DERBY-3313 and linked issues).

        We don't reset the isolation level to unknown unconditionally, as this forces us to go to the server all the time. Since the value should now be valid (DERBY-3192), we check if it has been changed from the default.

        Parameters:
        closeStatementsOnClose - is used to differentiate between cases where statement pooling is enabled or not. If true, it means statement pooling is disabled and the statements are fully reset, which includes a re-prepare. If false, statement pooling is enabled, and a more lightweight reset procedure is used.
        Throws:
        SqlException
      • locatorProcedureCall

        CallableLocatorProcedures locatorProcedureCall()
        Get handle to the object that contains prepared statements for calling locator procedures for this connection. The object will be created on the first invocation. An example of how to call a stored procedure via this method:
         
            connection.locatorProcedureCall().blobReleaseLocator(locator);
          
        Returns:
        object with prepared statements for calling locator procedures
      • isXAConnection

        public boolean isXAConnection()
      • getXAState

        public int getXAState()
      • setXAState

        public void setXAState​(int state)
      • accumulateWarning

        private void accumulateWarning​(SqlWarning e)
      • accumulate440WarningForMessageProcFailure

        void accumulate440WarningForMessageProcFailure​(SqlWarning e)
      • accumulate444WarningForMessageProcFailure

        void accumulate444WarningForMessageProcFailure​(SqlWarning e)
      • getServerVersion

        public int getServerVersion()
      • holdability

        final int holdability()
        Return the holdabilty for the Connection. Matches the embedded driver in the restriction that while in a global (XA) transaction the holdability is CLOSE_CURSORS_AT_COMMIT. Otherwise return the holdability set by the user.
      • createClob

        public java.sql.Clob createClob()
                                 throws java.sql.SQLException
        Constructs an object that implements the Clob interface. The object returned initially contains no data.
        Specified by:
        createClob in interface java.sql.Connection
        Returns:
        An object that implements the Clob interface
        Throws:
        java.sql.SQLException - if an object that implements the Clob interface can not be constructed.
      • createBlob

        public java.sql.Blob createBlob()
                                 throws java.sql.SQLException
        Constructs an object that implements the Blob interface. The object returned initially contains no data.
        Specified by:
        createBlob in interface java.sql.Connection
        Returns:
        An object that implements the Blob interface
        Throws:
        java.sql.SQLException - if an object that implements the Blob interface can not be constructed.
      • isAborting

        public boolean isAborting()
        Return true if the connection is aborting
      • beginAborting

        protected void beginAborting()
        Begin aborting the connection
      • getSchema

        public java.lang.String getSchema()
                                   throws java.sql.SQLException
        Get the name of the current schema.
        Specified by:
        getSchema in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setSchema

        public void setSchema​(java.lang.String schemaName)
                       throws java.sql.SQLException
        Set the default schema for the Connection.
        Specified by:
        setSchema in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • abort

        public void abort​(java.util.concurrent.Executor executor)
                   throws java.sql.SQLException
        Specified by:
        abort in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • getNetworkTimeout

        public int getNetworkTimeout()
                              throws java.sql.SQLException
        Specified by:
        getNetworkTimeout in interface java.sql.Connection
        Throws:
        java.sql.SQLException
      • setNetworkTimeout

        public void setNetworkTimeout​(java.util.concurrent.Executor executor,
                                      int milliseconds)
                               throws java.sql.SQLException
        Specified by:
        setNetworkTimeout in interface java.sql.Connection
        Throws:
        java.sql.SQLException