Search in sources :

Example 1 with Person

use of sqlite.feature.speed.model.Person 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 Person

use of sqlite.feature.speed.model.Person 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 Person

use of sqlite.feature.speed.model.Person in project kripton by xcesco.

the class PersonDaoImpl method selectById.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, name, surname FROM person WHERE id=${id}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
 * 	<dt>surname</dt><dd>is associated to bean's property <strong>surname</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${id}</dt><dd>is binded to method's parameter <strong>id</strong></dd>
 * </dl>
 *
 * @param id
 * 	is binded to <code>${id}</code>
 * @return selected bean or <code>null</code>.
 */
@Override
public Person selectById(long id) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_ID_SQL2;
    // add where arguments
    _contentValues.addWhereArgs(String.valueOf(id));
    String[] _sqlArgs = _contentValues.whereArgsAsArray();
    try (Cursor _cursor = database().rawQuery(_sql, _sqlArgs)) {
        Person resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("surname");
            resultBean = new Person();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.name = _cursor.getString(index1);
            }
            if (!_cursor.isNull(index2)) {
                resultBean.surname = _cursor.getString(index2);
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor) Person(sqlite.feature.speed.model.Person)

Example 4 with Person

use of sqlite.feature.speed.model.Person in project kripton by xcesco.

the class PersonDaoImpl method selectAll.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, name, surname FROM person</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
 * 	<dt>surname</dt><dd>is associated to bean's property <strong>surname</strong></dd>
 * </dl>
 *
 * @return collection of bean or empty collection.
 */
@Override
public List<Person> selectAll() {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_ALL_SQL1;
    // add where arguments
    String[] _sqlArgs = _contentValues.whereArgsAsArray();
    try (Cursor _cursor = database().rawQuery(_sql, _sqlArgs)) {
        ArrayList<Person> resultList = new ArrayList<Person>(_cursor.getCount());
        Person resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("surname");
            do {
                resultBean = new Person();
                resultBean.id = _cursor.getLong(index0);
                if (!_cursor.isNull(index1)) {
                    resultBean.name = _cursor.getString(index1);
                }
                if (!_cursor.isNull(index2)) {
                    resultBean.surname = _cursor.getString(index2);
                }
                resultList.add(resultBean);
            } while (_cursor.moveToNext());
        }
        return resultList;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Person(sqlite.feature.speed.model.Person)

Example 5 with Person

use of sqlite.feature.speed.model.Person 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

Person (sqlite.feature.speed.model.Person)5 BaseAndroidTest (base.BaseAndroidTest)3 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)3 One (com.abubusoft.kripton.common.One)3 Test (org.junit.Test)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 Cursor (android.database.Cursor)2 KriptonContentValues (com.abubusoft.kripton.android.sqlite.KriptonContentValues)2 ArrayList (java.util.ArrayList)2