コード例 #1
0
ファイル: PgDiffTriggers.java プロジェクト: Xatter/apgdiff
  /**
   * Returns list of triggers that should be dropped.
   *
   * @param oldTable original table
   * @param newTable new table
   * @return list of triggers that should be dropped
   */
  private static List<PgTrigger> getDropTriggers(final PgTable oldTable, final PgTable newTable) {
    @SuppressWarnings("CollectionWithoutInitialCapacity")
    final List<PgTrigger> list = new ArrayList<PgTrigger>();

    if (newTable != null && oldTable != null) {
      final List<PgTrigger> newTriggers = newTable.getTriggers();

      for (final PgTrigger oldTrigger : oldTable.getTriggers()) {
        if (!newTriggers.contains(oldTrigger)) {
          list.add(oldTrigger);
        }
      }
    }

    return list;
  }
コード例 #2
0
ファイル: PgDiffTriggers.java プロジェクト: Xatter/apgdiff
  /**
   * Returns list of triggers that should be added.
   *
   * @param oldTable original table
   * @param newTable new table
   * @return list of triggers that should be added
   */
  private static List<PgTrigger> getNewTriggers(final PgTable oldTable, final PgTable newTable) {
    @SuppressWarnings("CollectionWithoutInitialCapacity")
    final List<PgTrigger> list = new ArrayList<PgTrigger>();

    if (newTable != null) {
      if (oldTable == null) {
        list.addAll(newTable.getTriggers());
      } else {
        for (final PgTrigger newTrigger : newTable.getTriggers()) {
          if (!oldTable.getTriggers().contains(newTrigger)) {
            list.add(newTrigger);
          }
        }
      }
    }

    return list;
  }
コード例 #3
0
ファイル: PgDiffTriggers.java プロジェクト: Xatter/apgdiff
  /**
   * Outputs statements for trigger comments that have changed.
   *
   * @param writer writer
   * @param oldSchema old schema
   * @param newSchema new schema
   * @param searchPathHelper search path helper
   */
  public static void alterComments(
      final PrintWriter writer,
      final PgSchema oldSchema,
      final PgSchema newSchema,
      final SearchPathHelper searchPathHelper) {
    if (oldSchema == null) {
      return;
    }

    for (PgTable oldTable : oldSchema.getTables()) {
      final PgTable newTable = newSchema.getTable(oldTable.getName());

      if (newTable == null) {
        continue;
      }

      for (final PgTrigger oldTrigger : oldTable.getTriggers()) {
        final PgTrigger newTrigger = newTable.getTrigger(oldTrigger.getName());

        if (newTrigger == null) {
          continue;
        }

        if (oldTrigger.getComment() == null && newTrigger.getComment() != null
            || oldTrigger.getComment() != null
                && newTrigger.getComment() != null
                && !oldTrigger.getComment().equals(newTrigger.getComment())) {
          searchPathHelper.outputSearchPath(writer);
          writer.println();
          writer.print("COMMENT ON TRIGGER ");
          writer.print(PgDiffUtils.getQuotedName(newTrigger.getName()));
          writer.print(" ON ");
          writer.print(PgDiffUtils.getQuotedName(newTrigger.getTableName()));
          writer.print(" IS ");
          writer.print(newTrigger.getComment());
          writer.println(';');
        } else if (oldTrigger.getComment() != null && newTrigger.getComment() == null) {
          searchPathHelper.outputSearchPath(writer);
          writer.println();
          writer.print("COMMENT ON TRIGGER ");
          writer.print(PgDiffUtils.getQuotedName(newTrigger.getName()));
          writer.print(" ON ");
          writer.print(PgDiffUtils.getQuotedName(newTrigger.getTableName()));
          writer.println(" IS NULL;");
        }
      }
    }
  }