void nextExecuted(String sql) throws SQLException
    {
        count++;

        if (_order.contains(sql))
        {
            return;
        }

        String sqlCmd = sql.substring(0, 7);
        String rest = sql.substring(sqlCmd.equals("UPDATE ") ? 7 // "UPDATE "
                : 12); // "INSERT INTO " or "DELETE FROM "
        String tableName = rest.substring(0, rest.indexOf(' '));
        HashSet fkTables = (HashSet) _fkInfo.get(tableName);

        // we should not change order of INSERT/DELETE/UPDATE
        // statements for the same table
        if (_touched.contains(tableName))
        {
            executeBatch();
        }
        if (sqlCmd.equals("INSERT "))
        {
            if (_dontInsert != null && _dontInsert.contains(tableName))
            {
                // one of the previous INSERTs contained a table
                // that references this table.
                // Let's execute that previous INSERT right now so that
                // in the future INSERTs into this table will go first
                // in the _order array.
                executeBatch();
            }
        }
        else
        //if (sqlCmd.equals("DELETE ") || sqlCmd.equals("UPDATE "))
        {
            // We process UPDATEs in the same way as DELETEs
            // because setting FK to NULL in UPDATE is equivalent
            // to DELETE from the referential integrity point of view.

            if (_deleted != null && fkTables != null)
            {
                HashSet intersection = (HashSet) _deleted.clone();

                intersection.retainAll(fkTables);
                if (!intersection.isEmpty())
                {
                    // one of the previous DELETEs contained a table
                    // that is referenced from this table.
                    // Let's execute that previous DELETE right now so that
                    // in the future DELETEs into this table will go first
                    // in the _order array.
                    executeBatch();
                }
            }
        }

        _order.add(sql);

        _touched.add(tableName);
        if (sqlCmd.equals("INSERT "))
        {
            if (fkTables != null)
            {
                if (_dontInsert == null)
                {
                    _dontInsert = new HashSet();
                }
                _dontInsert.addAll(fkTables);
            }
        }
        else if (sqlCmd.equals("DELETE "))
        {
            if (_deleted == null)
            {
                _deleted = new HashSet();
            }
            _deleted.add(tableName);
        }
    }
void nextExecuted ( String sql ) throws SQLException { count ++ ; if ( _order . contains ( sql ) ) { return ; } String sqlCmd = sql . substring ( 0 , 7 ) ; String rest = sql . substring ( sqlCmd . equals ( "UPDATE " ) ? 7 : 12 ) ; String tableName = rest . substring ( 0 , rest . indexOf ( ' ' ) ) ; HashSet fkTables = ( HashSet ) _fkInfo . get ( tableName ) ; if ( _touched . contains ( tableName ) ) { executeBatch ( ) ; } if ( sqlCmd . equals ( "INSERT " ) ) { if ( _dontInsert != null && _dontInsert . contains ( tableName ) ) { executeBatch ( ) ; } } else { if ( _deleted != null && fkTables != null ) { HashSet intersection = ( HashSet ) _deleted . clone ( ) ; intersection . retainAll ( fkTables ) ; if ( ! intersection . isEmpty ( ) ) { executeBatch ( ) ; } } } _order . add ( sql ) ; _touched . add ( tableName ) ; if ( sqlCmd . equals ( "INSERT " ) ) { if ( fkTables != null ) { if ( _dontInsert == null ) { _dontInsert = new HashSet ( ) ; } _dontInsert . addAll ( fkTables ) ; } } else if ( sqlCmd . equals ( "DELETE " ) ) { if ( _deleted == null ) { _deleted = new HashSet ( ) ; } _deleted . add ( tableName ) ; } }
Remember the order of execution