use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.
the class ChangeSet method handleChildNode.
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 {
Change change = toChange(child, resourceAccessor);
if (change == null && child.getValue() instanceof String) {
this.setAttribute(child.getName(), child.getValue());
} else {
addChange(change);
}
}
}
use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.
the class AbstractChange method serialize.
@Override
public ParsedNode serialize() throws ParsedNodeException {
ParsedNode node = new ParsedNode(null, getSerializedObjectName());
ChangeMetaData metaData = ChangeFactory.getInstance().getChangeMetaData(this);
for (ChangeParameterMetaData param : metaData.getSetParameters(this).values()) {
Object currentValue = param.getCurrentValue(this);
currentValue = serializeValue(currentValue);
if (currentValue != null) {
node.addChild(null, param.getParameterName(), currentValue);
}
}
return node;
}
use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.
the class AbstractChange method load.
@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
ChangeMetaData metaData = ChangeFactory.getInstance().getChangeMetaData(this);
this.setResourceAccessor(resourceAccessor);
try {
Collection<ChangeParameterMetaData> changeParameters = metaData.getParameters().values();
for (ChangeParameterMetaData param : changeParameters) {
if (Collection.class.isAssignableFrom(param.getDataTypeClass())) {
if (param.getDataTypeClassParameters().length == 1) {
Class collectionType = (Class) param.getDataTypeClassParameters()[0];
if (ColumnConfig.class.isAssignableFrom(collectionType)) {
List<ParsedNode> columnNodes = new ArrayList<ParsedNode>(parsedNode.getChildren(null, param.getParameterName()));
columnNodes.addAll(parsedNode.getChildren(null, "column"));
Object nodeValue = parsedNode.getValue();
if (nodeValue instanceof ParsedNode) {
columnNodes.add((ParsedNode) nodeValue);
} else if (nodeValue instanceof Collection) {
for (Object nodeValueChild : ((Collection) nodeValue)) {
if (nodeValueChild instanceof ParsedNode) {
columnNodes.add((ParsedNode) nodeValueChild);
}
}
}
for (ParsedNode child : columnNodes) {
if (child.getName().equals("column") || child.getName().equals("columns")) {
List<ParsedNode> columnChildren = child.getChildren(null, "column");
if (columnChildren != null && columnChildren.size() > 0) {
for (ParsedNode columnChild : columnChildren) {
ColumnConfig columnConfig = createEmptyColumnConfig(collectionType);
columnConfig.load(columnChild, resourceAccessor);
((ChangeWithColumns) this).addColumn(columnConfig);
}
} else {
ColumnConfig columnConfig = createEmptyColumnConfig(collectionType);
columnConfig.load(child, resourceAccessor);
((ChangeWithColumns) this).addColumn(columnConfig);
}
}
}
} else if (LiquibaseSerializable.class.isAssignableFrom(collectionType)) {
if (!collectionType.isInterface() && !Modifier.isAbstract(collectionType.getModifiers())) {
String elementName = ((LiquibaseSerializable) collectionType.newInstance()).getSerializedObjectName();
List<ParsedNode> nodes = new ArrayList<ParsedNode>(parsedNode.getChildren(null, param.getParameterName()));
if (!elementName.equals(param.getParameterName())) {
nodes.addAll(parsedNode.getChildren(null, elementName));
}
Object nodeValue = parsedNode.getValue();
if (nodeValue instanceof ParsedNode) {
nodes.add((ParsedNode) nodeValue);
} else if (nodeValue instanceof Collection) {
for (Object nodeValueChild : ((Collection) nodeValue)) {
if (nodeValueChild instanceof ParsedNode) {
nodes.add((ParsedNode) nodeValueChild);
}
}
}
for (ParsedNode node : nodes) {
if (node.getName().equals(elementName) || node.getName().equals(param.getParameterName())) {
List<ParsedNode> childNodes = node.getChildren(null, elementName);
if (childNodes != null && childNodes.size() > 0) {
for (ParsedNode childNode : childNodes) {
LiquibaseSerializable childObject = (LiquibaseSerializable) collectionType.newInstance();
childObject.load(childNode, resourceAccessor);
((Collection) param.getCurrentValue(this)).add(childObject);
}
} else {
LiquibaseSerializable childObject = (LiquibaseSerializable) collectionType.newInstance();
childObject.load(node, resourceAccessor);
((Collection) param.getCurrentValue(this)).add(childObject);
}
}
}
}
}
}
} else if (LiquibaseSerializable.class.isAssignableFrom(param.getDataTypeClass())) {
if (!param.getDataTypeClass().isInterface() && !Modifier.isAbstract(param.getDataTypeClass().getModifiers())) {
try {
ParsedNode child = parsedNode.getChild(null, param.getParameterName());
if (child != null) {
LiquibaseSerializable serializableChild = (LiquibaseSerializable) param.getDataTypeClass().newInstance();
serializableChild.load(child, resourceAccessor);
param.setValue(this, serializableChild);
}
} catch (InstantiationException e) {
throw new UnexpectedLiquibaseException(e);
} catch (IllegalAccessException e) {
throw new UnexpectedLiquibaseException(e);
}
}
} else {
Object childValue = parsedNode.getChildValue(null, param.getParameterName(), param.getDataTypeClass());
if (childValue == null && param.getSerializationType() == SerializationType.DIRECT_VALUE) {
childValue = parsedNode.getValue();
}
param.setValue(this, childValue);
}
}
} catch (InstantiationException e) {
throw new UnexpectedLiquibaseException(e);
} catch (IllegalAccessException e) {
throw new UnexpectedLiquibaseException(e);
}
customLoadLogic(parsedNode, resourceAccessor);
try {
this.finishInitialization();
} catch (SetupException e) {
throw new ParsedNodeException(e);
}
}
use of liquibase.parser.core.ParsedNode in project liquibase by liquibase.
the class UpdateDataChange 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 ColumnConfig method load.
@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
for (ParsedNode child : parsedNode.getChildren()) {
if (!ObjectUtil.hasProperty(this, child.getName())) {
throw new ParsedNodeException("Unexpected node: " + child.getName());
}
}
name = parsedNode.getChildValue(null, "name", String.class);
computed = parsedNode.getChildValue(null, "computed", Boolean.class);
type = parsedNode.getChildValue(null, "type", String.class);
encoding = parsedNode.getChildValue(null, "encoding", String.class);
autoIncrement = parsedNode.getChildValue(null, "autoIncrement", Boolean.class);
startWith = parsedNode.getChildValue(null, "startWith", BigInteger.class);
incrementBy = parsedNode.getChildValue(null, "incrementBy", BigInteger.class);
remarks = parsedNode.getChildValue(null, "remarks", String.class);
descending = parsedNode.getChildValue(null, "descending", Boolean.class);
value = parsedNode.getChildValue(null, "value", String.class);
if (value == null) {
value = StringUtils.trimToNull((String) parsedNode.getValue());
}
setValueNumeric(parsedNode.getChildValue(null, "valueNumeric", String.class));
try {
valueDate = parsedNode.getChildValue(null, "valueDate", Date.class);
} catch (ParsedNodeException e) {
valueComputed = new DatabaseFunction(parsedNode.getChildValue(null, "valueDate", String.class));
}
valueBoolean = parsedNode.getChildValue(null, "valueBoolean", Boolean.class);
valueBlobFile = parsedNode.getChildValue(null, "valueBlobFile", String.class);
valueClobFile = parsedNode.getChildValue(null, "valueClobFile", String.class);
String valueComputedString = parsedNode.getChildValue(null, "valueComputed", String.class);
if (valueComputedString != null) {
valueComputed = new DatabaseFunction(valueComputedString);
}
String valueSequenceNextString = parsedNode.getChildValue(null, "valueSequenceNext", String.class);
if (valueSequenceNextString != null) {
valueSequenceNext = new SequenceNextValueFunction(valueSequenceNextString);
}
String valueSequenceCurrentString = parsedNode.getChildValue(null, "valueSequenceCurrent", String.class);
if (valueSequenceCurrentString != null) {
valueSequenceCurrent = new SequenceCurrentValueFunction(valueSequenceCurrentString);
}
defaultValueConstraintName = parsedNode.getChildValue(null, "defaultValueConstraintName", String.class);
defaultValue = parsedNode.getChildValue(null, "defaultValue", String.class);
setDefaultValueNumeric(parsedNode.getChildValue(null, "defaultValueNumeric", String.class));
try {
defaultValueDate = parsedNode.getChildValue(null, "defaultValueDate", Date.class);
} catch (ParsedNodeException e) {
defaultValueComputed = new DatabaseFunction(parsedNode.getChildValue(null, "defaultValueDate", String.class));
}
defaultValueBoolean = parsedNode.getChildValue(null, "defaultValueBoolean", Boolean.class);
String defaultValueComputedString = parsedNode.getChildValue(null, "defaultValueComputed", String.class);
if (defaultValueComputedString != null) {
defaultValueComputed = new DatabaseFunction(defaultValueComputedString);
}
String defaultValueSequenceNextString = parsedNode.getChildValue(null, "defaultValueSequenceNext", String.class);
if (defaultValueSequenceNextString != null) {
defaultValueSequenceNext = new SequenceNextValueFunction(defaultValueSequenceNextString);
}
loadConstraints(parsedNode.getChild(null, "constraints"));
}
Aggregations