Search in sources :

Example 21 with CJException

use of com.mysql.cj.exceptions.CJException in project aws-mysql-jdbc by awslabs.

the class ResultSetImpl method realClose.

@Override
public void realClose(boolean calledExplicitly) throws SQLException {
    JdbcConnection locallyScopedConn = this.connection;
    if (locallyScopedConn == null) {
        // already closed
        return;
    }
    synchronized (locallyScopedConn.getConnectionMutex()) {
        // additional check in case ResultSet was closed while current thread was waiting for lock
        if (this.isClosed) {
            return;
        }
        try {
            if (this.useUsageAdvisor) {
                if (!calledExplicitly) {
                    this.eventSink.processEvent(ProfilerEvent.TYPE_USAGE, this.session, this.owningStatement, this, 0, new Throwable(), Messages.getString("ResultSet.ResultSet_implicitly_closed_by_driver"));
                }
                int resultSetSizeThreshold = locallyScopedConn.getPropertySet().getIntegerProperty(PropertyKey.resultSetSizeThreshold).getValue();
                if (this.rowData.size() > resultSetSizeThreshold) {
                    this.eventSink.processEvent(ProfilerEvent.TYPE_USAGE, this.session, this.owningStatement, this, 0, new Throwable(), Messages.getString("ResultSet.Too_Large_Result_Set", new Object[] { Integer.valueOf(this.rowData.size()), Integer.valueOf(resultSetSizeThreshold) }));
                }
                if (!isLast() && !isAfterLast() && (this.rowData.size() != 0)) {
                    this.eventSink.processEvent(ProfilerEvent.TYPE_USAGE, this.session, this.owningStatement, this, 0, new Throwable(), Messages.getString("ResultSet.Possible_incomplete_traversal_of_result_set", new Object[] { Integer.valueOf(getRow()), Integer.valueOf(this.rowData.size()) }));
                }
                // Report on any columns that were selected but not referenced
                if (this.columnUsed.length > 0 && !this.rowData.wasEmpty()) {
                    StringBuilder buf = new StringBuilder();
                    for (int i = 0; i < this.columnUsed.length; i++) {
                        if (!this.columnUsed[i]) {
                            if (buf.length() > 0) {
                                buf.append(", ");
                            }
                            buf.append(this.columnDefinition.getFields()[i].getFullName());
                        }
                    }
                    if (buf.length() > 0) {
                        this.eventSink.processEvent(ProfilerEvent.TYPE_USAGE, this.session, this.owningStatement, this, 0, new Throwable(), Messages.getString("ResultSet.The_following_columns_were_never_referenced", new String[] { buf.toString() }));
                    }
                }
            }
        } finally {
            if (this.owningStatement != null && calledExplicitly) {
                this.owningStatement.removeOpenResultSet(this);
            }
            SQLException exceptionDuringClose = null;
            if (this.rowData != null) {
                try {
                    this.rowData.close();
                } catch (CJException sqlEx) {
                    exceptionDuringClose = SQLExceptionsMapping.translateException(sqlEx);
                }
            }
            if (this.statementUsedForFetchingRows != null) {
                try {
                    this.statementUsedForFetchingRows.realClose(true, false);
                } catch (SQLException sqlEx) {
                    if (exceptionDuringClose != null) {
                        exceptionDuringClose.setNextException(sqlEx);
                    } else {
                        exceptionDuringClose = sqlEx;
                    }
                }
            }
            this.rowData = null;
            this.columnDefinition = null;
            this.eventSink = null;
            this.warningChain = null;
            this.owningStatement = null;
            this.db = null;
            this.serverInfo = null;
            this.thisRow = null;
            this.fastDefaultCal = null;
            this.fastClientCal = null;
            this.connection = null;
            this.session = null;
            this.isClosed = true;
            if (exceptionDuringClose != null) {
                throw exceptionDuringClose;
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) CJException(com.mysql.cj.exceptions.CJException)

Aggregations

CJException (com.mysql.cj.exceptions.CJException)21 NativePacketPayload (com.mysql.cj.protocol.a.NativePacketPayload)9 ArrayList (java.util.ArrayList)6 AuthenticationLdapSaslClientPlugin (com.mysql.cj.protocol.a.authentication.AuthenticationLdapSaslClientPlugin)5 Test (org.junit.jupiter.api.Test)5 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)4 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 UnableToConnectException (com.mysql.cj.exceptions.UnableToConnectException)3 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)3 ServerPreparedQuery (com.mysql.cj.ServerPreparedQuery)2 OperationCancelledException (com.mysql.cj.exceptions.OperationCancelledException)2 PasswordExpiredException (com.mysql.cj.exceptions.PasswordExpiredException)2 Resultset (com.mysql.cj.protocol.Resultset)2 LazyString (com.mysql.cj.util.LazyString)2 Properties (java.util.Properties)2 NativeSession (com.mysql.cj.NativeSession)1 PreparedQuery (com.mysql.cj.PreparedQuery)1 UsernameCallback (com.mysql.cj.callback.UsernameCallback)1 HostInfo (com.mysql.cj.conf.HostInfo)1