public class ReflectiveEntityConverter<T> extends java.lang.Object implements EntityConverter<T>
EntityConverterEntityConverter.Column, EntityConverter.ColumnType| Modifier and Type | Field and Description |
|---|---|
protected Cupboard |
mCupboard
The
Cupboard instance for this converter |
protected java.lang.Class<T> |
mEntityClass |
| Constructor and Description |
|---|
ReflectiveEntityConverter(Cupboard cupboard,
java.lang.Class<T> entityClass) |
ReflectiveEntityConverter(Cupboard cupboard,
java.lang.Class<T> entityClass,
java.util.Collection<java.lang.String> ignoredFieldsNames) |
ReflectiveEntityConverter(Cupboard cupboard,
java.lang.Class<T> entityClass,
java.util.Collection<java.lang.String> ignoredFieldNames,
java.util.Collection<EntityConverter.Column> additionalColumns)
Constructor suitable for
EntityConverterFactorys that only need minor
changes to the default behavior of this converter, not requiring a sub class. |
| Modifier and Type | Method and Description |
|---|---|
T |
fromCursor(android.database.Cursor cursor)
Create an entity from the cursor.
|
protected java.lang.String |
getColumn(java.lang.reflect.Field field)
Return the column name based on the field supplied.
|
java.util.List<EntityConverter.Column> |
getColumns()
Get the database column names along with the colum types
|
protected FieldConverter<?> |
getFieldConverter(java.lang.reflect.Field field)
Get a
FieldConverter for the specified field. |
java.lang.Long |
getId(T instance)
Get the id of an entity
|
protected Index |
getIndexes(java.lang.reflect.Field field) |
java.lang.String |
getTable()
Get the database table for the entity
|
protected boolean |
isIgnored(java.lang.reflect.Field field)
Check if a field should be ignored.
|
protected boolean |
isReadOnlyColumn(java.lang.reflect.Field field)
Return if the specified field is read only; meaning that it will never be stored, but only
read from if it exists in the database.
|
void |
setId(java.lang.Long id,
T instance)
Set the id value on an entity
|
void |
toValues(T object,
android.content.ContentValues values)
Convert an entity to content values
Generally speaking do not add content values for columns that aren't returned from
EntityConverter.getColumns() and omit columns of value EntityConverter.ColumnType.JOIN |
protected final java.lang.Class<T> mEntityClass
public ReflectiveEntityConverter(Cupboard cupboard, java.lang.Class<T> entityClass)
public ReflectiveEntityConverter(Cupboard cupboard, java.lang.Class<T> entityClass, java.util.Collection<java.lang.String> ignoredFieldsNames)
public ReflectiveEntityConverter(Cupboard cupboard, java.lang.Class<T> entityClass, java.util.Collection<java.lang.String> ignoredFieldNames, java.util.Collection<EntityConverter.Column> additionalColumns)
EntityConverterFactorys that only need minor
changes to the default behavior of this converter, not requiring a sub class.cupboard - the cupboard instanceentityClass - the entity classignoredFieldNames - a collection of field names that should be ignored as an alternative to implementing isIgnored(java.lang.reflect.Field)additionalColumns - a collection of additional columns that will be requested from the cursorprotected FieldConverter<?> getFieldConverter(java.lang.reflect.Field field)
FieldConverter for the specified field. This allows for subclasses
to provide a specific FieldConverter for a property. The default implementation
simply calls Cupboard.getFieldConverter(java.lang.reflect.Type)field - the fieldprotected boolean isIgnored(java.lang.reflect.Field field)
Cupboard.isUseAnnotations() returns true also checks for the Ignore
annotation.field - the fieldpublic T fromCursor(android.database.Cursor cursor)
EntityConverterEntityConverter.getColumns(),
but the number of columns might be less if the result does not contain them.
For example, if the converter has 10 columns and the cursor has only 7, the columns 0-6 from EntityConverter.getColumns() will be supplied, even
if the original cursor does not contain all of them. This allows a EntityConverter to iterate over the columns without checking for column name.
Note the contract between @{link #getColumns} and this function: EntityConverter.getColumns() should always specify the required columns for conversion. Any unlisted columns will be dropped from
the cursor that is supplied here for performance reasons.fromCursor in interface EntityConverter<T>cursor - the cursorpublic void toValues(T object, android.content.ContentValues values)
EntityConverterEntityConverter.getColumns() and omit columns of value EntityConverter.ColumnType.JOINtoValues in interface EntityConverter<T>object - the entityvalues - the content values to populatepublic java.util.List<EntityConverter.Column> getColumns()
EntityConvertergetColumns in interface EntityConverter<T>EntityConverter.ColumnTypeprotected boolean isReadOnlyColumn(java.lang.reflect.Field field)
DatabaseCompartment.createTables()field - the field to checkEntityConverter.ColumnType.JOIN), false otherwisepublic void setId(java.lang.Long id,
T instance)
EntityConvertersetId in interface EntityConverter<T>id - the idinstance - the instance to set the id onpublic java.lang.Long getId(T instance)
EntityConvertergetId in interface EntityConverter<T>instance - the entityprotected java.lang.String getColumn(java.lang.reflect.Field field)
Column annotation, then
the column name is taken from the annotation. In all other cases the
column name is simply the name of the field.field - the entity fieldprotected Index getIndexes(java.lang.reflect.Field field)
public java.lang.String getTable()
EntityConvertergetTable in interface EntityConverter<T>