use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.
the class CustomChangeWrapper method load.
@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
setClassLoader(resourceAccessor.toClassLoader());
try {
setClass(parsedNode.getChildValue(null, "class", String.class));
} catch (CustomChangeException e) {
throw new ParsedNodeException(e);
}
super.load(parsedNode, resourceAccessor);
}
use of liquibase.parser.core.ParsedNodeException 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"));
}
use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.
the class DatabaseSnapshot method load.
@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
try {
Map<String, DatabaseObject> referencedObjects = new HashMap<String, DatabaseObject>();
Map<String, DatabaseObject> objects = new HashMap<String, DatabaseObject>();
Map<String, DatabaseObject> allObjects = new HashMap<String, DatabaseObject>();
ParsedNode databaseNode = parsedNode.getChild(null, "database");
DatabaseConnection connection = getDatabase().getConnection();
if (databaseNode != null && connection instanceof OfflineConnection) {
((OfflineConnection) connection).setDatabaseMajorVersion(databaseNode.getChildValue(null, "majorVersion", Integer.class));
((OfflineConnection) connection).setDatabaseMinorVersion(databaseNode.getChildValue(null, "minorVersion", Integer.class));
((OfflineConnection) connection).setProductVersion(databaseNode.getChildValue(null, "productVersion", String.class));
((OfflineConnection) connection).setConnectionUserName(databaseNode.getChildValue(null, "user", String.class));
}
loadObjects(referencedObjects, allObjects, parsedNode.getChild(null, "referencedObjects"), resourceAccessor);
loadObjects(objects, allObjects, parsedNode.getChild(null, "objects"), resourceAccessor);
for (DatabaseObject object : allObjects.values()) {
for (String attr : new ArrayList<String>(object.getAttributes())) {
Object value = object.getAttribute(attr, Object.class);
if (value instanceof String && allObjects.containsKey(value)) {
if (ObjectUtil.hasProperty(object, attr)) {
ObjectUtil.setProperty(object, attr, allObjects.get(value));
} else {
object.setAttribute(attr, allObjects.get(value));
}
} else if (value instanceof Collection && ((Collection) value).size() > 0 && allObjects.containsKey(((Collection) value).iterator().next())) {
List newList = new ArrayList();
for (String element : (Collection<String>) value) {
newList.add(allObjects.get(element));
}
if (ObjectUtil.hasProperty(object, attr)) {
ObjectUtil.setProperty(object, attr, newList);
} else {
object.setAttribute(attr, newList);
}
} else {
if (value != null && ObjectUtil.hasProperty(object, attr)) {
if (value instanceof byte[] && ObjectUtil.getPropertyType(object, attr).equals(String.class)) {
value = new String((byte[]) value, LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
}
object.setAttribute(attr, null);
ObjectUtil.setProperty(object, attr, value);
}
}
}
}
for (DatabaseObject object : objects.values()) {
this.allFound.add(object);
}
for (DatabaseObject object : referencedObjects.values()) {
this.referencedObjects.add(object);
}
} catch (Exception e) {
throw new ParsedNodeException(e);
}
}
use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.
the class AbstractLiquibaseSerializable method load.
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
for (ParsedNode childNode : parsedNode.getChildren()) {
if (!shouldAutoLoad(childNode)) {
continue;
}
try {
if (this.getSerializableFields().contains(childNode.getName())) {
Class dataTypeClass = this.getSerializableFieldDataTypeClass(childNode.getName());
if (Collection.class.isAssignableFrom(dataTypeClass)) {
Type[] dataTypeClassParameters = getSerializableFieldDataTypeClassParameters(childNode.getName());
if (dataTypeClassParameters.length == 1) {
Class collectionType = null;
if (dataTypeClassParameters[0] instanceof Class) {
collectionType = (Class) dataTypeClassParameters[0];
} else if (dataTypeClassParameters[0] instanceof ParameterizedType) {
collectionType = (Class) ((ParameterizedType) dataTypeClassParameters[0]).getRawType();
}
if (collectionType != null && LiquibaseSerializable.class.isAssignableFrom(collectionType) && !collectionType.isInterface() && !Modifier.isAbstract(collectionType.getModifiers())) {
String elementName = ((LiquibaseSerializable) collectionType.newInstance()).getSerializedObjectName();
List<ParsedNode> elementNodes = Collections.emptyList();
if (childNode.getName().equals(elementName)) {
elementNodes = Collections.singletonList(childNode);
} else {
elementNodes = childNode.getChildren(null, elementName);
}
if (!elementNodes.isEmpty()) {
Collection collection = ((Collection) getSerializableFieldValue(childNode.getName()));
for (ParsedNode node : elementNodes) {
LiquibaseSerializable childObject = (LiquibaseSerializable) collectionType.newInstance();
childObject.load(node, resourceAccessor);
collection.add(childObject);
}
}
}
}
}
if (LiquibaseSerializable.class.isAssignableFrom(dataTypeClass)) {
if (!dataTypeClass.isInterface() && !Modifier.isAbstract(dataTypeClass.getModifiers())) {
LiquibaseSerializable childObject = (LiquibaseSerializable) dataTypeClass.newInstance();
childObject.load(childNode, resourceAccessor);
setSerializableFieldValue(childNode.getName(), childObject);
}
} else if (childNode.getValue() != null) {
ObjectUtil.setProperty(this, childNode.getName(), convertEscaped(childNode.getValue().toString()));
}
} else {
for (String field : this.getSerializableFields()) {
Class dataTypeClass = this.getSerializableFieldDataTypeClass(field);
if (Collection.class.isAssignableFrom(dataTypeClass)) {
Type[] dataTypeClassParameters = getSerializableFieldDataTypeClassParameters(field);
if (dataTypeClassParameters.length == 1) {
Class collectionType = null;
if (dataTypeClassParameters[0] instanceof Class) {
collectionType = (Class) dataTypeClassParameters[0];
} else if (dataTypeClassParameters[0] instanceof ParameterizedType) {
collectionType = (Class) ((ParameterizedType) dataTypeClassParameters[0]).getRawType();
}
if (collectionType != null && LiquibaseSerializable.class.isAssignableFrom(collectionType) && !collectionType.isInterface() && !Modifier.isAbstract(collectionType.getModifiers())) {
String elementName = ((LiquibaseSerializable) collectionType.newInstance()).getSerializedObjectName();
List<ParsedNode> elementNodes = Collections.emptyList();
if (childNode.getName().equals(elementName)) {
elementNodes = Collections.singletonList(childNode);
} else if (childNode.getName().equals(field)) {
elementNodes = childNode.getChildren(null, elementName);
}
if (!elementNodes.isEmpty()) {
Collection collection = ((Collection) getSerializableFieldValue(field));
for (ParsedNode node : elementNodes) {
LiquibaseSerializable childObject = (LiquibaseSerializable) collectionType.newInstance();
childObject.load(node, resourceAccessor);
collection.add(childObject);
}
}
}
}
}
}
}
} catch (Exception e) {
throw new ParsedNodeException("Error setting property", e);
}
}
if (parsedNode.getValue() != null) {
for (String field : this.getSerializableFields()) {
SerializationType type = this.getSerializableFieldType(field);
if (type == SerializationType.DIRECT_VALUE) {
Object value = parsedNode.getValue(String.class);
value = convertEscaped(value);
ObjectUtil.setProperty(this, field, value);
} else if (type == SerializationType.NAMED_FIELD) {
Object value = parsedNode.getChildValue(null, field, Object.class);
value = convertEscaped(value);
ObjectUtil.setProperty(this, field, value);
}
}
}
}
Aggregations