Search in sources :

Example 1 with Child

use of sqlite.feature.jql.entities.Child in project kripton by xcesco.

the class DaoChildImpl method selectByParentId.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT _id, name, parent_id FROM child WHERE parent_id=${parentId}</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>parent_id</dt><dd>is associated to bean's property <strong>parentId</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${parentId}</dt><dd>is binded to method's parameter <strong>parentId</strong></dd>
 * </dl>
 *
 * @param parentId
 * 	is binded to <code>${parentId}</code>
 * @return collection of bean or empty collection.
 */
@Override
public List<Child> selectByParentId(long parentId) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_PARENT_ID_SQL4;
    // add where arguments
    _contentValues.addWhereArgs(String.valueOf(parentId));
    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<Child> resultList = new ArrayList<Child>(_cursor.getCount());
        Child resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("_id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("parent_id");
            do {
                resultBean = new Child();
                resultBean.id = _cursor.getLong(index0);
                resultBean.name = _cursor.getString(index1);
                if (!_cursor.isNull(index2)) {
                    resultBean.parentId = _cursor.getLong(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) Child(sqlite.feature.jql.entities.Child)

Example 2 with Child

use of sqlite.feature.jql.entities.Child in project kripton by xcesco.

the class DaoChildImpl method selectByParent.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>select * from child where parent_id in (select _id from person where _id=${parentId})</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>parent_id</dt><dd>is associated to bean's property <strong>parentId</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${parentId}</dt><dd>is binded to method's parameter <strong>parentId</strong></dd>
 * </dl>
 *
 * @param parentId
 * 	is binded to <code>${parentId}</code>
 * @return collection of bean or empty collection.
 */
@Override
public List<Child> selectByParent(long parentId) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_PARENT_SQL2;
    // add where arguments
    _contentValues.addWhereArgs(String.valueOf(parentId));
    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<Child> resultList = new ArrayList<Child>(_cursor.getCount());
        Child resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("_id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("parent_id");
            do {
                resultBean = new Child();
                resultBean.id = _cursor.getLong(index0);
                resultBean.name = _cursor.getString(index1);
                if (!_cursor.isNull(index2)) {
                    resultBean.parentId = _cursor.getLong(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) Child(sqlite.feature.jql.entities.Child)

Example 3 with Child

use of sqlite.feature.jql.entities.Child in project kripton by xcesco.

the class DaoChildImpl method selectAll.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT _id, name, parent_id FROM child</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>parent_id</dt><dd>is associated to bean's property <strong>parentId</strong></dd>
 * </dl>
 *
 * @return collection of bean or empty collection.
 */
@Override
public List<Child> selectAll() {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_ALL_SQL1;
    // 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<Child> resultList = new ArrayList<Child>(_cursor.getCount());
        Child resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("_id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("parent_id");
            do {
                resultBean = new Child();
                resultBean.id = _cursor.getLong(index0);
                resultBean.name = _cursor.getString(index1);
                if (!_cursor.isNull(index2)) {
                    resultBean.parentId = _cursor.getLong(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) Child(sqlite.feature.jql.entities.Child)

Example 4 with Child

use of sqlite.feature.jql.entities.Child 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)

Aggregations

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