use of liquibase.util.ISODateFormat 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);
}
}
}
use of liquibase.util.ISODateFormat in project liquibase by liquibase.
the class OfflineChangeLogHistoryService method setExecType.
@Override
public void setExecType(final ChangeSet changeSet, final ChangeSet.ExecType execType) throws DatabaseException {
if (isExecuteDmlAgainstDatabase()) {
ExecutorService.getInstance().getExecutor(getDatabase()).execute(new MarkChangeSetRanStatement(changeSet, execType));
getDatabase().commit();
}
if (execType.equals(ChangeSet.ExecType.FAILED) || execType.equals(ChangeSet.ExecType.SKIPPED)) {
//do nothing
return;
} else if (execType.ranBefore) {
replaceChangeSet(changeSet, new ReplaceChangeSetLogic() {
@Override
public String[] execute(String[] line) {
line[COLUMN_DATEEXECUTED] = new ISODateFormat().format(new java.sql.Timestamp(new Date().getTime()));
line[COLUMN_MD5SUM] = changeSet.generateCheckSum().toString();
line[COLUMN_EXECTYPE] = execType.value;
return line;
}
});
} else {
appendChangeSet(changeSet, execType);
}
}
use of liquibase.util.ISODateFormat in project liquibase by liquibase.
the class HsqlDatabase method getDateLiteral.
@Override
public String getDateLiteral(String isoDate) {
String returnString = isoDate;
try {
if (isDateTime(isoDate)) {
ISODateFormat isoTimestampFormat = new ISODateFormat();
DateFormat dbTimestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
returnString = dbTimestampFormat.format(isoTimestampFormat.parse(isoDate));
}
} catch (ParseException e) {
throw new RuntimeException("Unexpected date format: " + isoDate, e);
}
return "'" + returnString + "'";
}
use of liquibase.util.ISODateFormat in project liquibase by liquibase.
the class AddDefaultValueChange method checkStatus.
@Override
public ChangeStatus checkStatus(Database database) {
ChangeStatus result = new ChangeStatus();
try {
Column column = SnapshotGeneratorFactory.getInstance().createSnapshot(new Column(Table.class, getCatalogName(), getSchemaName(), getTableName(), getColumnName()), database);
if (column == null) {
return result.unknown("Column " + getColumnName() + " does not exist");
}
result.assertComplete(column.getDefaultValue() != null, "Column " + getColumnName() + " has no default value");
if (column.getDefaultValue() == null) {
return result;
}
if (getDefaultValue() != null) {
return result.assertCorrect(getDefaultValue().equals(column.getDefaultValue()), "Default value was " + column.getDefaultValue());
} else if (getDefaultValueDate() != null) {
return result.assertCorrect(getDefaultValueDate().equals(new ISODateFormat().format((Date) column.getDefaultValue())), "Default value was " + column.getDefaultValue());
} else if (getDefaultValueNumeric() != null) {
return result.assertCorrect(getDefaultValueNumeric().equals(column.getDefaultValue().toString()), "Default value was " + column.getDefaultValue());
} else if (getDefaultValueBoolean() != null) {
return result.assertCorrect(getDefaultValueBoolean().equals(column.getDefaultValue()), "Default value was " + column.getDefaultValue());
} else if (getDefaultValueComputed() != null) {
return result.assertCorrect(getDefaultValueComputed().equals(column.getDefaultValue()), "Default value was " + column.getDefaultValue());
} else if (getDefaultValueSequenceNext() != null) {
return result.assertCorrect(getDefaultValueSequenceNext().equals(column.getDefaultValue()), "Default value was " + column.getDefaultValue());
} else {
return result.unknown("Unknown default value type");
}
} catch (Exception e) {
return result.unknown(e);
}
}
use of liquibase.util.ISODateFormat in project liquibase by liquibase.
the class AbstractLiquibaseSerializable method convertEscaped.
protected Object convertEscaped(Object value) {
if (value == null) {
return null;
}
Matcher matcher = Pattern.compile("(.*)!\\{(.*)\\}").matcher((String) value);
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);
value = aClass.getConstructor(long.class).newInstance(date.getTime());
} else if (Enum.class.isAssignableFrom(aClass)) {
value = Enum.valueOf((Class<? extends Enum>) aClass, stringValue);
} else {
value = aClass.getConstructor(String.class).newInstance(stringValue);
}
} catch (Exception e) {
throw new UnexpectedLiquibaseException(e);
}
}
return value;
}
Aggregations