use of com.raizlabs.android.dbflow.converter.TypeConverter in project DBFlow by Raizlabs.
the class ValueQueryBuilder method convertValueToDatabaseString.
/**
* Converts the given value into a String for the Database using a {@link com.raizlabs.android.dbflow.converter.TypeConverter}
* if one exists.
*
* @param modelValue The un-typeconverted value of the model.
* @return The string DB value of the object
*/
@SuppressWarnings("unchecked")
public static String convertValueToDatabaseString(Object modelValue) {
String stringVal;
Object value = modelValue;
if (value != null) {
TypeConverter typeConverter = FlowManager.getTypeConverterForClass(value.getClass());
if (typeConverter != null) {
value = typeConverter.getDBValue(value);
}
}
if (value instanceof Number) {
stringVal = String.valueOf(value);
} else {
stringVal = String.valueOf(value);
if (!stringVal.equals(Condition.Operation.EMPTY_PARAM)) {
stringVal = DatabaseUtils.sqlEscapeString(stringVal);
}
}
return stringVal;
}
use of com.raizlabs.android.dbflow.converter.TypeConverter in project DBFlow by Raizlabs.
the class Condition method concatenate.
@SuppressWarnings("unchecked")
@Override
public Condition concatenate(Object value) {
operation = new QueryBuilder(Operation.EQUALS).append(columnName()).toString();
TypeConverter typeConverter = this.typeConverter;
if (typeConverter == null && value != null) {
typeConverter = FlowManager.getTypeConverterForClass(value.getClass());
}
if (typeConverter != null && convertToDB) {
value = typeConverter.getDBValue(value);
}
if (value instanceof String || value instanceof ITypeConditional) {
operation = String.format("%1s %1s ", operation, Operation.CONCATENATE);
} else if (value instanceof Number) {
operation = String.format("%1s %1s ", operation, Operation.PLUS);
} else {
throw new IllegalArgumentException(String.format("Cannot concatenate the %1s", value != null ? value.getClass() : "null"));
}
this.value = value;
isValueSet = true;
return this;
}
Aggregations