Search in sources :

Example 11 with ISODateFormat

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;
}
Also used : ISODateFormat(liquibase.util.ISODateFormat) Matcher(java.util.regex.Matcher) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 12 with ISODateFormat

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);
    }
}
Also used : ISODateFormat(liquibase.util.ISODateFormat) DatabaseObject(liquibase.structure.DatabaseObject) Timestamp(java.sql.Timestamp) DatabaseException(liquibase.exception.DatabaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 13 with ISODateFormat

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 + "'";
}
Also used : ISODateFormat(liquibase.util.ISODateFormat) SimpleDateFormat(java.text.SimpleDateFormat) ISODateFormat(liquibase.util.ISODateFormat) DateFormat(java.text.DateFormat) DateParseException(liquibase.exception.DateParseException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with ISODateFormat

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);
    }
}
Also used : ISODateFormat(liquibase.util.ISODateFormat) MarkChangeSetRanStatement(liquibase.statement.core.MarkChangeSetRanStatement) Date(java.util.Date)

Aggregations

ISODateFormat (liquibase.util.ISODateFormat)14 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)6 Date (java.util.Date)5 ParseException (java.text.ParseException)4 DatabaseException (liquibase.exception.DatabaseException)3 DatabaseObject (liquibase.structure.DatabaseObject)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Change (liquibase.change.Change)2 LiquibaseException (liquibase.exception.LiquibaseException)2 ParsedNodeException (liquibase.parser.core.ParsedNodeException)2 CSVReader (liquibase.util.csv.CSVReader)2 CSVWriter (liquibase.util.csv.CSVWriter)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Timestamp (java.sql.Timestamp)1