Class PooledConnectionImpl

    • Field Detail

      • connection

        private java.sql.Connection connection
        The JDBC database connection that represents the physical db connection.
      • delegatingConnection

        private final DelegatingConnection<?> delegatingConnection
        A DelegatingConnection used to create a PoolablePreparedStatementStub.
      • logicalConnection

        private java.sql.Connection logicalConnection
        The JDBC database logical connection.
      • eventListeners

        private final java.util.Vector<javax.sql.ConnectionEventListener> eventListeners
        ConnectionEventListeners.
      • statementEventListeners

        private final java.util.Vector<javax.sql.StatementEventListener> statementEventListeners
        StatementEventListeners.
      • closed

        private boolean closed
        Flag set to true, once close() is called.
      • accessToUnderlyingConnectionAllowed

        private boolean accessToUnderlyingConnectionAllowed
        Controls access to the underlying connection.
    • Constructor Detail

      • PooledConnectionImpl

        PooledConnectionImpl​(java.sql.Connection connection)
        Wraps the real connection.
        Parameters:
        connection - the connection to be wrapped.
    • Method Detail

      • addConnectionEventListener

        public void addConnectionEventListener​(javax.sql.ConnectionEventListener listener)
        Specified by:
        addConnectionEventListener in interface javax.sql.PooledConnection
      • addStatementEventListener

        public void addStatementEventListener​(javax.sql.StatementEventListener listener)
        Specified by:
        addStatementEventListener in interface javax.sql.PooledConnection
      • assertOpen

        private void assertOpen()
                         throws java.sql.SQLException
        Throws an SQLException, if isClosed is true
        Throws:
        java.sql.SQLException
      • close

        public void close()
                   throws java.sql.SQLException
        Closes the physical connection and marks this PooledConnection so that it may not be used to generate any more logical Connections.
        Specified by:
        close in interface javax.sql.PooledConnection
        Throws:
        java.sql.SQLException - Thrown when an error occurs or the connection is already closed.
      • createKey

        protected PStmtKey createKey​(java.lang.String sql)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        Returns:
        a PStmtKey for the given arguments.
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     int autoGeneratedKeys)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        autoGeneratedKeys - A flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS.
        Returns:
        a key to uniquely identify a prepared statement.
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     int[] columnIndexes)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        columnIndexes - An array of column indexes indicating the columns that should be returned from the inserted row or rows.
        Returns:
        a key to uniquely identify a prepared statement.
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     int resultSetType,
                                     int resultSetConcurrency)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        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 key to uniquely identify a prepared statement.
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     int resultSetType,
                                     int resultSetConcurrency,
                                     int resultSetHoldability)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        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
        resultSetHoldability - One of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT.
        Returns:
        a key to uniquely identify a prepared statement.
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     int resultSetType,
                                     int resultSetConcurrency,
                                     int resultSetHoldability,
                                     PoolingConnection.StatementType statementType)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        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.
        resultSetHoldability - One of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT.
        statementType - The SQL statement type, prepared or callable.
        Returns:
        a key to uniquely identify a prepared statement.
        Since:
        2.4.0
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     int resultSetType,
                                     int resultSetConcurrency,
                                     PoolingConnection.StatementType statementType)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        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.
        statementType - The SQL statement type, prepared or callable.
        Returns:
        a key to uniquely identify a prepared statement.
        Since:
        2.4.0
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     PoolingConnection.StatementType statementType)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        statementType - The SQL statement type, prepared or callable.
        Returns:
        a key to uniquely identify a prepared statement.
      • createKey

        protected PStmtKey createKey​(java.lang.String sql,
                                     java.lang.String[] columnNames)
        Creates a PStmtKey for the given arguments.
        Parameters:
        sql - The SQL statement.
        columnNames - An array of column names indicating the columns that should be returned from the inserted row or rows.
        Returns:
        a key to uniquely identify a prepared statement.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Closes the physical connection and checks that the logical connection was closed as well.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getCatalogOrNull

        private java.lang.String getCatalogOrNull()
      • getSchemaOrNull

        private java.lang.String getSchemaOrNull()
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Returns a JDBC connection.
        Specified by:
        getConnection in interface javax.sql.PooledConnection
        Returns:
        The database connection.
        Throws:
        java.sql.SQLException - if the connection is not open or the previous logical connection is still open
      • isAccessToUnderlyingConnectionAllowed

        public boolean isAccessToUnderlyingConnectionAllowed()
        Returns the value of the accessToUnderlyingConnectionAllowed property.
        Returns:
        true if access to the underlying is allowed, false otherwise.
      • normalizeSQL

        protected java.lang.String normalizeSQL​(java.lang.String sql)
        Normalizes the given SQL statement, producing a canonical form that is semantically equivalent to the original.
        Parameters:
        sql - The SQL statement.
        Returns:
        the normalized SQL statement.
      • notifyListeners

        void notifyListeners()
        Sends a connectionClosed event.
      • prepareCall

        java.sql.CallableStatement prepareCall​(java.lang.String sql)
                                        throws java.sql.SQLException
        Creates or obtains a CallableStatement from my pool.
        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

        java.sql.CallableStatement prepareCall​(java.lang.String sql,
                                               int resultSetType,
                                               int resultSetConcurrency)
                                        throws java.sql.SQLException
        Creates or obtains a CallableStatement from my pool.
        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

        java.sql.CallableStatement prepareCall​(java.lang.String sql,
                                               int resultSetType,
                                               int resultSetConcurrency,
                                               int resultSetHoldability)
                                        throws java.sql.SQLException
        Creates or obtains a CallableStatement from my pool.
        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

        java.sql.PreparedStatement prepareStatement​(java.lang.String sql)
                                             throws java.sql.SQLException
        Creates or obtains a PreparedStatement from my pool.
        Parameters:
        sql - the SQL statement.
        Returns:
        a PoolablePreparedStatement
        Throws:
        java.sql.SQLException
      • prepareStatement

        java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                    int autoGeneratedKeys)
                                             throws java.sql.SQLException
        Creates or obtains a PreparedStatement from my pool.
        Parameters:
        sql - an SQL statement that may contain one or more '?' IN parameter placeholders.
        autoGeneratedKeys - a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS.
        Returns:
        a PoolablePreparedStatement
        Throws:
        java.sql.SQLException
        See Also:
        Connection.prepareStatement(String, int)
      • prepareStatement

        java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                    int[] columnIndexes)
                                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • prepareStatement

        java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                    int resultSetType,
                                                    int resultSetConcurrency)
                                             throws java.sql.SQLException
        Creates or obtains a PreparedStatement from my pool.
        Parameters:
        sql - a String object that is the SQL statement to be sent to the database; may contain one or more '?' IN 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 PoolablePreparedStatement.
        Throws:
        java.sql.SQLException
        See Also:
        Connection.prepareStatement(String, int, int)
      • prepareStatement

        java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                    int resultSetType,
                                                    int resultSetConcurrency,
                                                    int resultSetHoldability)
                                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • prepareStatement

        java.sql.PreparedStatement prepareStatement​(java.lang.String sql,
                                                    java.lang.String[] columnNames)
                                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • removeConnectionEventListener

        public void removeConnectionEventListener​(javax.sql.ConnectionEventListener listener)
        Specified by:
        removeConnectionEventListener in interface javax.sql.PooledConnection
      • removeStatementEventListener

        public void removeStatementEventListener​(javax.sql.StatementEventListener listener)
        Specified by:
        removeStatementEventListener in interface javax.sql.PooledConnection
      • setAccessToUnderlyingConnectionAllowed

        public void setAccessToUnderlyingConnectionAllowed​(boolean allow)
        Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to the underlying connection. (Default: false.)
        Parameters:
        allow - Access to the underlying connection is granted when true.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Since:
        2.6.0