Search in sources :

Example 1 with ParsedNode

use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.

the class CustomChangeWrapper method customLoadLogic.

@Override
public void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    ParsedNode paramsNode = parsedNode.getChild(null, "params");
    if (paramsNode == null) {
        paramsNode = parsedNode;
    }
    for (ParsedNode child : paramsNode.getChildren(null, "param")) {
        Object value = child.getValue();
        if (value == null) {
            value = child.getChildValue(null, "value");
        }
        if (value != null) {
            value = value.toString();
        }
        this.setParam(child.getChildValue(null, "name", String.class), (String) value);
    }
    CustomChange customChange = null;
    try {
        customChange = (CustomChange) Class.forName(className, false, resourceAccessor.toClassLoader()).newInstance();
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
    for (ParsedNode node : parsedNode.getChildren()) {
        Object value = node.getValue();
        if (value != null && ObjectUtil.hasProperty(customChange, node.getName())) {
            this.setParam(node.getName(), value.toString());
        }
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException)

Example 2 with ParsedNode

use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.

the class ChangeSet method load.

@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);
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ContextExpression(liquibase.ContextExpression) Labels(liquibase.Labels)

Example 3 with ParsedNode

use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.

the class ChangeSet method handleRollbackNode.

protected void handleRollbackNode(ParsedNode rollbackNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    String changeSetId = rollbackNode.getChildValue(null, "changeSetId", String.class);
    if (changeSetId != null) {
        String changeSetAuthor = rollbackNode.getChildValue(null, "changeSetAuthor", String.class);
        String changeSetPath = rollbackNode.getChildValue(null, "changeSetPath", getFilePath());
        DatabaseChangeLog changeLog = this.getChangeLog();
        ChangeSet changeSet = changeLog.getChangeSet(changeSetPath, changeSetAuthor, changeSetId);
        while (changeSet == null && changeLog != null) {
            changeLog = changeLog.getParentChangeLog();
            if (changeLog != null) {
                changeSet = changeLog.getChangeSet(changeSetPath, changeSetAuthor, changeSetId);
            }
        }
        if (changeSet == null) {
            throw new ParsedNodeException("Change set " + new ChangeSet(changeSetId, changeSetAuthor, false, false, changeSetPath, null, null, null).toString(false) + " does not exist");
        }
        for (Change change : changeSet.getChanges()) {
            rollback.getChanges().add(change);
        }
        return;
    }
    boolean foundValue = false;
    for (ParsedNode childNode : rollbackNode.getChildren()) {
        Change rollbackChange = toChange(childNode, resourceAccessor);
        if (rollbackChange != null) {
            addRollbackChange(rollbackChange);
            foundValue = true;
        }
    }
    Object value = rollbackNode.getValue();
    if (value != null) {
        if (value instanceof String) {
            String finalValue = StringUtils.trimToNull((String) value);
            if (finalValue != null) {
                String[] strings = StringUtils.processMutliLineSQL(finalValue, true, true, ";");
                for (String string : strings) {
                    addRollbackChange(new RawSQLChange(string));
                    foundValue = true;
                }
            }
        } else {
            throw new ParsedNodeException("Unexpected object: " + value.getClass().getName() + " '" + value.toString() + "'");
        }
    }
    if (!foundValue) {
        addRollbackChange(new EmptyChange());
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) RawSQLChange(liquibase.change.core.RawSQLChange) ParsedNodeException(liquibase.parser.core.ParsedNodeException) Change(liquibase.change.Change) EmptyChange(liquibase.change.core.EmptyChange) RawSQLChange(liquibase.change.core.RawSQLChange) DbmsTargetedChange(liquibase.change.DbmsTargetedChange) EmptyChange(liquibase.change.core.EmptyChange)

Example 4 with ParsedNode

use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.

the class DatabaseChangeLog method expandExpressions.

protected void expandExpressions(ParsedNode parsedNode) {
    if (changeLogParameters == null) {
        return;
    }
    try {
        Object value = parsedNode.getValue();
        if (value != null && value instanceof String) {
            parsedNode.setValue(changeLogParameters.expandExpressions(parsedNode.getValue(String.class), this));
        }
        List<ParsedNode> children = parsedNode.getChildren();
        if (children != null) {
            for (ParsedNode child : children) {
                expandExpressions(child);
            }
        }
    } catch (ParsedNodeException e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 5 with ParsedNode

use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.

the class DatabaseChangeLog method load.

public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException, SetupException {
    setLogicalFilePath(parsedNode.getChildValue(null, "logicalFilePath", String.class));
    setContexts(new ContextExpression(parsedNode.getChildValue(null, "context", String.class)));
    String objectQuotingStrategy = parsedNode.getChildValue(null, "objectQuotingStrategy", String.class);
    if (objectQuotingStrategy != null) {
        setObjectQuotingStrategy(ObjectQuotingStrategy.valueOf(objectQuotingStrategy));
    }
    for (ParsedNode childNode : parsedNode.getChildren()) {
        handleChildNode(childNode, resourceAccessor);
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ContextExpression(liquibase.ContextExpression)

Aggregations

ParsedNode (liquibase.parser.core.ParsedNode)23 ParsedNodeException (liquibase.parser.core.ParsedNodeException)12 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)5 ContextExpression (liquibase.ContextExpression)4 DatabaseObject (liquibase.structure.DatabaseObject)4 Labels (liquibase.Labels)3 InputStream (java.io.InputStream)2 ParseException (java.text.ParseException)2 Change (liquibase.change.Change)2 DbmsTargetedChange (liquibase.change.DbmsTargetedChange)2 EmptyChange (liquibase.change.core.EmptyChange)2 RawSQLChange (liquibase.change.core.RawSQLChange)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 ChangeLogParseException (liquibase.exception.ChangeLogParseException)2 Yaml (org.yaml.snakeyaml.Yaml)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1