Search in sources :

Example 6 with ISODateFormat

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);
        }
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) Matcher(java.util.regex.Matcher) ParsedNodeException(liquibase.parser.core.ParsedNodeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParseException(java.text.ParseException) ISODateFormat(liquibase.util.ISODateFormat) Column(liquibase.structure.core.Column) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

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

Example 8 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 9 with ISODateFormat

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);
    }
}
Also used : ISODateFormat(liquibase.util.ISODateFormat) Table(liquibase.structure.core.Table) Column(liquibase.structure.core.Column) Date(java.util.Date) ParseException(java.text.ParseException)

Example 10 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) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Aggregations

ISODateFormat (liquibase.util.ISODateFormat)10 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)5 ParseException (java.text.ParseException)4 Date (java.util.Date)3 GlobalConfiguration (liquibase.configuration.GlobalConfiguration)2 DatabaseException (liquibase.exception.DatabaseException)2 LiquibaseException (liquibase.exception.LiquibaseException)2 DatabaseObject (liquibase.structure.DatabaseObject)2 CSVReader (liquibase.util.csv.CSVReader)2 CSVWriter (liquibase.util.csv.CSVWriter)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1