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);
}
}
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);
}
}
}
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);
}
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;
}
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);
}
}
}
Aggregations