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");
}
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");
}
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;
}
}
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;
}
}
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");
}
Aggregations