예제 #1
0
 private String[] getInsertSql(ColumnTypeHelper helper, WriteRowsEvent event, ITableReplicator rep)
     throws UnsupportedEncodingException {
   RDBSchnauzer table = (RDBSchnauzer) rep;
   if (rep.isMergeTable() && slaveDb.isMySQL()) {
     return getInsertUpdateSql(helper, event, table);
   } else if (rep.isMergeTable() && slaveDb.isSQLServer()) {
     return getInsUpSqlSql(helper, event, table);
   } else if (this.slaveDb.isSQLServer2000()) {
     return getSql2000Sql(helper, event, table);
   } else {
     return getCommInsertSql(helper, event, table);
   }
 }
예제 #2
0
  @Override
  public boolean doDelete(ColumnTypeHelper helper, DeleteRowsEvent event) {
    boolean need = false;
    String[] sqls = null;
    int index = 0;
    doBeforeDelete(helper, event);
    for (int i = 0; i < tables.size(); i++) {
      RDBSchnauzer rep = (RDBSchnauzer) tables.get(i);
      if (notEqualS(helper.databaseName, masterDb.dbname)) continue;
      if (notEqualS(helper.tableName, rep.getMasterTableName())) continue;
      List<Row> rows = event.getRows();
      for (int j = 0; j < rows.size(); j++) {
        Row row = rows.get(j);
        List<Column> columns = row.getColumns();
        if (sqls == null) {
          sqls = new String[rows.size() * tables.size() + 1];
          sqls[0] = getStatusUpdateSql(helper);
        }
        need = true;
        try {
          sqls[++index] = rep.getDelete() + getWhereStr(rep, columns, helper);
        } catch (Exception e) {
          mailAndLog(Infos.Create + Infos.DoDelete + Infos.Failed, e.getMessage());
          return false;
        }
      }
    }

    String[] errInfo = new String[1];

    if (!need || !logSql(sqls)) {
      autoSetPosition(helper);
      return true;
    }

    if (dbhelper.excuteSqlByTransaction(sqls, errInfo)) {
      slaveDb.binlog = this.getBinLogName(helper);
      slaveDb.pos = helper.position;
      slaveDb.tablepos = helper.tableMapPos;
      LOGGER.info(Infos.DoDelete + Infos.OK);
      return true;
    }

    String sInfo = getWarning(sqls, errInfo);
    mailAndLog(Infos.DoDelete + Infos.Failed, sInfo);
    rollBackToTableEvent(helper);
    return false;
  }
예제 #3
0
  private void getTheLastBinlogAndPos() {
    try {
      MySQLDbHelper mhelper = new MySQLDbHelper(masterDb);
      ResultSet rs = mhelper.getRS("show master logs");
      String binlog = "";
      Long pos = 0L;
      while (rs.next()) {
        binlog = rs.getString("log_name");
      }
      rs.close();
      rs = mhelper.getRS("show binlog events in '" + binlog + "'");
      while (rs.next()) {
        pos = rs.getLong("pos");
      }
      rs.close();
      masterDb.binlog = binlog;
      masterDb.pos = pos;
      slaveDb.binlog = binlog;
      slaveDb.pos = pos;

    } catch (Exception e) {
      ErrorHelper.errExit("Get binlog filename " + Infos.Failed + ": " + e.getMessage());
    }
  }