コード例 #1
0
  @Override
  protected void addStoredFunction(DdlWrite writer, MTable table, HistoryTableUpdate update)
      throws IOException {

    String procedureName = procedureName(table.getName());
    String historyTable = historyTableName(table.getName());

    List<String> includedColumns = includedColumnNames(table);

    DdlBuffer apply = writer.applyHistory();

    if (update != null) {
      apply.append("-- Regenerated ").append(procedureName).newLine();
      apply.append("-- changes: ").append(update.description()).newLine();
    }

    addFunction(apply, procedureName, historyTable, includedColumns);

    if (update != null) {
      // put a reverted version into the rollback buffer
      update.toRevertedColumns(includedColumns);

      DdlBuffer rollback = writer.rollback();
      rollback.append("-- Revert regenerated ").append(procedureName).newLine();
      rollback.append("-- revert changes: ").append(update.description()).newLine();

      addFunction(rollback, procedureName, historyTable, includedColumns);
    }
  }
コード例 #2
0
  /** Use Postgres create table like to create the history table. */
  @Override
  protected void createHistoryTable(DdlBuffer apply, MTable table) throws IOException {

    String baseTable = table.getName();
    apply
        .append("create table ")
        .append(baseTable)
        .append(historySuffix)
        .append("(like ")
        .append(baseTable)
        .append(")")
        .endOfStatement();
  }
コード例 #3
0
  @Override
  protected void createTriggers(DdlWrite writer, MTable table) throws IOException {

    String baseTableName = table.getName();
    String procedureName = procedureName(baseTableName);
    String triggerName = triggerName(baseTableName);

    DdlBuffer apply = writer.applyHistory();
    apply
        .append("create trigger ")
        .append(triggerName)
        .newLine()
        .append("  before update or delete on ")
        .append(baseTableName)
        .newLine()
        .append("  for each row execute procedure ")
        .append(procedureName)
        .append("();")
        .newLine()
        .newLine();
  }