Search in sources :

Example 1 with BindAppDataSource

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;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Transaction(sqlite.feature.in.case2.BindAppDataSource.Transaction) BindAppDataSource(sqlite.feature.in.case2.BindAppDataSource) BindAppDaoFactory(sqlite.feature.in.case2.BindAppDaoFactory) DaoCityImpl(sqlite.feature.in.case2.DaoCityImpl) City(sqlite.feature.in.case2.City) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with BindAppDataSource

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());
}
Also used : Test(org.junit.Test) BindAppDataSource(sqlite.feature.optional.case1.BindAppDataSource) Assert(org.junit.Assert) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) BaseAndroidTest(base.BaseAndroidTest) Article(sqlite.feature.optional.model.Article) BindAppDataSource(sqlite.feature.optional.case1.BindAppDataSource) Article(sqlite.feature.optional.model.Article) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 3 with BindAppDataSource

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;
        }
    });
}
Also used : Song(sqlite.feature.relations.case1.Song) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) BindAppDataSource(sqlite.feature.relations.case1.BindAppDataSource) BindAppDaoFactory(sqlite.feature.relations.case1.BindAppDaoFactory) Album(sqlite.feature.relations.case1.Album) List(java.util.List) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 4 with BindAppDataSource

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;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) City2PersonDaoImpl(sqlite.feature.many2many.case7.City2PersonDaoImpl) PersonDaoImpl(sqlite.feature.many2many.case7.PersonDaoImpl) City2PersonDaoImpl(sqlite.feature.many2many.case7.City2PersonDaoImpl) City(sqlite.feature.many2many.case7.City) CityPerson(sqlite.feature.many2many.case7.CityPerson) CityDaoImpl(sqlite.feature.many2many.case7.CityDaoImpl) Transaction(sqlite.feature.many2many.case7.BindAppDataSource.Transaction) BindAppDataSource(sqlite.feature.many2many.case7.BindAppDataSource) BindAppDaoFactory(sqlite.feature.many2many.case7.BindAppDaoFactory) ArrayList(java.util.ArrayList) List(java.util.List) Person(sqlite.feature.many2many.case7.Person) CityPerson(sqlite.feature.many2many.case7.CityPerson) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 5 with BindAppDataSource

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;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Song(sqlite.feature.relations.case1.Song) BindAppDataSource(sqlite.feature.relations.case1.BindAppDataSource) BindAppDaoFactory(sqlite.feature.relations.case1.BindAppDaoFactory) Album(sqlite.feature.relations.case1.Album) List(java.util.List) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Aggregations

BaseAndroidTest (base.BaseAndroidTest)8 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)8 Test (org.junit.Test)8 List (java.util.List)6 Date (java.util.Date)3 BindAppDaoFactory (sqlite.feature.custombean.case1.BindAppDaoFactory)2 BindAppDataSource (sqlite.feature.custombean.case1.BindAppDataSource)2 Transaction (sqlite.feature.custombean.case1.BindAppDataSource.Transaction)2 Book (sqlite.feature.custombean.case1.Book)2 Loan (sqlite.feature.custombean.case1.Loan)2 LoanWithUserAndBook (sqlite.feature.custombean.case1.LoanWithUserAndBook)2 User (sqlite.feature.custombean.case1.User)2 Album (sqlite.feature.relations.case1.Album)2 BindAppDaoFactory (sqlite.feature.relations.case1.BindAppDaoFactory)2 BindAppDataSource (sqlite.feature.relations.case1.BindAppDataSource)2 Song (sqlite.feature.relations.case1.Song)2 ArrayList (java.util.ArrayList)1 Assert (org.junit.Assert)1 BindAppDaoFactory (sqlite.feature.custombean.case2.BindAppDaoFactory)1 BindAppDataSource (sqlite.feature.custombean.case2.BindAppDataSource)1