Search in sources :

Example 6 with ParsedNode

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

the class XMLChangeLogSAXHandler method startElement.

@Override
public void startElement(String uri, String localName, String qualifiedName, Attributes attributes) throws SAXException {
    ParsedNode node = new ParsedNode(null, localName);
    try {
        if (attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                try {
                    node.addChild(null, attributes.getLocalName(i), attributes.getValue(i));
                } catch (NullPointerException e) {
                    throw e;
                }
            }
        }
        if (!nodeStack.isEmpty()) {
            nodeStack.peek().addChild(node);
        }
        if (nodeStack.isEmpty()) {
            databaseChangeLogTree = node;
        }
        nodeStack.push(node);
        textStack.push(new StringBuffer());
    } catch (ParsedNodeException e) {
        throw new SAXException(e);
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException) SAXException(org.xml.sax.SAXException)

Example 7 with ParsedNode

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

the class DeleteDataChange method customLoadLogic.

@Override
protected void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    ParsedNode whereParams = parsedNode.getChild(null, "whereParams");
    if (whereParams != null) {
        for (ParsedNode param : whereParams.getChildren(null, "param")) {
            ColumnConfig columnConfig = new ColumnConfig();
            try {
                columnConfig.load(param, resourceAccessor);
            } catch (ParsedNodeException e) {
                e.printStackTrace();
            }
            addWhereParam(columnConfig);
        }
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException)

Example 8 with ParsedNode

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

the class CustomPreconditionWrapper method load.

@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    setClassLoader(resourceAccessor.toClassLoader());
    setClassName(parsedNode.getChildValue(null, "className", String.class));
    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);
    }
    super.load(parsedNode, resourceAccessor);
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode)

Example 9 with ParsedNode

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

the class AbstractLiquibaseSerializable method serialize.

@Override
public ParsedNode serialize() throws ParsedNodeException {
    ParsedNode node = new ParsedNode(null, getSerializedObjectName());
    for (String field : getSerializableFields()) {
        Object fieldValue = getSerializableFieldValue(field);
        fieldValue = serializeValue(fieldValue);
        if (fieldValue == null) {
            continue;
        }
        SerializationType type = getSerializableFieldType(field);
        if (type == SerializationType.DIRECT_VALUE) {
            node.setValue(fieldValue);
        } else if (type == SerializationType.NAMED_FIELD || type == SerializationType.NESTED_OBJECT) {
            if (fieldValue instanceof ParsedNode) {
                node.addChild((ParsedNode) fieldValue);
            } else {
                node.addChild(new ParsedNode(null, field).setValue(fieldValue));
            }
        } else {
            throw new UnexpectedLiquibaseException("Unknown type: " + type);
        }
    }
    return node;
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 10 with ParsedNode

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

the class AbstractDatabaseObject method load.

@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    for (ParsedNode child : parsedNode.getChildren()) {
        String name = child.getName();
        if (name.equals("snapshotId")) {
            this.snapshotId = child.getValue(String.class);
            continue;
        }
        Class propertyType = ObjectUtil.getPropertyType(this, name);
        if (propertyType != null && Collection.class.isAssignableFrom(propertyType) && !(child.getValue() instanceof Collection)) {
            if (this.attributes.get(name) == null) {
                this.setAttribute(name, new ArrayList<Column>());
            }
            this.getAttribute(name, List.class).add(child.getValue());
        } else {
            Object childValue = child.getValue();
            if (childValue != null && childValue instanceof String) {
                Matcher matcher = Pattern.compile("(.*)!\\{(.*)\\}").matcher((String) childValue);
                if (matcher.matches()) {
                    String stringValue = matcher.group(1);
                    try {
                        Class<?> aClass = Class.forName(matcher.group(2));
                        if (Date.class.isAssignableFrom(aClass)) {
                            Date date = new ISODateFormat().parse(stringValue);
                            childValue = aClass.getConstructor(long.class).newInstance(date.getTime());
                        } else if (Enum.class.isAssignableFrom(aClass)) {
                            childValue = Enum.valueOf((Class<? extends Enum>) aClass, stringValue);
                        } else {
                            childValue = aClass.getConstructor(String.class).newInstance(stringValue);
                        }
                    } catch (Exception e) {
                        throw new UnexpectedLiquibaseException(e);
                    }
                }
            }
            this.attributes.put(name, childValue);
        }
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) Matcher(java.util.regex.Matcher) ParsedNodeException(liquibase.parser.core.ParsedNodeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParseException(java.text.ParseException) ISODateFormat(liquibase.util.ISODateFormat) Column(liquibase.structure.core.Column) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

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