liquibase.statement.DatabaseFunction Java Examples

The following examples show how to use liquibase.statement.DatabaseFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeometryType.java    From liquibase-spatial with Apache License 2.0 6 votes vote down vote up
/**
 * @see liquibase.datatype.LiquibaseDataType#objectToSql(java.lang.Object,
 *      liquibase.database.Database)
 */
@Override
public String objectToSql(final Object value, final Database database) {
   final String returnValue;
   if (value instanceof Geometry) {
      // TODO: Tailor the output for the database.
      returnValue = ((Geometry) value).toText();
   } else if (value instanceof String) {
      returnValue = value.toString();
   } else if (value instanceof DatabaseFunction) {
      returnValue = value.toString();
   } else if (value == null || value.toString().equalsIgnoreCase("null")) {
      returnValue = null;
   } else {
      throw new UnexpectedLiquibaseException("Cannot convert type " + value.getClass()
            + " to a Geometry value");
   }
   return returnValue;
}
 
Example #2
Source File: AbstractJdbcDatabase.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean isFunction(final String string) {
    if (string.endsWith("()")) {
        return true;
    }
    for (DatabaseFunction function : getDateFunctions()) {
        if (function.toString().equalsIgnoreCase(string)) {
            return true;
        }
    }
    return false;
}
 
Example #3
Source File: AbstractJdbcDatabase.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void setCurrentDateTimeFunction(final String function) {
    if (function != null) {
        this.currentDateTimeFunction = function;
        this.dateFunctions.add(new DatabaseFunction(function));
    }
}
 
Example #4
Source File: HiveInsertGenerator.java    From liquibase-impala with Apache License 2.0 5 votes vote down vote up
private void generateValues(StringBuilder sql, HiveInsertStatement statement, Database database) {
    sql.append("(");

    for (Object newValue : statement.getColumnValues()) {
        if (newValue == null || newValue.toString().equalsIgnoreCase("NULL")) {
            sql.append("NULL");
        } else if (newValue instanceof String && !looksLikeFunctionCall(((String) newValue), database)) {
            sql.append(DataTypeFactory.getInstance().fromObject(newValue, database).objectToSql(newValue, database));
        } else if (newValue instanceof Date) {
            sql.append(database.getDateLiteral(((Date) newValue)));
        } else if (newValue instanceof Boolean) {
            if (((Boolean) newValue)) {
                sql.append(DataTypeFactory.getInstance().getTrueBooleanValue(database));
            } else {
                sql.append(DataTypeFactory.getInstance().getFalseBooleanValue(database));
            }
        } else if (newValue instanceof DatabaseFunction) {
            sql.append(database.generateDatabaseFunctionValue((DatabaseFunction) newValue));
        } else {
            sql.append(newValue);
        }
        sql.append(", ");
    }

    sql.deleteCharAt(sql.lastIndexOf(" "));
    int lastComma = sql.lastIndexOf(",");
    if (lastComma >= 0) {
        sql.deleteCharAt(lastComma);
    }

    sql.append(")");
}
 
Example #5
Source File: AbstractJdbcDatabase.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public List<DatabaseFunction> getDateFunctions() {
    return dateFunctions;
}