-
Notifications
You must be signed in to change notification settings - Fork 16
Reactive programming with RxJava Support
xcesco edited this page Nov 29, 2017
·
9 revisions
Reactive programming is one of programming trends of this moment. If you want to get more information about it just visit the following site:
The main scope of Rx library is simplify asynchronous tasks. In Android platform development, Rx library is a valid replacement of AsynchTask.
Kripton library contains suppports AsyncTask and Rx too. When you want to enable Rx supports in SQLite you have to:
- add in gradle configuration Rx library references:
dependencies {
implementation 'io.reactivex.rxjava2:rxjava:2.1.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
}
- enable in data source generation with attribute
rx=true
in@BindDataSource
.
@BindDataSource(daoSet = {ContactDao.class}, fileName = "contact.db", rx = true)
public interface ContactDataSource {
}
Once Rx Kripton support is enabled, when a datasource is generated, it contains:
- A subject for each table: this feature allows to register an async listener to monitor table changes. When an insert/update/delete operation is executed on the associated table, an event was fired. This event is trapped by subject.
- Executed methods to execute transaction or simply batch operations with Observable, Flowable, Single, Maybe.
Just for example. Suppose we have an application that manages Contact. So, we have to create a Contact entity, Dao Contact interface and Data Source interface.
Contact.class
@BindTable
public class Contact {
public long id;
public String name;
public String surname;
}
The dao interface DaoContact.class
public interface ContactDao {
@BindSqlInsert
void insert(Contact bean);
@BindSqlUpdate(where="id=${bean.id}")
void update(Contact bean);
@BindSqlDelete(where="id=${bean.id}")
void delete(Contact bean);
@BindSqlSelect(where="id=${id}")
Contact selectById(long id);
@BindSqlSelect
List<Contact> selectAll();
}
And ContactDataSource.class
@BindDataSource(daoSet = {ContactDao.class}, fileName = "contact.db", rx = true)
public interface ContactDataSource {
}
- 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