Ejemplo n.º 1
0
  /**
   * Implementation delegates logic to the {@link
   * liquibase.sqlgenerator.SqlGeneratorFactory#getAffectedDatabaseObjects(liquibase.statement.SqlStatement,
   * liquibase.database.Database)} method on the {@link SqlStatement} objects returned by {@link
   * #generateStatements } Returns empty set if change is not supported for the passed database
   */
  @Override
  public Set<DatabaseObject> getAffectedDatabaseObjects(Database database) {
    if (this.generateStatementsVolatile(database)) {
      return new HashSet<DatabaseObject>();
    }
    Set<DatabaseObject> affectedObjects = new HashSet<DatabaseObject>();
    SqlStatement[] statements = generateStatements(database);

    if (statements != null) {
      for (SqlStatement statement : statements) {
        affectedObjects.addAll(
            SqlGeneratorFactory.getInstance().getAffectedDatabaseObjects(statement, database));
      }
    }

    return affectedObjects;
  }
Ejemplo n.º 2
0
 @Override
 public void addReservedWords(Collection<String> words) {
   reservedWords.addAll(words);
 }
Ejemplo n.º 3
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));
    }
  }