Esempio n. 1
0
  @Override
  public void load(ParsedNode node, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    this.id = node.getChildValue(null, "id", String.class);
    this.author = node.getChildValue(null, "author", String.class);
    this.alwaysRun =
        node.getChildValue(null, "runAlways", node.getChildValue(null, "alwaysRun", false));
    this.runOnChange = node.getChildValue(null, "runOnChange", false);
    this.contexts = new ContextExpression(node.getChildValue(null, "context", String.class));
    this.labels =
        new Labels(StringUtils.trimToNull(node.getChildValue(null, "labels", String.class)));
    setDbms(node.getChildValue(null, "dbms", String.class));
    this.runInTransaction = node.getChildValue(null, "runInTransaction", true);
    this.created = node.getChildValue(null, "created", String.class);
    this.runOrder = node.getChildValue(null, "runOrder", String.class);
    this.comments =
        StringUtils.join(
            node.getChildren(null, "comment"),
            "\n",
            new StringUtils.StringUtilsFormatter() {
              @Override
              public String toString(Object obj) {
                if (((ParsedNode) obj).getValue() == null) {
                  return "";
                } else {
                  return ((ParsedNode) obj).getValue().toString();
                }
              }
            });
    this.comments = StringUtils.trimToNull(this.comments);

    String objectQuotingStrategyString =
        StringUtils.trimToNull(node.getChildValue(null, "objectQuotingStrategy", String.class));
    if (changeLog != null) {
      this.objectQuotingStrategy = changeLog.getObjectQuotingStrategy();
    }
    if (objectQuotingStrategyString != null) {
      this.objectQuotingStrategy = ObjectQuotingStrategy.valueOf(objectQuotingStrategyString);
    }

    if (this.objectQuotingStrategy == null) {
      this.objectQuotingStrategy = ObjectQuotingStrategy.LEGACY;
    }

    this.filePath =
        StringUtils.trimToNull(node.getChildValue(null, "logicalFilePath", String.class));
    if (filePath == null) {
      filePath = changeLog.getFilePath();
    }

    this.setFailOnError(node.getChildValue(null, "failOnError", Boolean.class));
    String onValidationFailString = node.getChildValue(null, "onValidationFail", "HALT");
    this.setOnValidationFail(ValidationFailOption.valueOf(onValidationFailString));

    for (ParsedNode child : node.getChildren()) {
      handleChildNode(child, resourceAccessor);
    }
  }
Esempio n. 2
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));
    }
  }