use of com.abubusoft.kripton.android.sqlite.SQLiteEvent in project kripton by xcesco.
the class TestRx method testDatabase.
@Test
public void testDatabase() {
final BindXenoDataSource ds = prepareDataSource();
Disposable s1 = ds.getCountryDao().subject().subscribe(new Consumer<SQLiteEvent>() {
@Override
public void accept(SQLiteEvent t) throws Exception {
log("----> MAP " + Thread.currentThread().getName());
log("S1 ---------------------- receive country %s %s", t.operationType, t.value);
}
});
/*
* ds.execute(new ObservableTransaction<Country>() {
*
* @Override public TransactionResult onExecute(BindXenoDaoFactory
* daoFactory, ObservableEmitter<Country> emitter) { log("onExecute " +
* Thread.currentThread().getName()); CountryDaoImpl dao =
* daoFactory.getCountryDao();
*
* List<Country> list = dao.selectAll();
*
* for (Country item : list) { emitter.onNext(item); }
*
* return TransactionResult.COMMIT; }
* }).subscribeOn(Schedulers.computation()).observeOn(Schedulers.io()).
* subscribe(new Consumer<Country>() {
*
* @Override public void accept(Country t) throws Exception {
* log("accept " + Thread.currentThread().getName()); log(" country " +
* t.name);
*
* } });
*/
ds.executeBatch(new BindXenoDataSource.Batch<Void>() {
@Override
public Void onExecute(BindXenoDaoFactory daoFactory) {
for (int i = 100; i < 102; i++) {
Country bean = new Country();
bean.code = "code" + i;
bean.callingCode = "" + i;
bean.name = "name" + i;
daoFactory.getCountryDao().insert(bean);
}
return null;
}
});
Disposable s2 = ds.countrySubject().observeOn(Schedulers.io()).map(new Function<SQLiteEvent, List<Country>>() {
@Override
public List<Country> apply(SQLiteEvent t) throws Exception {
log("----> MAP " + Thread.currentThread().getName());
return ds.executeBatch(new BindXenoDataSource.Batch<List<Country>>() {
@Override
public List<Country> onExecute(BindXenoDaoFactory daoFactory) {
return daoFactory.getCountryDao().selectAll();
}
});
}
}).subscribe(new Consumer<List<Country>>() {
@Override
public void accept(List<Country> t) throws Exception {
log("----> S2 " + Thread.currentThread().getName());
// log("S2 ---------------------- receive country %s
// %s",t.operationType , t.value);
// ds.getCountryDao().selectAll();
}
});
ds.executeBatch(new BindXenoDataSource.Batch<Void>() {
@Override
public Void onExecute(BindXenoDaoFactory daoFactory) {
for (int i = 200; i < 202; i++) {
Country bean = new Country();
bean.code = "code" + i;
bean.callingCode = "" + i;
bean.name = "name" + i;
daoFactory.getCountryDao().insert(bean);
}
return null;
}
});
try {
Thread.currentThread().sleep(5000);
} catch (Throwable e) {
e.printStackTrace();
}
s1.dispose();
s2.dispose();
}
Aggregations