Data source options
xcesco edited this page Apr 26, 2018
·
4 revisions
There are two ways to customize data source creation: by code or by annotation.
When data-source is created, usually at application startup, it is possible to define some features: if it is in-memory if DDL log is enabled, the populator and the migration-version tasks and so on.
By code, it is possible to initialize data source using DataSourceOptions and its builder.
DataSourceOptions.Builder optionsBuilder=DataSourceOptions.builder();
optionsBuilder.inMemory(false);
optionsBuilder.databaseLifecycleHandler(new DatabaseLifecycleHandler() {
@Override
public void onUpdate(SQLiteDatabase database, int oldVersion, int newVersion, boolean upgrade) {
Logger.info("databaseLifecycleHandler - onUpdate");
}
@Override
public void onCreate(SQLiteDatabase database) {
Logger.info("databaseLifecycleHandler - onCreate "+database.getVersion());
...
}
@Override
public void onConfigure(SQLiteDatabase database) {
Logger.info("databaseLifecycleHandler - onConfigure");
...
}
});
optionsBuilder.addUpdateTask(1, new SQLiteUpdateTask() {
@Override
public void execute(SQLiteDatabase database, int previousVersion, int currentVersion) {
...
}
});
// create data source
BindAppWithConfigDataSource ds=BindAppWithConfigDataSource.build(optionsBuilder.build());
To achieve the same result with @BindDataSourceOptions just define data source:
@BindDataSourceOptions(
logEnabled = true,
populator = PersonPopulator.class,
cursorFactory = PersonCursorFactory.class,
databaseLifecycleHandler=PersonLifecycleHandler.class,
updateTasks = {
@BindDataSourceUpdateTask(version = 2, task = PersonUpdateTask.class)
})
@BindDataSource(daoSet = { DaoPerson.class }, fileName = "app.db")
public interface AppWithConfigDataSource {
}
And the code for creating data source will become
// create data source
BindAppWithConfigDataSource ds=BindAppWithConfigDataSource.instance();
- 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