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.com*/import android.content.ContentValues;
import android.database.Cursor;
import com.danielesegato.adme.config.ADMEFieldConfig;
import com.danielesegato.adme.config.SQLiteType;
/**
* Persist an {@link java.lang.Integer} in the SQLite database, it can be null.
*/publicclass IntObjectADMESerializer extends BaseADMESerializer {
privatestatic IntObjectADMESerializer singleton = new IntObjectADMESerializer();
publicstatic IntObjectADMESerializer getSingleton() {
return singleton;
}
@Override
public SQLiteType getSQLiteType() {
return SQLiteType.INTEGER;
}
@Override
public Object sqlToJava(Cursor cursor, int columnPos, ADMEFieldConfig fieldConfig) {
return cursor.isNull(columnPos) ? null : cursor.getInt(columnPos);
}
@Override
public String stringToSqlRaw(String val, ADMEFieldConfig fieldConfig) {
return val != null ? Integer.toString(Integer.parseInt(val)) : NULL_RAW;
}
@Override
publicvoid storeInContentValues(String key, ContentValues values, Object fieldValue, ADMEFieldConfig fieldConfig) throws IllegalArgumentException {
if (fieldValue != null && !(fieldValue instanceofInteger)) {
thrownew IllegalArgumentException(String.format(
String.format("Field value for entity %s field %s can't be considered a Integer for key %s: %s",
fieldConfig.getADMEEntityConfig().getEntityName(),
fieldConfig.getColumnName(),
key,
fieldValue)
));
}
if (fieldValue != null) {
values.put(key, (Integer) fieldValue);
} else {
values.putNull(key);
}
}
}