Search in sources :

Example 1 with BindXenoDataSource

use of sqlite.feature.rx.persistence.BindXenoDataSource 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();
    }
}
Also used : CountryDaoImpl(sqlite.feature.rx.persistence.CountryDaoImpl) Disposable(io.reactivex.disposables.Disposable) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Country(sqlite.feature.rx.model.Country) List(java.util.List) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with BindXenoDataSource

use of sqlite.feature.rx.persistence.BindXenoDataSource 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;
}
Also used : CountryDaoImpl(sqlite.feature.rx.persistence.CountryDaoImpl) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) Country(sqlite.feature.rx.model.Country) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory)

Example 3 with BindXenoDataSource

use of sqlite.feature.rx.persistence.BindXenoDataSource 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;
        }
    });
}
Also used : CountryDaoImpl(sqlite.feature.rx.persistence.CountryDaoImpl) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) OnReadBeanListener(com.abubusoft.kripton.android.sqlite.OnReadBeanListener) Country(sqlite.feature.rx.model.Country) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 4 with BindXenoDataSource

use of sqlite.feature.rx.persistence.BindXenoDataSource 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;
        }
    });
}
Also used : CountryDaoImpl(sqlite.feature.rx.persistence.CountryDaoImpl) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Country(sqlite.feature.rx.model.Country) List(java.util.List) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 5 with BindXenoDataSource

use of sqlite.feature.rx.persistence.BindXenoDataSource 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();
}
Also used : Disposable(io.reactivex.disposables.Disposable) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory) SQLiteEvent(com.abubusoft.kripton.android.sqlite.SQLiteEvent) Function(io.reactivex.functions.Function) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) Country(sqlite.feature.rx.model.Country) List(java.util.List) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Aggregations

Country (sqlite.feature.rx.model.Country)5 BindXenoDaoFactory (sqlite.feature.rx.persistence.BindXenoDaoFactory)5 BindXenoDataSource (sqlite.feature.rx.persistence.BindXenoDataSource)5 BaseAndroidTest (base.BaseAndroidTest)4 Test (org.junit.Test)4 CountryDaoImpl (sqlite.feature.rx.persistence.CountryDaoImpl)4 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)3 List (java.util.List)3 Disposable (io.reactivex.disposables.Disposable)2 OnReadBeanListener (com.abubusoft.kripton.android.sqlite.OnReadBeanListener)1 SQLiteEvent (com.abubusoft.kripton.android.sqlite.SQLiteEvent)1 Function (io.reactivex.functions.Function)1