use of sqlite.feature.rx.persistence.CountryDaoImpl in project kripton by xcesco.
the class TestRx method testRunAsync.
@Test
public void testRunAsync() {
BindXenoDataSource dataSource = prepareDataSource();
dataSource.execute(new BindXenoDataSource.ObservableTransaction<Country>() {
@Override
public TransactionResult onExecute(BindXenoDaoFactory daoFactory, ObservableEmitter<Country> emitter) {
CountryDaoImpl dao = daoFactory.getCountryDao();
List<Country> list = dao.selectAll();
for (Country item : list) {
emitter.onNext(item);
}
return TransactionResult.COMMIT;
}
}).subscribeOn(Schedulers.newThread()).subscribe(new Observer<Country>() {
@Override
public void onSubscribe(Disposable d) {
System.out.println(Thread.currentThread().getName() + " onSubscribe");
}
@Override
public void onNext(Country t) {
System.out.println(Thread.currentThread().getName() + " onNext " + t.name);
}
@Override
public void onError(Throwable e) {
System.out.println(Thread.currentThread().getName() + " onNext");
}
@Override
public void onComplete() {
System.out.println(Thread.currentThread().getName() + " onComplete");
}
});
System.out.println(Thread.currentThread().getName() + " Finished");
try {
Thread.currentThread().sleep(5000);
} catch (Throwable e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
use of sqlite.feature.rx.persistence.CountryDaoImpl in project kripton by xcesco.
the class TestRx method prepareDataSource.
public BindXenoDataSource prepareDataSource() {
BindXenoDataSource dataSource = BindXenoDataSource.instance();
dataSource.executeBatch(new BindXenoDataSource.Batch<Void>() {
@Override
public Void onExecute(BindXenoDaoFactory daoFactory) {
CountryDaoImpl dao = daoFactory.getCountryDao();
for (int i = 0; i < COUNTER; i++) {
Country bean = new Country();
bean.code = "code" + i;
bean.callingCode = "" + i;
bean.name = "name" + i;
// Object bean = new
dao.insert(bean);
}
return null;
// dao.selectAll();
}
});
return dataSource;
}
use of sqlite.feature.rx.persistence.CountryDaoImpl in project kripton by xcesco.
the class TestRx method testRunSyncWithListener.
@Test
public void testRunSyncWithListener() {
BindXenoDataSource dataSource = BindXenoDataSource.instance();
dataSource.execute(new BindXenoDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindXenoDaoFactory daoFactory) {
CountryDaoImpl dao = daoFactory.getCountryDao();
for (int i = 0; i < COUNTER; i++) {
Country bean = new Country();
bean.code = "code" + i;
bean.callingCode = "" + i;
bean.name = "name" + i;
// Object bean = new
dao.insert(bean);
}
dao.selectAll();
return TransactionResult.COMMIT;
}
});
dataSource.execute(new BindXenoDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindXenoDaoFactory daoFactory) {
System.out.println("onSubscribe");
CountryDaoImpl dao = daoFactory.getCountryDao();
dao.selectAll(new OnReadBeanListener<Country>() {
@Override
public void onRead(Country bean, int row, int rowCount) {
System.out.println("onNext" + bean);
}
});
System.out.println("onComplete");
return TransactionResult.COMMIT;
}
});
}
use of sqlite.feature.rx.persistence.CountryDaoImpl in project kripton by xcesco.
the class TestRx method testRunSync.
@Test
public void testRunSync() {
BindXenoDataSource dataSource = BindXenoDataSource.instance();
dataSource.execute(new BindXenoDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindXenoDaoFactory daoFactory) {
CountryDaoImpl dao = daoFactory.getCountryDao();
for (int i = 0; i < COUNTER; i++) {
Country bean = new Country();
bean.code = "code" + i;
bean.callingCode = "" + i;
bean.name = "name" + i;
// Object bean = new
dao.insert(bean);
}
dao.selectAll();
return TransactionResult.COMMIT;
}
});
dataSource.execute(new BindXenoDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindXenoDaoFactory daoFactory) {
System.out.println("onSubscribe");
CountryDaoImpl dao = daoFactory.getCountryDao();
List<Country> list = dao.selectAll();
for (Country item : list) {
System.out.println("onNext" + item);
}
System.out.println("onComplete");
return TransactionResult.COMMIT;
}
});
}
Aggregations