Search in sources :

Example 1 with SequenceCurrentValueFunction

use of liquibase.statement.SequenceCurrentValueFunction in project liquibase by liquibase.

the class ObjectUtil method setProperty.

public static void setProperty(Object object, String propertyName, String propertyValue) {
    Method method = getWriteMethod(object, propertyName);
    if (method == null) {
        throw new UnexpectedLiquibaseException("Property '" + propertyName + "' not found on object type " + object.getClass().getName());
    }
    Class<?> parameterType = method.getParameterTypes()[0];
    Object finalValue = propertyValue;
    if (parameterType.equals(Boolean.class) || parameterType.equals(boolean.class)) {
        finalValue = Boolean.valueOf(propertyValue);
    } else if (parameterType.equals(Integer.class)) {
        finalValue = Integer.valueOf(propertyValue);
    } else if (parameterType.equals(Long.class)) {
        finalValue = Long.valueOf(propertyValue);
    } else if (parameterType.equals(BigInteger.class)) {
        finalValue = new BigInteger(propertyValue);
    } else if (parameterType.equals(BigDecimal.class)) {
        finalValue = new BigDecimal(propertyValue);
    } else if (parameterType.equals(DatabaseFunction.class)) {
        finalValue = new DatabaseFunction(propertyValue);
    } else if (parameterType.equals(SequenceNextValueFunction.class)) {
        finalValue = new SequenceNextValueFunction(propertyValue);
    } else if (parameterType.equals(SequenceCurrentValueFunction.class)) {
        finalValue = new SequenceCurrentValueFunction(propertyValue);
    } else if (Enum.class.isAssignableFrom(parameterType)) {
        finalValue = Enum.valueOf((Class<Enum>) parameterType, propertyValue);
    }
    try {
        method.invoke(object, finalValue);
    } catch (IllegalAccessException e) {
        throw new UnexpectedLiquibaseException(e);
    } catch (IllegalArgumentException e) {
        throw new UnexpectedLiquibaseException("Cannot call " + method.toString() + " with value of type " + finalValue.getClass().getName());
    } catch (InvocationTargetException e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : SequenceCurrentValueFunction(liquibase.statement.SequenceCurrentValueFunction) DatabaseFunction(liquibase.statement.DatabaseFunction) Method(java.lang.reflect.Method) BigDecimal(java.math.BigDecimal) InvocationTargetException(java.lang.reflect.InvocationTargetException) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) SequenceNextValueFunction(liquibase.statement.SequenceNextValueFunction) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 2 with SequenceCurrentValueFunction

use of liquibase.statement.SequenceCurrentValueFunction 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"));
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) SequenceCurrentValueFunction(liquibase.statement.SequenceCurrentValueFunction) ParsedNodeException(liquibase.parser.core.ParsedNodeException) DatabaseFunction(liquibase.statement.DatabaseFunction) BigInteger(java.math.BigInteger) SequenceNextValueFunction(liquibase.statement.SequenceNextValueFunction) Date(java.util.Date)

Aggregations

BigInteger (java.math.BigInteger)2 DatabaseFunction (liquibase.statement.DatabaseFunction)2 SequenceCurrentValueFunction (liquibase.statement.SequenceCurrentValueFunction)2 SequenceNextValueFunction (liquibase.statement.SequenceNextValueFunction)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)1 ParsedNode (liquibase.parser.core.ParsedNode)1 ParsedNodeException (liquibase.parser.core.ParsedNodeException)1