use of sqlite.feature.jql.entities.Person in project kripton by xcesco.
the class TestFeatJQLRuntime method testJQL1.
@Test
public void testJQL1() {
BindFamilyDataSource dataSource = BindFamilyDataSource.instance();
// transaction to insert elements
dataSource.execute(new BindFamilyDataSource.Transaction() {
@Override
public TransactionResult onExecute(BindFamilyDaoFactory daoFactory) {
// TODO Auto-generated method stub
Person person = new Person();
person.name = "Tonj Manero";
daoFactory.getDaoPerson().insertBean(person);
Child child = new Child();
child.name = "Luna";
child.parentId = person.id;
daoFactory.getDaoChild().insertBean(child);
daoFactory.getDaoChild().insertBean(child);
List<Child> list = daoFactory.getDaoChild().selectByParent(person.id);
assertTrue(2 == list.size());
for (int i = 0; i < list.size(); i++) {
assertTrue(list.get(i).name.equals("Luna"));
}
return TransactionResult.COMMIT;
}
});
}
use of sqlite.feature.jql.entities.Person in project kripton by xcesco.
the class DaoPersonImpl method selectAll.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT _id, name, image 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>image</dt><dd>is associated to bean's property <strong>image</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_SQL5;
// add where arguments
String[] _sqlArgs = _contentValues.whereArgsAsArray();
// log section BEGIN
if (_context.isLogEnabled()) {
// manage log
Logger.info(_sql);
// log for where parameters -- BEGIN
int _whereParamCounter = 0;
for (String _whereParamItem : _contentValues.whereArgs()) {
Logger.info("==> param%s: '%s'", (_whereParamCounter++), StringUtils.checkSize(_whereParamItem));
}
// log for where parameters -- END
}
// log section END
try (Cursor _cursor = database().rawQuery(_sql, _sqlArgs)) {
// log section BEGIN
if (_context.isLogEnabled()) {
Logger.info("Rows found: %s", _cursor.getCount());
}
// log section END
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("image");
do {
resultBean = new Person();
resultBean.id = _cursor.getLong(index0);
resultBean.name = _cursor.getString(index1);
if (!_cursor.isNull(index2)) {
resultBean.image = _cursor.getBlob(index2);
}
resultList.add(resultBean);
} while (_cursor.moveToNext());
}
return resultList;
}
}
Aggregations