Search in sources :

Example 11 with TransactionResult

use of com.abubusoft.kripton.android.sqlite.TransactionResult in project kripton by xcesco.

the class TestLiveDataRuntime method testRun.

@Test
public void testRun() throws InterruptedException {
    // .build(DataSourceOptions.builder().inMemory(false).build());
    BindApp0DataSource ds = BindApp0DataSource.instance();
    System.out.println("aa" + KriptonTaskExecutor.getInstance().isMainThread());
    LiveData<List<Person>> liveData = ds.getDaoPerson0().select("Manero");
    liveData.observeForever(new Observer<List<Person>>() {

        @Override
        public void onChanged(List<Person> t) {
            System.out.println("*********** " + t.size());
        }
    });
    ds.execute(new BindApp0DataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindApp0DaoFactory daoFactory) {
            Person person = new Person();
            person.name = "Manero";
            person.surname = "Tonj";
            daoFactory.getDaoPerson0().insert(person);
            return TransactionResult.COMMIT;
        }
    });
    Thread.sleep(1000);
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) BindApp0DataSource(sqlite.feature.livedata.persistence0.BindApp0DataSource) List(java.util.List) BindApp0DaoFactory(sqlite.feature.livedata.persistence0.BindApp0DaoFactory) Person(sqlite.feature.livedata.data.Person) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 12 with TransactionResult

use of com.abubusoft.kripton.android.sqlite.TransactionResult in project kripton by xcesco.

the class TestForeignKeyActionRuntime method testRun.

@Test
public void testRun() {
    BindArtistDataSource dataSource = BindArtistDataSource.instance();
    dataSource.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindArtistDaoFactory daoFactory) {
            ArtistDaoImpl daoArtist = daoFactory.getArtistDao();
            AlbumDaoImpl daoAlbum = daoFactory.getAlbumDao();
            Artist bean = new Artist();
            bean.name = "Tonj Manero";
            daoArtist.insert(bean);
            Album album = new Album();
            album.name = "First album";
            album.artistId = bean.id;
            daoAlbum.insert(album);
            Assert.assertTrue(daoArtist.selectAll().size() == 1);
            daoArtist.deleteById(bean.id);
            Assert.assertTrue(daoArtist.selectAll().size() == 0);
            return TransactionResult.COMMIT;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Transaction(sqlite.feature.foreignkeyaction.BindArtistDataSource.Transaction) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 13 with TransactionResult

use of com.abubusoft.kripton.android.sqlite.TransactionResult in project kripton by xcesco.

the class TestForeignKeyARuntime method testRunSqlite2.

@Test
public void testRunSqlite2() throws IOException, InstantiationException, IllegalAccessException {
    BindDummyDataSource dataSource = BindDummyDataSource.instance();
    dataSource.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindDummyDaoFactory daoFactory) {
            DaoBeanA_1Impl dao = daoFactory.getDaoBeanA_1();
            BeanA_2 beanParent = new BeanA_2();
            beanParent.valueString2 = "parent";
            daoFactory.getDaoBeanA_2().insert(beanParent);
            BeanA_1 bean = new BeanA_1();
            bean.valueString = "hello";
            bean.beanA2Id = beanParent.id;
            dao.insert(bean);
            assertEquals(1, bean.id);
            return TransactionResult.COMMIT;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Transaction(sqlite.feature.foreignKey.BindDummyDataSource.Transaction) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 14 with TransactionResult

use of com.abubusoft.kripton.android.sqlite.TransactionResult in project kripton by xcesco.

the class TestForeignKeyARuntime method testRunSqlite1.

@Test
public void testRunSqlite1() throws IOException, InstantiationException, IllegalAccessException {
    BindDummyDataSource dataSource = BindDummyDataSource.instance();
    dataSource.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindDummyDaoFactory daoFactory) {
            DaoBeanA_1Impl dao = daoFactory.getDaoBeanA_1();
            BeanA_2 beanParent = new BeanA_2();
            beanParent.valueString2 = "parent";
            daoFactory.getDaoBeanA_2().insert(beanParent);
            BeanA_1 bean = new BeanA_1();
            bean.valueString = "hello";
            bean.beanA2Id = beanParent.id;
            dao.insert(bean);
            assertEquals(1, bean.id);
            List<BeanA_1> list = dao.selectById(bean.id);
            Assert.assertEquals("not one ", 1, list.size());
            return TransactionResult.COMMIT;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Transaction(sqlite.feature.foreignKey.BindDummyDataSource.Transaction) List(java.util.List) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 15 with TransactionResult

use of com.abubusoft.kripton.android.sqlite.TransactionResult 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)

Aggregations

TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)28 BaseAndroidTest (base.BaseAndroidTest)27 Test (org.junit.Test)27 List (java.util.List)13 Transaction (sqlite.feature.foreignKey.BindDummyDataSource.Transaction)4 One (com.abubusoft.kripton.common.One)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Country (sqlite.feature.rx.model.Country)3 BindXenoDaoFactory (sqlite.feature.rx.persistence.BindXenoDaoFactory)3 BindXenoDataSource (sqlite.feature.rx.persistence.BindXenoDataSource)3 CountryDaoImpl (sqlite.feature.rx.persistence.CountryDaoImpl)3 Person (sqlite.feature.speed.model.Person)3 BindPersonDaoFactory (sqlite.feature.speed.persistence.BindPersonDaoFactory)3 BindPersonDataSource (sqlite.feature.speed.persistence.BindPersonDataSource)3 Transaction (sqlite.feature.speed.persistence.BindPersonDataSource.Transaction)3 PersonDaoImpl (sqlite.feature.speed.persistence.PersonDaoImpl)3 ArrayList (java.util.ArrayList)2 BindKripton180BeanDaoFactory (sqlite.feature.typeadapter.kripton180.bean.BindKripton180BeanDaoFactory)2 BindKripton180BeanDataSource (sqlite.feature.typeadapter.kripton180.bean.BindKripton180BeanDataSource)2