use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class UserDaoImpl method getAllUsers.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT id, user_name FROM user</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
* <dt>user_name</dt><dd>is associated to bean's property <strong>userName</strong></dd>
* </dl>
*
* @return collection of bean or empty collection.
*/
@Override
public List<User> getAllUsers() {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = GET_ALL_USERS_SQL3;
// 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("user_name");
do {
resultBean = new User();
resultBean.id = _cursor.getLong(index0);
if (!_cursor.isNull(index1)) {
resultBean.userName = _cursor.getString(index1);
}
resultList.add(resultBean);
} while (_cursor.moveToNext());
}
return resultList;
}
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class UserDeviceDaoImpl method selectByUserId.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT id, user_id, device_id FROM user_2_device WHERE user_id=${userId}</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
* <dt>user_id</dt><dd>is associated to bean's property <strong>userId</strong></dd>
* <dt>device_id</dt><dd>is associated to bean's property <strong>deviceId</strong></dd>
* </dl>
*
* <h2>Query's parameters:</h2>
* <dl>
* <dt>${userId}</dt><dd>is binded to method's parameter <strong>userId</strong></dd>
* </dl>
*
* @param userId
* is binded to <code>${userId}</code>
* @return collection of bean or empty collection.
*/
@Override
public List<UserDevice> selectByUserId(long userId) {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = SELECT_BY_USER_ID_SQL6;
// add where arguments
_contentValues.addWhereArgs(String.valueOf(userId));
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<UserDevice> resultList = new ArrayList<UserDevice>(_cursor.getCount());
UserDevice resultBean = null;
if (_cursor.moveToFirst()) {
int index0 = _cursor.getColumnIndex("id");
int index1 = _cursor.getColumnIndex("user_id");
int index2 = _cursor.getColumnIndex("device_id");
do {
resultBean = new UserDevice();
resultBean.id = _cursor.getLong(index0);
if (!_cursor.isNull(index1)) {
resultBean.userId = _cursor.getLong(index1);
}
if (!_cursor.isNull(index2)) {
resultBean.deviceId = _cursor.getLong(index2);
}
resultList.add(resultBean);
} while (_cursor.moveToNext());
}
return resultList;
}
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class DaoBean02Impl method deleteOne.
/**
* <h2>SQL delete</h2>
* <pre>DELETE FROM bean02 WHERE id=${id}</pre>
*
* <h2>Where parameters:</h2>
* <dl>
* <dt>${id}</dt><dd>is mapped to method's parameter <strong>id</strong></dd>
* </dl>
*
* @param id
* is used as where parameter <strong>${id}</strong>
*
* @return number of deleted records
*/
@Override
public long deleteOne(long id) {
if (deleteOnePreparedStatement0 == null) {
// generate static SQL for statement
String _sql = "DELETE FROM bean02 WHERE id=?";
deleteOnePreparedStatement0 = KriptonDatabaseWrapper.compile(_context, _sql);
}
KriptonContentValues _contentValues = contentValuesForUpdate(deleteOnePreparedStatement0);
_contentValues.addWhereArgs(String.valueOf(id));
// log section BEGIN
if (_context.isLogEnabled()) {
// display log
Logger.info("DELETE FROM bean02 WHERE id=?");
// 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
int result = KriptonDatabaseWrapper.updateDelete(deleteOnePreparedStatement0, _contentValues);
return result;
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class DaoBean05Impl method updateOne.
/**
* <h2>SQL update:</h2>
* <pre>UPDATE ws_bean SET number=:number, bean_type=:beanType, text=:text, content=:content, creation_time=:creationTime WHERE pk=${bean.pk} and text=${bean.text} and creation_time=${bean.creationTime}</pre>
*
* <h2>Updated columns:</h2>
* <dl>
* <dt>number</dt><dd>is mapped to <strong>${bean.number}</strong></dd>
* <dt>bean_type</dt><dd>is mapped to <strong>${bean.beanType}</strong></dd>
* <dt>text</dt><dd>is mapped to <strong>${bean.text}</strong></dd>
* <dt>content</dt><dd>is mapped to <strong>${bean.content}</strong></dd>
* <dt>creation_time</dt><dd>is mapped to <strong>${bean.creationTime}</strong></dd>
* </dl>
*
* <h2>Parameters used in where conditions:</h2>
* <dl>
* <dt>${bean.pk}</dt><dd>is mapped to method's parameter <strong>bean.pk</strong></dd>
* <dt>${bean.text}</dt><dd>is mapped to method's parameter <strong>bean.text</strong></dd>
* <dt>${bean.creationTime}</dt><dd>is mapped to method's parameter <strong>bean.creationTime</strong></dd>
* </dl>
*
* @param bean
* is used as ${bean}
*
* @return number of updated records
*/
@Override
public long updateOne(Bean05 bean) {
if (updateOnePreparedStatement2 == null) {
// generate static SQL for statement
String _sql = "UPDATE ws_bean SET number=?, bean_type=?, text=?, content=?, creation_time=? WHERE pk=? and text=? and creation_time=?";
updateOnePreparedStatement2 = KriptonDatabaseWrapper.compile(_context, _sql);
}
KriptonContentValues _contentValues = contentValuesForUpdate(updateOnePreparedStatement2);
_contentValues.put("number", bean.getNumber());
_contentValues.put("bean_type", EnumUtils.write(bean.getBeanType()));
_contentValues.put("text", bean.getText());
_contentValues.put("content", bean.getContent());
_contentValues.put("creation_time", DateUtils.write(bean.getCreationTime()));
_contentValues.addWhereArgs(String.valueOf(bean.getPk()));
_contentValues.addWhereArgs((bean.getText() == null ? "" : bean.getText()));
_contentValues.addWhereArgs((bean.getCreationTime() == null ? "" : DateUtils.write(bean.getCreationTime())));
// log section BEGIN
if (_context.isLogEnabled()) {
// display log
Logger.info("UPDATE ws_bean SET number=:number, bean_type=:bean_type, text=:text, content=:content, creation_time=:creation_time WHERE pk=? and text=? and creation_time=?");
// log for content values -- BEGIN
Triple<String, Object, KriptonContentValues.ParamType> _contentValue;
for (int i = 0; i < _contentValues.size(); i++) {
_contentValue = _contentValues.get(i);
if (_contentValue.value1 == null) {
Logger.info("==> :%s = <null>", _contentValue.value0);
} else {
Logger.info("==> :%s = '%s' (%s)", _contentValue.value0, StringUtils.checkSize(_contentValue.value1), _contentValue.value1.getClass().getCanonicalName());
}
}
// log for content values -- END
// 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
int result = KriptonDatabaseWrapper.updateDelete(updateOnePreparedStatement2, _contentValues);
return result;
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class DaoBean05Impl method selectOne.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT pk, number, bean_type, text, content, creation_time FROM ws_bean WHERE pk=${bean.pk} and text=${bean.text}</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>pk</dt><dd>is associated to bean's property <strong>pk</strong></dd>
* <dt>number</dt><dd>is associated to bean's property <strong>number</strong></dd>
* <dt>bean_type</dt><dd>is associated to bean's property <strong>beanType</strong></dd>
* <dt>text</dt><dd>is associated to bean's property <strong>text</strong></dd>
* <dt>content</dt><dd>is associated to bean's property <strong>content</strong></dd>
* <dt>creation_time</dt><dd>is associated to bean's property <strong>creationTime</strong></dd>
* </dl>
*
* <h2>Query's parameters:</h2>
* <dl>
* <dt>${bean.pk}</dt><dd>is binded to method's parameter <strong>bean.pk</strong></dd>
* <dt>${bean.text}</dt><dd>is binded to method's parameter <strong>bean.text</strong></dd>
* </dl>
*
* @param bean
* is used as ${bean}
* @return selected bean or <code>null</code>.
*/
@Override
public Bean05 selectOne(Bean05 bean) {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = SELECT_ONE_SQL2;
// add where arguments
_contentValues.addWhereArgs(String.valueOf(bean.getPk()));
_contentValues.addWhereArgs(bean.getText());
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
Bean05 resultBean = null;
if (_cursor.moveToFirst()) {
int index0 = _cursor.getColumnIndex("pk");
int index1 = _cursor.getColumnIndex("number");
int index2 = _cursor.getColumnIndex("bean_type");
int index3 = _cursor.getColumnIndex("text");
int index4 = _cursor.getColumnIndex("content");
int index5 = _cursor.getColumnIndex("creation_time");
resultBean = new Bean05();
resultBean.setPk(_cursor.getLong(index0));
if (!_cursor.isNull(index1)) {
resultBean.setNumber(_cursor.getLong(index1));
}
if (!_cursor.isNull(index2)) {
resultBean.setBeanType(BeanType.valueOf(_cursor.getString(index2)));
}
if (!_cursor.isNull(index3)) {
resultBean.setText(_cursor.getString(index3));
}
if (!_cursor.isNull(index4)) {
resultBean.setContent(_cursor.getBlob(index4));
}
if (!_cursor.isNull(index5)) {
resultBean.setCreationTime(DateUtils.read(_cursor.getString(index5)));
}
}
return resultBean;
}
}
Aggregations