If you think the Android project adme listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.danielesegato.adme.db.serializer;
//www.java2s.comimport android.content.ContentValues;
import android.database.Cursor;
import com.danielesegato.adme.config.ADMEFieldConfig;
import com.danielesegato.adme.config.SQLiteType;
/**
* Persist an {@link java.lang.String} in the SQLite database, it can be null.
*/publicclass StringADMESerializer extends BaseADMESerializer {
privatestatic StringADMESerializer singleton = new StringADMESerializer();
publicstatic StringADMESerializer getSingleton() {
return singleton;
}
@Override
public SQLiteType getSQLiteType() {
return SQLiteType.TEXT;
}
@Override
public Object sqlToJava(Cursor cursor, int columnPos, ADMEFieldConfig fieldConfig) {
return cursor.isNull(columnPos) ? null : cursor.getString(columnPos);
}
@Override
public String stringToSqlRaw(String val, ADMEFieldConfig fieldConfig) {
return val != null ? String.format("'%s'", val.replaceAll("'", "\\'")) : NULL_RAW;
}
@Override
publicvoid storeInContentValues(String key, ContentValues values, Object fieldValue, ADMEFieldConfig fieldConfig) throws IllegalArgumentException {
if (fieldValue != null && !(fieldValue instanceof String)) {
thrownew IllegalArgumentException(String.format(
String.format("Field value for entity %s field %s can't be considered a String for key %s: %s",
fieldConfig.getADMEEntityConfig().getEntityName(),
fieldConfig.getColumnName(),
key,
fieldValue)
));
}
if (fieldValue != null) {
values.put(key, (String) fieldValue);
} else {
values.putNull(key);
}
}
}