Search in sources :

Example 1 with PersonDaoImpl

use of sqlite.feature.speed.persistence.PersonDaoImpl in project kripton by xcesco.

the class TestSpeedRuntime method testInsertBatch.

@Test
public void testInsertBatch() {
    final int ITEM_COUNTER = 10000;
    final One<Long> start = new One<>();
    final One<Long> end = new One<>();
    final One<Integer> index = new One<>();
    final int COUNTER = 100;
    final BindPersonDataSource ds = BindPersonDataSource.instance();
    ds.openWritableDatabase();
    final List<Person> list = new ArrayList<Person>();
    for (int i = 0; i < ITEM_COUNTER; i++) {
        Person bean = new Person();
        bean.name = "name" + index.value0;
        bean.surname = "surname" + index.value0;
        list.add(bean);
    }
    start.value0 = System.currentTimeMillis();
    for (int i = 0; i < COUNTER; i++) {
        index.value0 = i;
        ds.execute(new Transaction() {

            @Override
            public TransactionResult onExecute(BindPersonDaoFactory daoFactory) {
                PersonDaoImpl dao = daoFactory.getPersonDao();
                for (int i = 0; i < list.size(); i++) {
                    dao.insert(list.get(i));
                }
                return TransactionResult.COMMIT;
            }
        });
    }
    end.value0 = System.currentTimeMillis();
    ds.close();
    // 3100
    System.out.println("Average time to insert " + ITEM_COUNTER + " items: " + ((end.value0 - start.value0) * 1.0 / COUNTER) + " ms");
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) One(com.abubusoft.kripton.common.One) BindPersonDaoFactory(sqlite.feature.speed.persistence.BindPersonDaoFactory) ArrayList(java.util.ArrayList) PersonDaoImpl(sqlite.feature.speed.persistence.PersonDaoImpl) Transaction(sqlite.feature.speed.persistence.BindPersonDataSource.Transaction) BindPersonDataSource(sqlite.feature.speed.persistence.BindPersonDataSource) Person(sqlite.feature.speed.model.Person) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with PersonDaoImpl

use of sqlite.feature.speed.persistence.PersonDaoImpl in project kripton by xcesco.

the class TestSpeedRuntime method testTransaction.

@Test
public void testTransaction() {
    final One<Long> start = new One<>();
    final One<Long> end = new One<>();
    final One<Integer> index = new One<>();
    final int COUNTER = 2000;
    final BindPersonDataSource ds = BindPersonDataSource.instance();
    ds.openWritableDatabase();
    start.value0 = System.currentTimeMillis();
    for (int i = 0; i < COUNTER; i++) {
        index.value0 = i;
        ds.execute(new Transaction() {

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

Example 3 with PersonDaoImpl

use of sqlite.feature.speed.persistence.PersonDaoImpl 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)

Aggregations

BaseAndroidTest (base.BaseAndroidTest)3 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)3 One (com.abubusoft.kripton.common.One)3 Test (org.junit.Test)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)1