Search in sources :

Example 21 with TransactionResult

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

the class TestPerformanceRuntime method testRunSave.

@Test
public void testRunSave() {
    // delete all
    final BindSimpleDataSource dataSource = BindSimpleDataSource.instance();
    dataSource.execute(new BindSimpleDataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindSimpleDaoFactory daoFactory) {
            daoFactory.getSimpleAddressDao().deleteAll();
            Collection<SimpleAddressItem> simpleAddressItems = Generator.getKriptonSimpleAddresses(SimpleAddressItem.class, LOOP_COUNT);
            long insertDuration;
            long insertOptimizedDuration;
            // normal INSERT
            {
                log("insert NORMAL start");
                long startTime = System.currentTimeMillis();
                for (SimpleAddressItem simpleAddressItem : simpleAddressItems) {
                    daoFactory.getSimpleAddressDao().insert(simpleAddressItem);
                }
                insertDuration = System.currentTimeMillis() - startTime;
                log("insert duration: %s", insertDuration);
            }
            // end
            daoFactory.getSimpleAddressDao().deleteAll();
            // optimized INSERT
            {
                log("insert OPTIZED start");
                long startTime = System.currentTimeMillis();
                for (SimpleAddressItem simpleAddressItem : simpleAddressItems) {
                    daoFactory.getSimpleAddressDao().insert(simpleAddressItem);
                }
                insertOptimizedDuration = System.currentTimeMillis() - startTime;
                log("insert OPTIMIZED duration: %s", insertOptimizedDuration);
            }
            // end
            return TransactionResult.COMMIT;
        }
    });
}
Also used : SimpleAddressItem(sqlite.feature.performance.simple.SimpleAddressItem) BindSimpleDataSource(sqlite.feature.performance.simple.BindSimpleDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) BindSimpleDaoFactory(sqlite.feature.performance.simple.BindSimpleDaoFactory) Collection(java.util.Collection) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 22 with TransactionResult

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

the class TestFeatureSQLTypeAdapterBitmapRuntime method testSelect.

@Test
public void testSelect() {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    final Bitmap bitmap = BitmapFactory.decodeFile("/src/test/resources/imgs/img.png", options);
    BindAppDataSource ds = BindAppDataSource.instance();
    ds.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
            Person bean = new Person();
            bean.image = bitmap;
            daoFactory.getDaoPerson().insert(bean);
            List<Person> list = daoFactory.getDaoPerson().list();
            for (Person person : list) {
                // use
                saveImage((new File("src/test/resources/imgs/img0.png")).getAbsolutePath(), person.image);
            }
            return TransactionResult.COMMIT;
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Transaction(sqlite.feature.typeadapter.bitmap.BindAppDataSource.Transaction) BindAppDataSource(sqlite.feature.typeadapter.bitmap.BindAppDataSource) BindAppDaoFactory(sqlite.feature.typeadapter.bitmap.BindAppDaoFactory) List(java.util.List) BitmapFactory(android.graphics.BitmapFactory) Person(sqlite.feature.typeadapter.bitmap.Person) File(java.io.File) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 23 with TransactionResult

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

the class TestSpeedRuntime method testSingle.

@Test
public void testSingle() {
    final One<Long> start = new One<>();
    final One<Long> end = new One<>();
    final int COUNTER = 200000;
    final BindPersonDataSource ds = BindPersonDataSource.instance();
    ds.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindPersonDaoFactory daoFactory) {
            start.value0 = System.currentTimeMillis();
            PersonDaoImpl dao = daoFactory.getPersonDao();
            for (int i = 0; i < COUNTER; i++) {
                Person bean = new Person();
                bean.name = "name" + i;
                bean.surname = "surname" + i;
                // Object bean = new
                dao.insert(bean);
            }
            end.value0 = System.currentTimeMillis();
            return TransactionResult.COMMIT;
        }
    });
    // 3100
    System.out.println("Esecuzione terminata in " + (end.value0 - start.value0) + " ms");
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Transaction(sqlite.feature.speed.persistence.BindPersonDataSource.Transaction) One(com.abubusoft.kripton.common.One) BindPersonDataSource(sqlite.feature.speed.persistence.BindPersonDataSource) BindPersonDaoFactory(sqlite.feature.speed.persistence.BindPersonDaoFactory) PersonDaoImpl(sqlite.feature.speed.persistence.PersonDaoImpl) Person(sqlite.feature.speed.model.Person) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 24 with TransactionResult

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

the class TestForeignKeyARuntime method testRunSqlite3.

@Test
public void testRunSqlite3() 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 25 with TransactionResult

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

the class TestForeignKeyARuntime method testRunSqlite4.

@Test
public void testRunSqlite4() 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)

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