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;
}
use of liquibase.util.ISODateFormat in project liquibase by liquibase.
the class DatabaseSnapshot method getSerializableFieldValue.
@Override
public Object getSerializableFieldValue(String field) {
switch(field) {
case "snapshotControl":
return snapshotControl;
case "objects":
return allFound;
case "referencedObjects":
return referencedObjects;
case "metadata":
return metadata;
case "created":
return new ISODateFormat().format(new Timestamp(new Date().getTime()));
case "database":
Map<String, Object> map = new HashMap<>();
map.put("shortName", database.getShortName());
map.put("productName", database.getDatabaseProductName());
map.put("url", database.getConnection().getURL());
try {
map.put("majorVersion", String.valueOf(database.getDatabaseMajorVersion()));
map.put("minorVersion", String.valueOf(database.getDatabaseMinorVersion()));
map.put("productVersion", database.getDatabaseProductVersion());
map.put("user", database.getConnection().getConnectionUserName());
} catch (DatabaseException e) {
// ok
}
return map;
default:
throw new UnexpectedLiquibaseException("Unknown field: " + field);
}
}
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 OfflineChangeLogHistoryService method setExecType.
@Override
public void setExecType(final ChangeSet changeSet, final ChangeSet.ExecType execType) throws DatabaseException {
if (isExecuteDmlAgainstDatabase()) {
Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", 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[Columns.DATEEXECUTED.ordinal()] = new ISODateFormat().format(new java.sql.Timestamp(new Date().getTime()));
line[Columns.MD5SUM.ordinal()] = changeSet.generateCheckSum().toString();
line[Columns.EXECTYPE.ordinal()] = execType.value;
return line;
}
});
} else {
appendChangeSet(changeSet, execType);
}
}
Aggregations