private void consistencyCheck(String where) throws SQLException, ConsistencyException {
  String schemaName=null;
  String tableName=null;
  int id=-1;
  int rowOffset=ConsistencyTable.ROW_UNSET;
  int rowLimit=ConsistencyTable.ROW_UNSET;
  String method;
  int this_cnt=0, master_cnt;
  String this_crc=null, master_crc;
  String select=consistencySelect + where;
  if (logger.isDebugEnabled())   logger.debug("ConsistencyTable row SELECT: " + select);
  ResultSet res=null;
  ResultSet ccres=null;
  try {
    res=statement.executeQuery(select);
    if (res.next()) {
      schemaName=trim(res.getString(ConsistencyTable.dbColumnName));
      tableName=trim(res.getString(ConsistencyTable.tblColumnName));
      id=res.getInt(ConsistencyTable.idColumnName);
      master_cnt=res.getInt(ConsistencyTable.masterCntColumnName);
      master_crc=trim(res.getString(ConsistencyTable.masterCrcColumnName));
      rowOffset=res.getInt(ConsistencyTable.offsetColumnName);
      rowLimit=res.getInt(ConsistencyTable.limitColumnName);
      method=trim(res.getString(ConsistencyTable.methodColumnName));
      Table table=conn.findTable(schemaName,tableName,false);
      if (table == null)       throw new ConsistencyException("Table not found: " + schemaName + "."+ tableName);
      ConsistencyCheck cc=ConsistencyCheckFactory.createConsistencyCheck(id,table,rowOffset,rowLimit,method,runtime.isConsistencyCheckColumnNames(),runtime.isConsistencyCheckColumnTypes());
      if (logger.isDebugEnabled())       logger.debug("Got consistency check: " + cc.toString());
      ccres=cc.performConsistencyCheck(conn);
      if (ccres.next()) {
        this_cnt=ccres.getInt(ConsistencyTable.thisCntColumnName);
        this_crc=trim(ccres.getString(ConsistencyTable.thisCrcColumnName));
        StringBuffer update=new StringBuffer(256);
        update.append("UPDATE ");
        update.append(consistencyTable);
        update.append(" SET ");
        update.append(ConsistencyTable.thisCntColumnName);
        update.append(" = ");
        update.append(this_cnt);
        update.append(", ");
        update.append(ConsistencyTable.thisCrcColumnName);
        update.append(" = '");
        update.append(this_crc);
        update.append("' ");
        update.append(where);
        if (logger.isDebugEnabled())         logger.debug(update.toString());
        statement.executeUpdate(update.toString());
      }
 else {
        String msg="Consistency check returned empty ResultSet.";
        logger.warn(msg);
      }
    }
 else {
      throw new ConsistencyException("Failed to retrieve consistency check result.");
    }
  }
  finally {
    if (res != null) {
      res.close();
    }
    if (ccres != null) {
      ccres.close();
    }
  }
  if (master_cnt == this_cnt) {
    if ((master_crc != null && this_crc != null && 0 == master_crc.compareTo(this_crc)) || (master_crc == null && this_crc == null)) {
      String msg="Consistency check succeeded on table '" + schemaName + "."+ tableName+ "' id: "+ id+ ", offset: "+ rowOffset+ ", limit: "+ rowLimit+ ", method: '"+ method+ "' succeeded";
      logger.info(msg);
      String debug="this_cnt  : " + this_cnt + "\nmaster_cnt: "+ master_cnt+ "\nthis_crc  : "+ this_crc+ "\nmaster_crc: "+ master_crc;
      if (logger.isDebugEnabled())       logger.debug(debug);
      return;
    }
  }
  String msg="Consistency check failed on table '" + schemaName + "."+ tableName+ "' id: "+ id+ ", offset: "+ rowOffset+ ", limit: "+ rowLimit+ ", method: '"+ method+ "' failed";
  if (logger.isDebugEnabled())   msg+="\nthis_cnt  : " + this_cnt + "\nmaster_cnt: "+ master_cnt+ "\nthis_crc  : "+ this_crc+ "\nmaster_crc: "+ master_crc;
  throw new ConsistencyException(msg);
}

private void consistencyCheck ( String where ) throws SQLException , ConsistencyException { String schemaName = null ; String tableName = null ; int id = - 1 ; int rowOffset = ConsistencyTable . ROW_UNSET ; int rowLimit = ConsistencyTable . ROW_UNSET ; String method ; int this_cnt = 0 , master_cnt ; String this_crc = null , master_crc ; String select = consistencySelect + where ; if ( logger . isDebugEnabled ( ) ) logger . debug ( "ConsistencyTable row SELECT: " + select ) ; ResultSet res = null ; ResultSet ccres = null ; try { res = statement . executeQuery ( select ) ; if ( res . next ( ) ) { schemaName = trim ( res . getString ( ConsistencyTable . dbColumnName ) ) ; tableName = trim ( res . getString ( ConsistencyTable . tblColumnName ) ) ; id = res . getInt ( ConsistencyTable . idColumnName ) ; master_cnt = res . getInt ( ConsistencyTable . masterCntColumnName ) ; master_crc = trim ( res . getString ( ConsistencyTable . masterCrcColumnName ) ) ; rowOffset = res . getInt ( ConsistencyTable . offsetColumnName ) ; rowLimit = res . getInt ( ConsistencyTable . limitColumnName ) ; method = trim ( res . getString ( ConsistencyTable . methodColumnName ) ) ; Table table = conn . findTable ( schemaName , tableName , false ) ; if ( table == null ) throw new ConsistencyException ( "Table not found: " + schemaName + "." + tableName ) ; ConsistencyCheck cc = ConsistencyCheckFactory . createConsistencyCheck ( id , table , rowOffset , rowLimit , method , runtime . isConsistencyCheckColumnNames ( ) , runtime . isConsistencyCheckColumnTypes ( ) ) ; if ( logger . isDebugEnabled ( ) ) logger . debug ( "Got consistency check: " + cc . toString ( ) ) ; ccres = cc . performConsistencyCheck ( conn ) ; if ( ccres . next ( ) ) { this_cnt = ccres . getInt ( ConsistencyTable . thisCntColumnName ) ; this_crc = trim ( ccres . getString ( ConsistencyTable . thisCrcColumnName ) ) ; StringBuffer update = new StringBuffer ( 256 ) ; update . append ( "UPDATE " ) ; update . append ( consistencyTable ) ; update . append ( " SET " ) ; update . append ( ConsistencyTable . thisCntColumnName ) ; update . append ( " = " ) ; update . append ( this_cnt ) ; update . append ( ", " ) ; update . append ( ConsistencyTable . thisCrcColumnName ) ; update . append ( " = '" ) ; update . append ( this_crc ) ; update . append ( "' " ) ; update . append ( where ) ; if ( logger . isDebugEnabled ( ) ) logger . debug ( update . toString ( ) ) ; statement . executeUpdate ( update . toString ( ) ) ; } else { String msg = "Consistency check returned empty ResultSet." ; logger . warn ( msg ) ; } } else { throw new ConsistencyException ( "Failed to retrieve consistency check result." ) ; } } finally { if ( res != null ) { res . close ( ) ; } if ( ccres != null ) { ccres . close ( ) ; } } if ( master_cnt == this_cnt ) { if ( ( master_crc != null && this_crc != null && 0 == master_crc . compareTo ( this_crc ) ) || ( master_crc == null && this_crc == null ) ) { String msg = "Consistency check succeeded on table '" + schemaName + "." + tableName + "' id: " + id + ", offset: " + rowOffset + ", limit: " + rowLimit + ", method: '" + method + "' succeeded" ; logger . info ( msg ) ; String debug = "this_cnt  : " + this_cnt + "\nmaster_cnt: " + master_cnt + "\nthis_crc  : " + this_crc + "\nmaster_crc: " + master_crc ; if ( logger . isDebugEnabled ( ) ) logger . debug ( debug ) ; return ; } } String msg = "Consistency check failed on table '" + schemaName + "." + tableName + "' id: " + id + ", offset: " + rowOffset + ", limit: " + rowLimit + ", method: '" + method + "' failed" ; if ( logger . isDebugEnabled ( ) ) msg += "\nthis_cnt  : " + this_cnt + "\nmaster_cnt: " + master_cnt + "\nthis_crc  : " + this_crc + "\nmaster_crc: " + master_crc ; throw new ConsistencyException ( msg ) ; }
compares consistency check values obtained on master and here .
