Java Code Examples for com.mysql.cj.exceptions.MysqlErrorNumbers#ER_WARNING_NOT_COMPLETE_ROLLBACK

The following examples show how to use com.mysql.cj.exceptions.MysqlErrorNumbers#ER_WARNING_NOT_COMPLETE_ROLLBACK . 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: ConnectionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The method rollback() drops all changes made since the previous
 * commit/rollback and releases any database locks currently held by the
 * Connection.
 * 
 * @exception SQLException
 *                if a database access error occurs
 * @see commit
 */
public void rollback() throws SQLException {
    synchronized (getConnectionMutex()) {
        checkClosed();

        try {
            if (this.connectionLifecycleInterceptors != null) {
                IterateBlock<ConnectionLifecycleInterceptor> iter = new IterateBlock<ConnectionLifecycleInterceptor>(
                        this.connectionLifecycleInterceptors.iterator()) {

                    @Override
                    void forEach(ConnectionLifecycleInterceptor each) throws SQLException {
                        if (!each.rollback()) {
                            this.stopIterating = true;
                        }
                    }
                };

                iter.doForAll();

                if (!iter.fullIteration()) {
                    return;
                }
            }
            if (this.session.getServerSession().isAutoCommit()) {
                throw SQLError.createSQLException(Messages.getString("Connection.20"), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN,
                        getExceptionInterceptor());
            }
            try {
                rollbackNoChecks();
            } catch (SQLException sqlEx) {
                // We ignore non-transactional tables if told to do so
                if (this.ignoreNonTxTables.getInitialValue() && (sqlEx.getErrorCode() == MysqlErrorNumbers.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
                    return;
                }
                throw sqlEx;

            }
        } catch (SQLException sqlException) {
            if (MysqlErrorNumbers.SQL_STATE_COMMUNICATION_LINK_FAILURE.equals(sqlException.getSQLState())) {
                throw SQLError.createSQLException(Messages.getString("Connection.21"), MysqlErrorNumbers.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN,
                        getExceptionInterceptor());
            }

            throw sqlException;
        } finally {
            this.session.setNeedsPing(this.reconnectAtTxEnd.getValue());
        }
    }
}
 
Example 2
Source File: ConnectionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void rollback(final Savepoint savepoint) throws SQLException {

        synchronized (getConnectionMutex()) {
            checkClosed();

            try {
                if (this.connectionLifecycleInterceptors != null) {
                    IterateBlock<ConnectionLifecycleInterceptor> iter = new IterateBlock<ConnectionLifecycleInterceptor>(
                            this.connectionLifecycleInterceptors.iterator()) {

                        @Override
                        void forEach(ConnectionLifecycleInterceptor each) throws SQLException {
                            if (!each.rollback(savepoint)) {
                                this.stopIterating = true;
                            }
                        }
                    };

                    iter.doForAll();

                    if (!iter.fullIteration()) {
                        return;
                    }
                }

                StringBuilder rollbackQuery = new StringBuilder("ROLLBACK TO SAVEPOINT ");
                rollbackQuery.append('`');
                rollbackQuery.append(savepoint.getSavepointName());
                rollbackQuery.append('`');

                java.sql.Statement stmt = null;

                try {
                    stmt = getMetadataSafeStatement();

                    stmt.executeUpdate(rollbackQuery.toString());
                } catch (SQLException sqlEx) {
                    int errno = sqlEx.getErrorCode();

                    if (errno == 1181) {
                        String msg = sqlEx.getMessage();

                        if (msg != null) {
                            int indexOfError153 = msg.indexOf("153");

                            if (indexOfError153 != -1) {
                                throw SQLError.createSQLException(Messages.getString("Connection.22", new Object[] { savepoint.getSavepointName() }),
                                        MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, errno, getExceptionInterceptor());
                            }
                        }
                    }

                    // We ignore non-transactional tables if told to do so
                    if (this.ignoreNonTxTables.getValue() && (sqlEx.getErrorCode() != MysqlErrorNumbers.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
                        throw sqlEx;
                    }

                    if (MysqlErrorNumbers.SQL_STATE_COMMUNICATION_LINK_FAILURE.equals(sqlEx.getSQLState())) {
                        throw SQLError.createSQLException(Messages.getString("Connection.23"), MysqlErrorNumbers.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN,
                                getExceptionInterceptor());
                    }

                    throw sqlEx;
                } finally {
                    closeStatement(stmt);
                }
            } finally {
                this.session.setNeedsPing(this.reconnectAtTxEnd.getValue());
            }
        }
    }
 
Example 3
Source File: ConnectionImpl.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void rollback() throws SQLException {
    synchronized (getConnectionMutex()) {
        checkClosed();

        try {
            if (this.connectionLifecycleInterceptors != null) {
                IterateBlock<ConnectionLifecycleInterceptor> iter = new IterateBlock<ConnectionLifecycleInterceptor>(
                        this.connectionLifecycleInterceptors.iterator()) {

                    @Override
                    void forEach(ConnectionLifecycleInterceptor each) throws SQLException {
                        if (!each.rollback()) {
                            this.stopIterating = true;
                        }
                    }
                };

                iter.doForAll();

                if (!iter.fullIteration()) {
                    return;
                }
            }
            if (this.session.getServerSession().isAutoCommit()) {
                throw SQLError.createSQLException(Messages.getString("Connection.20"), MysqlErrorNumbers.SQL_STATE_CONNECTION_NOT_OPEN,
                        getExceptionInterceptor());
            }
            try {
                rollbackNoChecks();
            } catch (SQLException sqlEx) {
                // We ignore non-transactional tables if told to do so
                if (this.ignoreNonTxTables.getInitialValue() && (sqlEx.getErrorCode() == MysqlErrorNumbers.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
                    return;
                }
                throw sqlEx;

            }
        } catch (SQLException sqlException) {
            if (MysqlErrorNumbers.SQL_STATE_COMMUNICATION_LINK_FAILURE.equals(sqlException.getSQLState())) {
                throw SQLError.createSQLException(Messages.getString("Connection.21"), MysqlErrorNumbers.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN,
                        getExceptionInterceptor());
            }

            throw sqlException;
        } finally {
            this.session.setNeedsPing(this.reconnectAtTxEnd.getValue());
        }
    }
}
 
Example 4
Source File: ConnectionImpl.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void rollback(final Savepoint savepoint) throws SQLException {

    synchronized (getConnectionMutex()) {
        checkClosed();

        try {
            if (this.connectionLifecycleInterceptors != null) {
                IterateBlock<ConnectionLifecycleInterceptor> iter = new IterateBlock<ConnectionLifecycleInterceptor>(
                        this.connectionLifecycleInterceptors.iterator()) {

                    @Override
                    void forEach(ConnectionLifecycleInterceptor each) throws SQLException {
                        if (!each.rollback(savepoint)) {
                            this.stopIterating = true;
                        }
                    }
                };

                iter.doForAll();

                if (!iter.fullIteration()) {
                    return;
                }
            }

            StringBuilder rollbackQuery = new StringBuilder("ROLLBACK TO SAVEPOINT ");
            rollbackQuery.append('`');
            rollbackQuery.append(savepoint.getSavepointName());
            rollbackQuery.append('`');

            java.sql.Statement stmt = null;

            try {
                stmt = getMetadataSafeStatement();

                stmt.executeUpdate(rollbackQuery.toString());
            } catch (SQLException sqlEx) {
                int errno = sqlEx.getErrorCode();

                if (errno == 1181) {
                    String msg = sqlEx.getMessage();

                    if (msg != null) {
                        int indexOfError153 = msg.indexOf("153");

                        if (indexOfError153 != -1) {
                            throw SQLError.createSQLException(Messages.getString("Connection.22", new Object[] { savepoint.getSavepointName() }),
                                    MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, errno, getExceptionInterceptor());
                        }
                    }
                }

                // We ignore non-transactional tables if told to do so
                if (this.ignoreNonTxTables.getValue() && (sqlEx.getErrorCode() != MysqlErrorNumbers.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
                    throw sqlEx;
                }

                if (MysqlErrorNumbers.SQL_STATE_COMMUNICATION_LINK_FAILURE.equals(sqlEx.getSQLState())) {
                    throw SQLError.createSQLException(Messages.getString("Connection.23"), MysqlErrorNumbers.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN,
                            getExceptionInterceptor());
                }

                throw sqlEx;
            } finally {
                closeStatement(stmt);
            }
        } finally {
            this.session.setNeedsPing(this.reconnectAtTxEnd.getValue());
        }
    }
}