-
Notifications
You must be signed in to change notification settings - Fork 16
Global SQL Type adapter
xcesco edited this page May 2, 2018
·
1 revision
SQL type adapters are usually defined directly on field declaration. When you need to use same SQL Type Adapter for all field of a specific type for all data model classes, you have two choices: mark every field of that type with needed type adapter or define this global type adapter at data-source level. The first case is already analyzed in SQL Type adapter page. For the second case, it can be useful get an example:
Suppose we want to manage all Date
field as Long
type (default behaviour is stored them in a string). To do this just define the data-source, using @BindDataSource, in the following as follows:
@BindDataSource(daoSet = { DaoPerson.class },
typeAdapters = {
@BindSqlAdapter(adapter = Date2Long.class) },
fileName = "person.db")
public interface AppDataSource {
}
And Date2Long
type adapter class:
public class Date2Long implements SqlTypeAdapter<Date, Long> {
@Override
public Date toJava(Long dataValue) {
if (dataValue != null) {
return new Date(2);
}
return null;
}
@Override
public Long toData(Date javaValue) {
if (javaValue != null) {
return javaValue.getTime();
}
return null;
}
@Override
public String toString(Date javaValue) {
return null;
}
}
- 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