use of sqlite.feature.many2many.case7.BindAppDataSource in project kripton by xcesco.
the class TestFeatureRuntime2 method testRuntime.
@Test
public void testRuntime() {
BindAppDataSource ds = BindAppDataSource.getInstance();
ds.execute(new Transaction() {
@Override
public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
DaoCityImpl dao = daoFactory.getDaoCity();
long id1;
long id2;
City bean1 = new City();
bean1.name = "city1";
id1 = dao.insert(bean1);
City bean2 = new City();
bean2.name = "city2";
id2 = dao.insert(bean2);
long[] params = { id1, id2 };
assertTrue(dao.selectAll(params).size() == 2);
return TransactionResult.COMMIT;
}
});
}
use of sqlite.feature.many2many.case7.BindAppDataSource in project kripton by xcesco.
the class TestOptionalCase1Runtime method testRunSqlite1.
/**
* Test run sqlite 1.
*/
@Test
public void testRunSqlite1() {
BindAppDataSource ds = BindAppDataSource.getInstance();
ds.execute(daoFactory -> {
daoFactory.getDaoArticle().insert(new Article(9, "test"));
return TransactionResult.COMMIT;
});
Assert.assertEquals(1, ds.executeBatch(daoFactory -> daoFactory.getDaoArticle().selectAll()).size());
Assert.assertTrue(ds.executeBatch(daoFactory -> daoFactory.getDaoArticle().selectById(1)).isPresent());
Assert.assertTrue(!ds.executeBatch(daoFactory -> daoFactory.getDaoArticle().selectById(10)).isPresent());
}
use of sqlite.feature.many2many.case7.BindAppDataSource in project kripton by xcesco.
the class TestFeatureChildSelectRuntime method testSelect.
/**
* Test select.
*/
@Test
public void testSelect() {
BindAppDataSource ds = BindAppDataSource.getInstance();
ds.execute(daoFactory -> {
for (int i = 0; i < ITERACTIONS; i++) {
Album album = new Album();
album.name = "album" + i;
daoFactory.getDaoAlbum().insert(album);
for (int j = 0; j < i; j++) {
Song song = new Song();
song.albumId = album.getId();
song.name = "song" + j;
daoFactory.getDaoSong().insert(song);
}
}
return TransactionResult.COMMIT;
});
ds.execute(new BindAppDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
List<Album> result = daoFactory.getDaoAlbum().selectAlbums();
for (int i = 0; i < ITERACTIONS; i++) {
assertThat(result.get(i).getSongs().size(), is(i));
}
return TransactionResult.COMMIT;
}
});
}
use of sqlite.feature.many2many.case7.BindAppDataSource in project kripton by xcesco.
the class TestRuntimeMany2Many7 method testMany2Many.
/**
* Test many 2 many.
*
* @throws InterruptedException
* the interrupted exception
*/
@Test
public void testMany2Many() throws InterruptedException {
BindAppDataSource ds = BindAppDataSource.getInstance();
ds.execute(new Transaction() {
@Override
public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
List<City> cities = new ArrayList<City>();
List<Person> persons = new ArrayList<Person>();
CityDaoImpl cityDao = daoFactory.getCityDao();
PersonDaoImpl personDao = daoFactory.getPersonDao();
City2PersonDaoImpl m2mDao = daoFactory.getCity2PersonDao();
// insert city
for (int i = 0; i < 1; i++) {
City bean = new City();
bean.name = "city" + i;
cityDao.insert(bean);
cities.add(bean);
}
// insert person
for (int i = 0; i < 1; i++) {
Person bean = new Person();
bean.name = "person" + i;
personDao.insert(bean);
persons.add(bean);
}
{
// m2m
CityPerson bean = new CityPerson(0, cities.get(0).id, persons.get(0).id);
m2mDao.insert(bean);
}
return TransactionResult.COMMIT;
}
});
}
use of sqlite.feature.many2many.case7.BindAppDataSource in project kripton by xcesco.
the class TestFeatureRelationRuntime method testSelect.
/**
* Test select.
*/
@Test
public void testSelect() {
BindAppDataSource ds = BindAppDataSource.getInstance();
ds.execute(new BindAppDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
for (int i = 0; i < ITERACTIONS; i++) {
Album album = new Album();
album.name = "album" + i;
daoFactory.getDaoAlbum().insert(album);
for (int j = 0; j < i; j++) {
Song song = new Song();
song.albumId = album.getId();
song.name = "song" + j;
daoFactory.getDaoSong().insert(song);
}
}
return TransactionResult.COMMIT;
}
});
ds.execute(new BindAppDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
List<Album> result = daoFactory.getDaoAlbum().selectAlbums();
for (int i = 0; i < ITERACTIONS; i++) {
assertThat(result.get(i).getSongs().size(), is(i));
}
return TransactionResult.COMMIT;
}
});
}
Aggregations