Search in sources :

Example 1 with User

use of sqlite.quickstart.model.User in project kripton by xcesco.

the class TestQuickstartRuntime method testRunSqlite1.

@Test
public void testRunSqlite1() {
    BindQuickStartDataSource dataSource = BindQuickStartDataSource.instance();
    dataSource.execute(new BindQuickStartDataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindQuickStartDaoFactory daoFactory) {
            User user = new User();
            user.id = 1;
            user.name = "user";
            user.username = "username";
            daoFactory.getUserDao().insert(user);
            Post post = new Post();
            post.id = 2;
            post.title = "post";
            post.userId = user.id;
            daoFactory.getPostDao().insert(post);
            Comment comment = new Comment();
            comment.id = 3;
            comment.postId = post.id;
            daoFactory.getCommentDao().insert(comment);
            return TransactionResult.COMMIT;
        }
    });
}
Also used : Comment(sqlite.quickstart.model.Comment) BindQuickStartDataSource(sqlite.quickstart.persistence.BindQuickStartDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) User(sqlite.quickstart.model.User) Post(sqlite.quickstart.model.Post) BindQuickStartDaoFactory(sqlite.quickstart.persistence.BindQuickStartDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with User

use of sqlite.quickstart.model.User in project kripton by xcesco.

the class UserDaoImpl method selectAll.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, name, username, email, address, phone, website, company FROM user ORDER BY username asc</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>username</dt><dd>is associated to bean's property <strong>username</strong></dd>
 * 	<dt>email</dt><dd>is associated to bean's property <strong>email</strong></dd>
 * 	<dt>address</dt><dd>is associated to bean's property <strong>address</strong></dd>
 * 	<dt>phone</dt><dd>is associated to bean's property <strong>phone</strong></dd>
 * 	<dt>website</dt><dd>is associated to bean's property <strong>website</strong></dd>
 * 	<dt>company</dt><dd>is associated to bean's property <strong>company</strong></dd>
 * </dl>
 *
 * @return collection of bean or empty collection.
 */
@Override
public List<User> 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<User> resultList = new ArrayList<User>(_cursor.getCount());
        User resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("username");
            int index3 = _cursor.getColumnIndex("email");
            int index4 = _cursor.getColumnIndex("address");
            int index5 = _cursor.getColumnIndex("phone");
            int index6 = _cursor.getColumnIndex("website");
            int index7 = _cursor.getColumnIndex("company");
            do {
                resultBean = new User();
                resultBean.id = _cursor.getLong(index0);
                if (!_cursor.isNull(index1)) {
                    resultBean.name = _cursor.getString(index1);
                }
                if (!_cursor.isNull(index2)) {
                    resultBean.username = _cursor.getString(index2);
                }
                if (!_cursor.isNull(index3)) {
                    resultBean.email = _cursor.getString(index3);
                }
                if (!_cursor.isNull(index4)) {
                    resultBean.address = UserTable.parseAddress(_cursor.getBlob(index4));
                }
                if (!_cursor.isNull(index5)) {
                    resultBean.phone = _cursor.getString(index5);
                }
                if (!_cursor.isNull(index6)) {
                    resultBean.website = _cursor.getString(index6);
                }
                if (!_cursor.isNull(index7)) {
                    resultBean.company = UserTable.parseCompany(_cursor.getBlob(index7));
                }
                resultList.add(resultBean);
            } while (_cursor.moveToNext());
        }
        return resultList;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) User(sqlite.quickstart.model.User) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 3 with User

use of sqlite.quickstart.model.User in project kripton by xcesco.

the class UserDaoImpl method selectById.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, name, username, email, address, phone, website, company FROM user WHERE id = ${value}</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>username</dt><dd>is associated to bean's property <strong>username</strong></dd>
 * 	<dt>email</dt><dd>is associated to bean's property <strong>email</strong></dd>
 * 	<dt>address</dt><dd>is associated to bean's property <strong>address</strong></dd>
 * 	<dt>phone</dt><dd>is associated to bean's property <strong>phone</strong></dd>
 * 	<dt>website</dt><dd>is associated to bean's property <strong>website</strong></dd>
 * 	<dt>company</dt><dd>is associated to bean's property <strong>company</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${value}</dt><dd>is binded to method's parameter <strong>id</strong></dd>
 * </dl>
 *
 * @param id
 * 	is binded to <code>${value}</code>
 * @return selected bean or <code>null</code>.
 */
@Override
public User 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();
    // 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
        User resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("username");
            int index3 = _cursor.getColumnIndex("email");
            int index4 = _cursor.getColumnIndex("address");
            int index5 = _cursor.getColumnIndex("phone");
            int index6 = _cursor.getColumnIndex("website");
            int index7 = _cursor.getColumnIndex("company");
            resultBean = new User();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.name = _cursor.getString(index1);
            }
            if (!_cursor.isNull(index2)) {
                resultBean.username = _cursor.getString(index2);
            }
            if (!_cursor.isNull(index3)) {
                resultBean.email = _cursor.getString(index3);
            }
            if (!_cursor.isNull(index4)) {
                resultBean.address = UserTable.parseAddress(_cursor.getBlob(index4));
            }
            if (!_cursor.isNull(index5)) {
                resultBean.phone = _cursor.getString(index5);
            }
            if (!_cursor.isNull(index6)) {
                resultBean.website = _cursor.getString(index6);
            }
            if (!_cursor.isNull(index7)) {
                resultBean.company = UserTable.parseCompany(_cursor.getBlob(index7));
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) User(sqlite.quickstart.model.User) Cursor(android.database.Cursor)

Aggregations

User (sqlite.quickstart.model.User)3 Cursor (android.database.Cursor)2 KriptonContentValues (com.abubusoft.kripton.android.sqlite.KriptonContentValues)2 BaseAndroidTest (base.BaseAndroidTest)1 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Comment (sqlite.quickstart.model.Comment)1 Post (sqlite.quickstart.model.Post)1 BindQuickStartDaoFactory (sqlite.quickstart.persistence.BindQuickStartDaoFactory)1 BindQuickStartDataSource (sqlite.quickstart.persistence.BindQuickStartDataSource)1