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