Class ConnectionImpl

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.sql.Connection, java.sql.Wrapper, TrackedUse

    class ConnectionImpl
    extends DelegatingConnection<java.sql.Connection>
    This class is the Connection that will be returned from PooledConnectionImpl.getConnection(). Most methods are wrappers around the JDBC 1.x Connection. A few exceptions include preparedStatement and close. In accordance with the JDBC specification this Connection cannot be used after closed() is called. Any further usage will result in an SQLException.

    ConnectionImpl extends DelegatingConnection to enable access to the underlying connection.

    Since:
    2.0
    • Field Detail

      • accessToUnderlyingConnectionAllowed

        private final boolean accessToUnderlyingConnectionAllowed
      • pooledConnection

        private final PooledConnectionImpl pooledConnection
        The object that instantiated this object
    • Constructor Detail

      • ConnectionImpl

        ConnectionImpl​(PooledConnectionImpl pooledConnection,
                       java.sql.Connection connection,
                       boolean accessToUnderlyingConnectionAllowed)
        Creates a ConnectionImpl.
        Parameters:
        pooledConnection - The PooledConnection that is calling the ctor.
        connection - The JDBC 1.x Connection to wrap.
        accessToUnderlyingConnectionAllowed - if true, then access is allowed to the underlying connection
    • Method Detail

      • close

        public void close()
                   throws java.sql.SQLException
        Marks the Connection as closed, and notifies the pool that the pooled connection is available.

        In accordance with the JDBC specification this Connection cannot be used after closed() is called. Any further usage will result in an SQLException.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.sql.Connection
        Overrides:
        close in class DelegatingConnection<java.sql.Connection>
        Throws:
        java.sql.SQLException - The database connection couldn't be closed.
      • prepareCall

        public java.sql.CallableStatement prepareCall​(java.lang.String sql)
                                               throws java.sql.SQLException
        If pooling of CallableStatements is turned on in the DriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.x Connection.
        Specified by:
        prepareCall in interface java.sql.Connection
        Overrides:
        prepareCall in class DelegatingConnection<java.sql.Connection>
        Parameters:
        sql - an SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is specified using JDBC call escape syntax.
        Returns:
        a default CallableStatement object containing the pre-compiled SQL statement.
        Throws:
        java.sql.SQLException - Thrown if a database access error occurs or this method is called on a closed connection.
        Since:
        2.4.0
      • prepareCall

        public java.sql.CallableStatement prepareCall​(java.lang.String sql,
                                                      int resultSetType,
                                                      int resultSetConcurrency)
                                               throws java.sql.SQLException
        If pooling of CallableStatements is turned on in the DriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.x Connection.
        Specified by:
        prepareCall in interface java.sql.Connection
        Overrides:
        prepareCall in class DelegatingConnection<java.sql.Connection>
        Parameters:
        sql - a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters.
        resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE.
        resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE.
        Returns:
        a CallableStatement object containing the pre-compiled SQL statement that will produce ResultSet objects with the given type and concurrency.
        Throws:
        java.sql.SQLException - Thrown if a database access error occurs, this method is called on a closed connection or the given parameters are not ResultSet constants indicating type and concurrency.
        Since:
        2.4.0
      • prepareCall

        public java.sql.CallableStatement prepareCall​(java.lang.String sql,
                                                      int resultSetType,
                                                      int resultSetConcurrency,
                                                      int resultSetHoldability)
                                               throws java.sql.SQLException
        If pooling of CallableStatements is turned on in the DriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.x Connection.
        Specified by:
        prepareCall in interface java.sql.Connection
        Overrides:
        prepareCall in class DelegatingConnection<java.sql.Connection>
        Parameters:
        sql - a String object that is the SQL statement to be sent to the database; may contain on or more '?' parameters.
        resultSetType - one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE.
        resultSetConcurrency - one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE.
        resultSetHoldability - one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT.
        Returns:
        a new CallableStatement object, containing the pre-compiled SQL statement, that will generate ResultSet objects with the given type, concurrency, and holdability.
        Throws:
        java.sql.SQLException - Thrown if a database access error occurs, this method is called on a closed connection or the given parameters are not ResultSet constants indicating type, concurrency, and holdability.
        Since:
        2.4.0
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql)
                                                    throws java.sql.SQLException
        If pooling of PreparedStatements is turned on in the DriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.x Connection.
        Specified by:
        prepareStatement in interface java.sql.Connection
        Overrides:
        prepareStatement in class DelegatingConnection<java.sql.Connection>
        Parameters:
        sql - SQL statement to be prepared
        Returns:
        the prepared statement
        Throws:
        java.sql.SQLException - if this connection is closed or an error occurs in the wrapped connection.
      • prepareStatement

        public java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                           int resultSetType,
                                                           int resultSetConcurrency)
                                                    throws java.sql.SQLException
        If pooling of PreparedStatements is turned on in the DriverAdapterCPDS, a pooled object may be returned, otherwise delegate to the wrapped JDBC 1.x Connection.
        Specified by:
        prepareStatement in interface java.sql.Connection
        Overrides:
        prepareStatement in class DelegatingConnection<java.sql.Connection>
        Throws:
        java.sql.SQLException - if this connection is closed or an error occurs in the wrapped connection.
      • 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
        Overrides:
        prepareStatement in class DelegatingConnection<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
        Overrides:
        prepareStatement in class DelegatingConnection<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
        Overrides:
        prepareStatement in class DelegatingConnection<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
        Overrides:
        prepareStatement in class DelegatingConnection<java.sql.Connection>
        Throws:
        java.sql.SQLException
      • isAccessToUnderlyingConnectionAllowed

        public boolean isAccessToUnderlyingConnectionAllowed()
        If false, getDelegate() and getInnermostDelegate() will return null.
        Returns:
        true if access is allowed to the underlying connection
        See Also:
        ConnectionImpl