-
Notifications
You must be signed in to change notification settings - Fork 16
@BindSqlAdapter
xcesco edited this page May 2, 2018
·
1 revision
This annotation decorates a field to use a particular SQL Type Adapter to customize persistence on an SQLite table. A type adapter must implements SqlTypeAdapter interface. It has two parameter type: the first is the field type (in our example is Bitmap), the second is the type that we want to use as replacement and that will be used to store data into an SQLite table column. It implements three methods:
-
toJava
: converts data retrieved from an SQLite table into a field. -
toData
: converts a field into data to store into an SQLite table. -
toString
: used if you want to use a field as query's parameter (SQLite wrapper for Android convert all SQL parameter used in where condition in its string representation).
- adapter: SQLite Type Adapter class
@BindTable
public class Person {
public long id;
@BindSqlAdapter(adapter = BitmapTypeAdapter.class)
public Bitmap image;
}
And the associated SQL type adapter:
public class BitmapTypeAdapter implements SqlTypeAdapter<Bitmap, byte[]> {
@Override
public Bitmap toJava(byte[] dataValue) {
if (dataValue == null)
return null;
return BitmapFactory.decodeByteArray(dataValue, 0, dataValue.length);
}
@Override
public byte[] toData(Bitmap bitmap) {
if (bitmap == null)
return null;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
return stream.toByteArray();
}
@Override
public String toString(Bitmap javaValue) {
throw (new KriptonRuntimeException("Unsupported operation!"));
}
}
- Introduction
- Goals & Features
- Kotlin
- Immutable or Mutable Pojo
- Annotation Processor Args
- Credits
- Articles
- Benchmarks
- Setup
- Tutorial
- Usage
- Dependencies and inspirations
- Stackoverflow
- Documentation
- SQL logging
- Data source options
- Indices
- SQL Type adapter
- Global SQL Type adapter
- Constraints
- Live data: welcome Architectural components!!
- Paged Live data
- Dynamic parts
- Transactional and batch operations
- Async Transactional and batch operations
- Global transaction
- Support for immutable POJO
- Generate Content provider
- Generate Database schema generation
- Database migration
- BindSqlColumn
- BindContentProvider
- BindContentProviderEntry
- BindContentProviderPath
- BindDao
- BindDaoMany2Many
- BindDataSource
- BindDataSourceOptions
- BindDataSourceUpdateTask
- BindIndex
- BindSqlRelation
- BindSqlAdapter
- BindSqlChildSelect
- BindSqlDelete
- BindSqlDynamicOrderBy
- BindSqlDynamicWhere
- BindSqlDynamicWhereParams
- BindSqlInsert
- BindSqlPageSize
- BindSqlParam
- BindSqlSelect
- BindSqlUpdate
- BindSqlType
- BindSqlTransaction