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);
}
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;
}
});
}
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;
}
});
}
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;
}
});
}
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();
}
}
Aggregations