Search in sources :

Example 1 with Person

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;
        }
    });
}
Also used : BindFamilyDaoFactory(sqlite.feature.jql.persistence.BindFamilyDaoFactory) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) BindFamilyDataSource(sqlite.feature.jql.persistence.BindFamilyDataSource) List(java.util.List) Person(sqlite.feature.jql.entities.Person) Child(sqlite.feature.jql.entities.Child) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with Person

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;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Person(sqlite.feature.jql.entities.Person)

Aggregations

Person (sqlite.feature.jql.entities.Person)2 Cursor (android.database.Cursor)1 BaseAndroidTest (base.BaseAndroidTest)1 KriptonContentValues (com.abubusoft.kripton.android.sqlite.KriptonContentValues)1 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 Child (sqlite.feature.jql.entities.Child)1 BindFamilyDaoFactory (sqlite.feature.jql.persistence.BindFamilyDaoFactory)1 BindFamilyDataSource (sqlite.feature.jql.persistence.BindFamilyDataSource)1