com.mysql.cj.exceptions.StatementIsClosedException Java Examples

The following examples show how to use com.mysql.cj.exceptions.StatementIsClosedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatementImpl.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int getOpenResultSetCount() {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            if (this.openResults != null) {
                return this.openResults.size();
            }

            return 0;
        }
    } catch (StatementIsClosedException e) {
        // we can't break the interface, having this be no-op in case of error is ok

        return 0;
    }
}
 
Example #2
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if closed() has been called, and throws an exception if so
 * 
 * @throws StatementIsClosedException
 *             if this statement has been closed
 */
protected JdbcConnection checkClosed() {
    JdbcConnection c = this.connection;

    if (c == null) {
        throw ExceptionFactory.createException(StatementIsClosedException.class, Messages.getString("Statement.AlreadyClosed"), getExceptionInterceptor());
    }

    return c;
}
 
Example #3
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void removeOpenResultSet(ResultSetInternalMethods rs) {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            if (this.openResults != null) {
                this.openResults.remove(rs);
            }

            boolean hasMoreResults = rs.getNextResultset() != null;

            // clear the current results or GGK results
            if (this.results == rs && !hasMoreResults) {
                this.results = null;
            }
            if (this.generatedKeysResults == rs) {
                this.generatedKeysResults = null;
            }

            // trigger closeOnCompletion if:
            // a) the result set removal wasn't triggered internally
            // b) there are no additional results
            if (!this.isImplicitlyClosingResults && !hasMoreResults) {
                checkAndPerformCloseOnCompletionAction();
            }
        }
    } catch (StatementIsClosedException e) {
        // we can't break the interface, having this be no-op in case of error is ok
    }
}
 
Example #4
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public int getOpenResultSetCount() {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            if (this.openResults != null) {
                return this.openResults.size();
            }

            return 0;
        }
    } catch (StatementIsClosedException e) {
        // we can't break the interface, having this be no-op in case of error is ok

        return 0;
    }
}
 
Example #5
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ResultSetInternalMethods getResultSetInternal() {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            return this.results;
        }
    } catch (StatementIsClosedException e) {
        return this.results; // you end up with the same thing as before, you'll get exception when actually trying to use it
    }
}
 
Example #6
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setHoldResultsOpenOverClose(boolean holdResultsOpenOverClose) {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            this.holdResultsOpenOverClose = holdResultsOpenOverClose;
        }
    } catch (StatementIsClosedException e) {
        // FIXME: can't break interface at this point
    }
}
 
Example #7
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the concurrency for result sets generated by this statement
 * 
 * @param concurrencyFlag
 * @throws SQLException
 */
void setResultSetConcurrency(int concurrencyFlag) throws SQLException {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            this.resultSetConcurrency = concurrencyFlag;
            // updating resultset factory because concurrency is cached there
            this.resultSetFactory = new ResultSetFactory(this.connection, this);
        }
    } catch (StatementIsClosedException e) {
        // FIXME: Can't break interface atm, we'll get the exception later when you try and do something useful with a closed statement...
    }
}
 
Example #8
Source File: StatementImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the result set type for result sets generated by this statement
 * 
 * @param typeFlag
 * @throws SQLException
 */
void setResultSetType(Resultset.Type typeFlag) throws SQLException {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            this.query.setResultType(typeFlag);
            // updating resultset factory because type is cached there
            this.resultSetFactory = new ResultSetFactory(this.connection, this);
        }
    } catch (StatementIsClosedException e) {
        // FIXME: Can't break interface atm, we'll get the exception later when you try and do something useful with a closed statement...
    }
}
 
Example #9
Source File: MySQLJDBCReflections.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
void registerExceptionsForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJCommunicationsException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, CJConnectionFeatureNotAvailableException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJOperationNotSupportedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJTimeoutException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJPacketTooBigException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, AssertionFailedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, CJOperationNotSupportedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ClosedOnExpiredPasswordException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ConnectionIsClosedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataConversionException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataReadException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DataTruncationException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, DeadlockTimeoutRollbackMarker.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, FeatureNotAvailableException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, InvalidConnectionAttributeException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, NumberOutOfRange.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, OperationCancelledException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, PasswordExpiredException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, PropertyNotModifiableException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, RSAException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, SSLParamsException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StatementIsClosedException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StreamingNotifiable.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, UnableToConnectException.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, UnsupportedConnectionStringException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, WrongArgumentException.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.mysql.cj.jdbc.MysqlXAException"));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, StandardLoadBalanceExceptionChecker.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, NdbLoadBalanceExceptionChecker.class.getName()));
}
 
Example #10
Source File: StatementImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if closed() has been called, and throws an exception if so
 * 
 * @return connection
 * @throws StatementIsClosedException
 *             if this statement has been closed
 */
protected JdbcConnection checkClosed() {
    JdbcConnection c = this.connection;

    if (c == null) {
        throw ExceptionFactory.createException(StatementIsClosedException.class, Messages.getString("Statement.AlreadyClosed"), getExceptionInterceptor());
    }

    return c;
}
 
Example #11
Source File: StatementImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeOpenResultSet(ResultSetInternalMethods rs) {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            if (this.openResults != null) {
                this.openResults.remove(rs);
            }

            boolean hasMoreResults = rs.getNextResultset() != null;

            // clear the current results or GGK results
            if (this.results == rs && !hasMoreResults) {
                this.results = null;
            }
            if (this.generatedKeysResults == rs) {
                this.generatedKeysResults = null;
            }

            // trigger closeOnCompletion if:
            // a) the result set removal wasn't triggered internally
            // b) there are no additional results
            if (!this.isImplicitlyClosingResults && !hasMoreResults) {
                checkAndPerformCloseOnCompletionAction();
            }
        }
    } catch (StatementIsClosedException e) {
        // we can't break the interface, having this be no-op in case of error is ok
    }
}
 
Example #12
Source File: StatementImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
protected ResultSetInternalMethods getResultSetInternal() {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            return this.results;
        }
    } catch (StatementIsClosedException e) {
        return this.results; // you end up with the same thing as before, you'll get exception when actually trying to use it
    }
}
 
Example #13
Source File: StatementImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setHoldResultsOpenOverClose(boolean holdResultsOpenOverClose) {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            this.holdResultsOpenOverClose = holdResultsOpenOverClose;
        }
    } catch (StatementIsClosedException e) {
        // FIXME: can't break interface at this point
    }
}
 
Example #14
Source File: StatementImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the concurrency for result sets generated by this statement
 * 
 * @param concurrencyFlag
 *            concurrency flag
 * @throws SQLException
 *             if a database access error occurs or this method is called on a closed PreparedStatement
 */
void setResultSetConcurrency(int concurrencyFlag) throws SQLException {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            this.resultSetConcurrency = concurrencyFlag;
            // updating resultset factory because concurrency is cached there
            this.resultSetFactory = new ResultSetFactory(this.connection, this);
        }
    } catch (StatementIsClosedException e) {
        // FIXME: Can't break interface atm, we'll get the exception later when you try and do something useful with a closed statement...
    }
}
 
Example #15
Source File: StatementImpl.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the result set type for result sets generated by this statement
 * 
 * @param typeFlag
 *            {@link com.mysql.cj.protocol.Resultset.Type}
 * @throws SQLException
 *             if a database access error occurs or this method is called on a closed PreparedStatement
 */
void setResultSetType(Resultset.Type typeFlag) throws SQLException {
    try {
        synchronized (checkClosed().getConnectionMutex()) {
            this.query.setResultType(typeFlag);
            // updating resultset factory because type is cached there
            this.resultSetFactory = new ResultSetFactory(this.connection, this);
        }
    } catch (StatementIsClosedException e) {
        // FIXME: Can't break interface atm, we'll get the exception later when you try and do something useful with a closed statement...
    }
}
 
Example #16
Source File: SQLExceptionsMapping.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
public static SQLException translateException(Throwable ex, ExceptionInterceptor interceptor) {
    if (ex instanceof SQLException) {
        return (SQLException) ex;

    } else if (ex.getCause() != null && ex.getCause() instanceof SQLException) {
        return (SQLException) ex.getCause();

    } else if (ex instanceof CJCommunicationsException) {
        return SQLError.createCommunicationsException(ex.getMessage(), ex, interceptor);

    } else if (ex instanceof CJConnectionFeatureNotAvailableException) {
        return new ConnectionFeatureNotAvailableException(ex.getMessage(), ex);

    } else if (ex instanceof SSLParamsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_BAD_SSL_PARAMS, 0, false, ex, interceptor);

    } else if (ex instanceof ConnectionIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN, ex, interceptor);

    } else if (ex instanceof InvalidConnectionAttributeException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, ex, interceptor);

    } else if (ex instanceof UnableToConnectException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, ex, interceptor);

    } else if (ex instanceof StatementIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof WrongArgumentException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof StringIndexOutOfBoundsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof NumberOutOfRange) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE, ex, interceptor);

    } else if (ex instanceof DataConversionException) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST, ex, interceptor);

    } else if (ex instanceof DataReadException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof DataTruncationException) {
        return new MysqlDataTruncation(((DataTruncationException) ex).getMessage(), ((DataTruncationException) ex).getIndex(),
                ((DataTruncationException) ex).isParameter(), ((DataTruncationException) ex).isRead(), ((DataTruncationException) ex).getDataSize(),
                ((DataTruncationException) ex).getTransferSize(), ((DataTruncationException) ex).getVendorCode());

    } else if (ex instanceof CJPacketTooBigException) {
        return new PacketTooBigException(ex.getMessage());

    } else if (ex instanceof OperationCancelledException) {
        return new MySQLStatementCancelledException(ex.getMessage());

    } else if (ex instanceof CJTimeoutException) {
        return new MySQLTimeoutException(ex.getMessage());

    } else if (ex instanceof CJOperationNotSupportedException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof UnsupportedOperationException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof CJException) {
        return SQLError.createSQLException(ex.getMessage(), ((CJException) ex).getSQLState(), ((CJException) ex).getVendorCode(),
                ((CJException) ex).isTransient(), interceptor);

    } else {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, ex, interceptor);
    }
}
 
Example #17
Source File: SQLExceptionsMapping.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static SQLException translateException(Throwable ex, ExceptionInterceptor interceptor) {
    if (ex instanceof SQLException) {
        return (SQLException) ex;

    } else if (ex.getCause() != null && ex.getCause() instanceof SQLException) {
        return (SQLException) ex.getCause();

    } else if (ex instanceof CJCommunicationsException) {
        return SQLError.createCommunicationsException(ex.getMessage(), ex, interceptor);

    } else if (ex instanceof CJConnectionFeatureNotAvailableException) {
        return new ConnectionFeatureNotAvailableException(ex.getMessage(), ex);

    } else if (ex instanceof SSLParamsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_BAD_SSL_PARAMS, 0, false, ex, interceptor);

    } else if (ex instanceof ConnectionIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN, ex, interceptor);

    } else if (ex instanceof InvalidConnectionAttributeException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, ex, interceptor);

    } else if (ex instanceof UnableToConnectException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, ex, interceptor);

    } else if (ex instanceof StatementIsClosedException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof WrongArgumentException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof StringIndexOutOfBoundsException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof NumberOutOfRange) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE, ex, interceptor);

    } else if (ex instanceof DataConversionException) {
        // must come before DataReadException as it's more specific
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_INVALID_CHARACTER_VALUE_FOR_CAST, ex, interceptor);

    } else if (ex instanceof DataReadException) {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, ex, interceptor);

    } else if (ex instanceof DataTruncationException) {
        return new MysqlDataTruncation(((DataTruncationException) ex).getMessage(), ((DataTruncationException) ex).getIndex(),
                ((DataTruncationException) ex).isParameter(), ((DataTruncationException) ex).isRead(), ((DataTruncationException) ex).getDataSize(),
                ((DataTruncationException) ex).getTransferSize(), ((DataTruncationException) ex).getVendorCode());

    } else if (ex instanceof CJPacketTooBigException) {
        return new PacketTooBigException(ex.getMessage());

    } else if (ex instanceof OperationCancelledException) {
        return new MySQLStatementCancelledException(ex.getMessage());

    } else if (ex instanceof CJTimeoutException) {
        return new MySQLTimeoutException(ex.getMessage());

    } else if (ex instanceof CJOperationNotSupportedException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof UnsupportedOperationException) {
        return new OperationNotSupportedException(ex.getMessage());

    } else if (ex instanceof CJException) {
        return SQLError.createSQLException(ex.getMessage(), ((CJException) ex).getSQLState(), ((CJException) ex).getVendorCode(),
                ((CJException) ex).isTransient(), interceptor);

    } else {
        return SQLError.createSQLException(ex.getMessage(), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, ex, interceptor);
    }
}