use of sqlite.quickstart.model.Comment 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;
}
});
}
use of sqlite.quickstart.model.Comment in project kripton by xcesco.
the class CommentDaoImpl method selectByPostId.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT post_id, id, name, email, body FROM comment WHERE post_id = ${value}</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>post_id</dt><dd>is associated to bean's property <strong>postId</strong></dd>
* <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>email</dt><dd>is associated to bean's property <strong>email</strong></dd>
* <dt>body</dt><dd>is associated to bean's property <strong>body</strong></dd>
* </dl>
*
* <h2>Query's parameters:</h2>
* <dl>
* <dt>${value}</dt><dd>is binded to method's parameter <strong>postId</strong></dd>
* </dl>
*
* @param postId
* is binded to <code>${value}</code>
* @return collection of bean or empty collection.
*/
@Override
public List<Comment> selectByPostId(long postId) {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = SELECT_BY_POST_ID_SQL5;
// add where arguments
_contentValues.addWhereArgs(String.valueOf(postId));
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<Comment> resultList = new ArrayList<Comment>(_cursor.getCount());
Comment resultBean = null;
if (_cursor.moveToFirst()) {
int index0 = _cursor.getColumnIndex("post_id");
int index1 = _cursor.getColumnIndex("id");
int index2 = _cursor.getColumnIndex("name");
int index3 = _cursor.getColumnIndex("email");
int index4 = _cursor.getColumnIndex("body");
do {
resultBean = new Comment();
if (!_cursor.isNull(index0)) {
resultBean.postId = _cursor.getLong(index0);
}
resultBean.id = _cursor.getLong(index1);
if (!_cursor.isNull(index2)) {
resultBean.name = _cursor.getString(index2);
}
if (!_cursor.isNull(index3)) {
resultBean.email = _cursor.getString(index3);
}
if (!_cursor.isNull(index4)) {
resultBean.body = _cursor.getString(index4);
}
resultList.add(resultBean);
} while (_cursor.moveToNext());
}
return resultList;
}
}
use of sqlite.quickstart.model.Comment in project kripton by xcesco.
the class CommentDaoImpl method selectOneByPostId.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT post_id, id, name, email, body FROM comment WHERE id = ${value}</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>post_id</dt><dd>is associated to bean's property <strong>postId</strong></dd>
* <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>email</dt><dd>is associated to bean's property <strong>email</strong></dd>
* <dt>body</dt><dd>is associated to bean's property <strong>body</strong></dd>
* </dl>
*
* <h2>Query's parameters:</h2>
* <dl>
* <dt>${value}</dt><dd>is binded to method's parameter <strong>postId</strong></dd>
* </dl>
*
* @param postId
* is binded to <code>${value}</code>
* @return selected bean or <code>null</code>.
*/
@Override
public Comment selectOneByPostId(long postId) {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = SELECT_ONE_BY_POST_ID_SQL6;
// add where arguments
_contentValues.addWhereArgs(String.valueOf(postId));
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
Comment resultBean = null;
if (_cursor.moveToFirst()) {
int index0 = _cursor.getColumnIndex("post_id");
int index1 = _cursor.getColumnIndex("id");
int index2 = _cursor.getColumnIndex("name");
int index3 = _cursor.getColumnIndex("email");
int index4 = _cursor.getColumnIndex("body");
resultBean = new Comment();
if (!_cursor.isNull(index0)) {
resultBean.postId = _cursor.getLong(index0);
}
resultBean.id = _cursor.getLong(index1);
if (!_cursor.isNull(index2)) {
resultBean.name = _cursor.getString(index2);
}
if (!_cursor.isNull(index3)) {
resultBean.email = _cursor.getString(index3);
}
if (!_cursor.isNull(index4)) {
resultBean.body = _cursor.getString(index4);
}
}
return resultBean;
}
}
Aggregations