Пример #1
0
  /**
   * Takes a list of SqlVisitors and returns a new list with only the SqlVisitors set to apply to
   * rollbacks
   */
  protected List<SqlVisitor> filterRollbackVisitors(final List<SqlVisitor> visitors) {
    final List<SqlVisitor> rollbackVisitors = new ArrayList<SqlVisitor>();
    if (visitors != null) {
      for (SqlVisitor visitor : visitors) {
        if (visitor.isApplyToRollback()) {
          rollbackVisitors.add(visitor);
        }
      }
    }

    return rollbackVisitors;
  }
Пример #2
0
  public CheckSum generateCheckSum() {
    StringBuffer stringToMD5 = new StringBuffer();
    for (Change change : getChanges()) {
      stringToMD5.append(change.generateCheckSum()).append(":");
    }

    for (SqlVisitor visitor : this.getSqlVisitors()) {
      stringToMD5.append(visitor.generateCheckSum()).append(";");
    }

    return CheckSum.compute(stringToMD5.toString());
  }
Пример #3
0
 @Override
 public void executeRollbackStatements(Change change, List<SqlVisitor> sqlVisitors)
     throws LiquibaseException, UnsupportedChangeException, RollbackImpossibleException {
   SqlStatement[] statements = change.generateRollbackStatements(this);
   List<SqlVisitor> rollbackVisitors = new ArrayList<SqlVisitor>();
   if (sqlVisitors != null) {
     for (SqlVisitor visitor : sqlVisitors) {
       if (visitor.isApplyToRollback()) {
         rollbackVisitors.add(visitor);
       }
     }
   }
   execute(statements, rollbackVisitors);
 }
Пример #4
0
  protected void handleChildNode(ParsedNode child, ResourceAccessor resourceAccessor)
      throws ParsedNodeException {
    if (child.getName().equals("rollback")) {
      handleRollbackNode(child, resourceAccessor);
    } else if (child.getName().equals("validCheckSum")
        || child.getName().equals("validCheckSums")) {
      if (child.getValue() == null) {
        return;
      }

      if (child.getValue() instanceof Collection) {
        for (Object checksum : (Collection) child.getValue()) {
          addValidCheckSum((String) checksum);
        }
      } else {
        addValidCheckSum(child.getValue(String.class));
      }
    } else if (child.getName().equals("modifySql")) {
      String dbmsString = StringUtils.trimToNull(child.getChildValue(null, "dbms", String.class));
      String contextString =
          StringUtils.trimToNull(child.getChildValue(null, "context", String.class));
      String labelsString =
          StringUtils.trimToNull(child.getChildValue(null, "labels", String.class));
      boolean applyToRollback = child.getChildValue(null, "applyToRollback", false);

      Set<String> dbms = new HashSet<String>();
      if (dbmsString != null) {
        dbms.addAll(StringUtils.splitAndTrim(dbmsString, ","));
      }
      ContextExpression context = null;
      if (contextString != null) {
        context = new ContextExpression(contextString);
      }

      Labels labels = null;
      if (labelsString != null) {
        labels = new Labels(labelsString);
      }

      List<ParsedNode> potentialVisitors = child.getChildren();
      for (ParsedNode node : potentialVisitors) {
        SqlVisitor sqlVisitor = SqlVisitorFactory.getInstance().create(node.getName());
        if (sqlVisitor != null) {
          sqlVisitor.setApplyToRollback(applyToRollback);
          if (dbms.size() > 0) {
            sqlVisitor.setApplicableDbms(dbms);
          }
          sqlVisitor.setContexts(context);
          sqlVisitor.setLabels(labels);
          sqlVisitor.load(node, resourceAccessor);

          addSqlVisitor(sqlVisitor);
        }
      }

    } else if (child.getName().equals("preConditions")) {
      this.preconditions = new PreconditionContainer();
      try {
        this.preconditions.load(child, resourceAccessor);
      } catch (ParsedNodeException e) {
        e.printStackTrace();
      }
    } else if (child.getName().equals("changes")) {
      for (ParsedNode changeNode : child.getChildren()) {
        handleChildNode(changeNode, resourceAccessor);
      }
    } else {
      addChange(toChange(child, resourceAccessor));
    }
  }