Search in sources :

Example 1 with StatementIsClosedException

use of com.mysql.cj.exceptions.StatementIsClosedException in project ABC by RuiPinto96274.

the class ClientPreparedStatement method executeBatchSerially.

/**
 * Executes the current batch of statements by executing them one-by-one.
 *
 * @param batchTimeout
 *            timeout for the batch execution
 * @return a list of update counts
 * @throws SQLException
 *             if an error occurs
 */
protected long[] executeBatchSerially(int batchTimeout) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.connection == null) {
            checkClosed();
        }
        long[] updateCounts = null;
        if (this.query.getBatchedArgs() != null) {
            int nbrCommands = this.query.getBatchedArgs().size();
            updateCounts = new long[nbrCommands];
            for (int i = 0; i < nbrCommands; i++) {
                updateCounts[i] = -3;
            }
            SQLException sqlEx = null;
            CancelQueryTask timeoutTask = null;
            try {
                timeoutTask = startQueryTimer(this, batchTimeout);
                if (this.retrieveGeneratedKeys) {
                    this.batchedGeneratedKeys = new ArrayList<>(nbrCommands);
                }
                int batchCommandIndex = ((PreparedQuery<?>) this.query).getBatchCommandIndex();
                for (batchCommandIndex = 0; batchCommandIndex < nbrCommands; batchCommandIndex++) {
                    ((PreparedQuery<?>) this.query).setBatchCommandIndex(batchCommandIndex);
                    Object arg = this.query.getBatchedArgs().get(batchCommandIndex);
                    try {
                        if (arg instanceof String) {
                            updateCounts[batchCommandIndex] = executeUpdateInternal((String) arg, true, this.retrieveGeneratedKeys);
                            // limit one generated key per OnDuplicateKey statement
                            getBatchedGeneratedKeys(this.results.getFirstCharOfQuery() == 'I' && containsOnDuplicateKeyInString((String) arg) ? 1 : 0);
                        } else {
                            QueryBindings<?> queryBindings = (QueryBindings<?>) arg;
                            updateCounts[batchCommandIndex] = executeUpdateInternal(queryBindings, true);
                            // limit one generated key per OnDuplicateKey statement
                            getBatchedGeneratedKeys(containsOnDuplicateKeyUpdateInSQL() ? 1 : 0);
                        }
                    } catch (SQLException ex) {
                        updateCounts[batchCommandIndex] = EXECUTE_FAILED;
                        if (this.continueBatchOnError && !(ex instanceof MySQLTimeoutException) && !(ex instanceof MySQLStatementCancelledException) && !hasDeadlockOrTimeoutRolledBackTx(ex)) {
                            sqlEx = ex;
                        } else {
                            long[] newUpdateCounts = new long[batchCommandIndex];
                            System.arraycopy(updateCounts, 0, newUpdateCounts, 0, batchCommandIndex);
                            throw SQLError.createBatchUpdateException(ex, newUpdateCounts, this.exceptionInterceptor);
                        }
                    }
                }
                if (sqlEx != null) {
                    throw SQLError.createBatchUpdateException(sqlEx, updateCounts, this.exceptionInterceptor);
                }
            } catch (NullPointerException npe) {
                try {
                    checkClosed();
                } catch (StatementIsClosedException connectionClosedEx) {
                    int batchCommandIndex = ((PreparedQuery<?>) this.query).getBatchCommandIndex();
                    updateCounts[batchCommandIndex] = EXECUTE_FAILED;
                    long[] newUpdateCounts = new long[batchCommandIndex];
                    System.arraycopy(updateCounts, 0, newUpdateCounts, 0, batchCommandIndex);
                    throw SQLError.createBatchUpdateException(SQLExceptionsMapping.translateException(connectionClosedEx), newUpdateCounts, this.exceptionInterceptor);
                }
                // we don't know why this happened, punt
                throw npe;
            } finally {
                ((PreparedQuery<?>) this.query).setBatchCommandIndex(-1);
                stopQueryTimer(timeoutTask, false, false);
                resetCancelledState();
            }
        }
        return (updateCounts != null) ? updateCounts : new long[0];
    }
}
Also used : SQLException(java.sql.SQLException) QueryBindings(com.mysql.cj.QueryBindings) ClientPreparedQueryBindings(com.mysql.cj.ClientPreparedQueryBindings) ClientPreparedQuery(com.mysql.cj.ClientPreparedQuery) PreparedQuery(com.mysql.cj.PreparedQuery) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CancelQueryTask(com.mysql.cj.CancelQueryTask) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) StatementIsClosedException(com.mysql.cj.exceptions.StatementIsClosedException)

Example 2 with StatementIsClosedException

use of com.mysql.cj.exceptions.StatementIsClosedException in project ABC by RuiPinto96274.

the class StatementImpl method setResultSetConcurrency.

/**
 * 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...
    }
}
Also used : ResultSetFactory(com.mysql.cj.jdbc.result.ResultSetFactory) StatementIsClosedException(com.mysql.cj.exceptions.StatementIsClosedException)

Example 3 with StatementIsClosedException

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

the class ClientPreparedStatement method executeBatchSerially.

/**
 * Executes the current batch of statements by executing them one-by-one.
 *
 * @param batchTimeout
 *            timeout for the batch execution
 * @return a list of update counts
 * @throws SQLException
 *             if an error occurs
 */
protected long[] executeBatchSerially(int batchTimeout) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.connection == null) {
            checkClosed();
        }
        long[] updateCounts = null;
        if (this.query.getBatchedArgs() != null) {
            int nbrCommands = this.query.getBatchedArgs().size();
            updateCounts = new long[nbrCommands];
            for (int i = 0; i < nbrCommands; i++) {
                updateCounts[i] = -3;
            }
            SQLException sqlEx = null;
            CancelQueryTask timeoutTask = null;
            try {
                timeoutTask = startQueryTimer(this, batchTimeout);
                if (this.retrieveGeneratedKeys) {
                    this.batchedGeneratedKeys = new ArrayList<>(nbrCommands);
                }
                int batchCommandIndex = ((PreparedQuery<?>) this.query).getBatchCommandIndex();
                for (batchCommandIndex = 0; batchCommandIndex < nbrCommands; batchCommandIndex++) {
                    ((PreparedQuery<?>) this.query).setBatchCommandIndex(batchCommandIndex);
                    Object arg = this.query.getBatchedArgs().get(batchCommandIndex);
                    try {
                        if (arg instanceof String) {
                            updateCounts[batchCommandIndex] = executeUpdateInternal((String) arg, true, this.retrieveGeneratedKeys);
                            // limit one generated key per OnDuplicateKey statement
                            getBatchedGeneratedKeys(this.results.getFirstCharOfQuery() == 'I' && containsOnDuplicateKeyInString((String) arg) ? 1 : 0);
                        } else {
                            QueryBindings<?> queryBindings = (QueryBindings<?>) arg;
                            updateCounts[batchCommandIndex] = executeUpdateInternal(queryBindings, true);
                            // limit one generated key per OnDuplicateKey statement
                            getBatchedGeneratedKeys(containsOnDuplicateKeyUpdateInSQL() ? 1 : 0);
                        }
                    } catch (SQLException ex) {
                        updateCounts[batchCommandIndex] = EXECUTE_FAILED;
                        if (this.continueBatchOnError && !(ex instanceof MySQLTimeoutException) && !(ex instanceof MySQLStatementCancelledException) && !hasDeadlockOrTimeoutRolledBackTx(ex)) {
                            sqlEx = ex;
                        } else {
                            long[] newUpdateCounts = new long[batchCommandIndex];
                            System.arraycopy(updateCounts, 0, newUpdateCounts, 0, batchCommandIndex);
                            throw SQLError.createBatchUpdateException(ex, newUpdateCounts, this.exceptionInterceptor);
                        }
                    }
                }
                if (sqlEx != null) {
                    throw SQLError.createBatchUpdateException(sqlEx, updateCounts, this.exceptionInterceptor);
                }
            } catch (NullPointerException npe) {
                try {
                    checkClosed();
                } catch (StatementIsClosedException connectionClosedEx) {
                    int batchCommandIndex = ((PreparedQuery<?>) this.query).getBatchCommandIndex();
                    updateCounts[batchCommandIndex] = EXECUTE_FAILED;
                    long[] newUpdateCounts = new long[batchCommandIndex];
                    System.arraycopy(updateCounts, 0, newUpdateCounts, 0, batchCommandIndex);
                    throw SQLError.createBatchUpdateException(SQLExceptionsMapping.translateException(connectionClosedEx), newUpdateCounts, this.exceptionInterceptor);
                }
                // we don't know why this happened, punt
                throw npe;
            } finally {
                ((PreparedQuery<?>) this.query).setBatchCommandIndex(-1);
                stopQueryTimer(timeoutTask, false, false);
                resetCancelledState();
            }
        }
        return (updateCounts != null) ? updateCounts : new long[0];
    }
}
Also used : SQLException(java.sql.SQLException) QueryBindings(com.mysql.cj.QueryBindings) ClientPreparedQueryBindings(com.mysql.cj.ClientPreparedQueryBindings) ClientPreparedQuery(com.mysql.cj.ClientPreparedQuery) PreparedQuery(com.mysql.cj.PreparedQuery) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CancelQueryTask(com.mysql.cj.CancelQueryTask) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) StatementIsClosedException(com.mysql.cj.exceptions.StatementIsClosedException)

Example 4 with StatementIsClosedException

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

the class StatementImpl method setResultSetConcurrency.

/**
 * 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...
    }
}
Also used : ResultSetFactory(com.mysql.cj.jdbc.result.ResultSetFactory) StatementIsClosedException(com.mysql.cj.exceptions.StatementIsClosedException)

Example 5 with StatementIsClosedException

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

the class StatementImpl method setResultSetType.

/**
 * 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...
    }
}
Also used : ResultSetFactory(com.mysql.cj.jdbc.result.ResultSetFactory) StatementIsClosedException(com.mysql.cj.exceptions.StatementIsClosedException)

Aggregations

StatementIsClosedException (com.mysql.cj.exceptions.StatementIsClosedException)9 ResultSetFactory (com.mysql.cj.jdbc.result.ResultSetFactory)6 CancelQueryTask (com.mysql.cj.CancelQueryTask)3 ClientPreparedQuery (com.mysql.cj.ClientPreparedQuery)3 ClientPreparedQueryBindings (com.mysql.cj.ClientPreparedQueryBindings)3 PreparedQuery (com.mysql.cj.PreparedQuery)3 QueryBindings (com.mysql.cj.QueryBindings)3 MySQLStatementCancelledException (com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException)3 MySQLTimeoutException (com.mysql.cj.jdbc.exceptions.MySQLTimeoutException)3 SQLException (java.sql.SQLException)3