use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class ByteDaoImpl method updateOne.
/**
* <h2>SQL update</h2>
* <pre>UPDATE byte_bean SET id=:id WHERE value=${value} and value2=${value2}</pre>
*
* <h2>Updated columns:</h2>
* <ul>
* <li>id</li>
* </ul>
*
* <h2>Where parameters:</h2>
* <dl>
* <dt>${value}</dt><dd>is mapped to method's parameter <strong>value</strong></dd>
* <dt>${value2}</dt><dd>is mapped to method's parameter <strong>value2</strong></dd>
* </dl>
*
* @param id
* is used as updated field <strong>id</strong>
* @param value
* is used as where parameter <strong>${value}</strong>
* @param value2
* is used as where parameter <strong>${value2}</strong>
*
* @return number of updated records
*/
@Override
public long updateOne(long id, byte[] value, Byte[] value2) {
if (updateOnePreparedStatement0 == null) {
// generate static SQL for statement
String _sql = "UPDATE byte_bean SET id=? WHERE value=? and value2=?";
updateOnePreparedStatement0 = KriptonDatabaseWrapper.compile(_context, _sql);
}
KriptonContentValues _contentValues = contentValuesForUpdate(updateOnePreparedStatement0);
_contentValues.put("id", id);
_contentValues.addWhereArgs((value == null ? "" : new String(value, StandardCharsets.UTF_8)));
_contentValues.addWhereArgs((value2 == null ? "" : new String(serializer1(value2), StandardCharsets.UTF_8)));
// log section BEGIN
if (_context.isLogEnabled()) {
// display log
Logger.info("UPDATE byte_bean SET id=:id WHERE value=? and value2=?");
// 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(updateOnePreparedStatement0, _contentValues);
return result;
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class ByteDaoImpl method selectOne.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT id, value, value2 FROM byte_bean</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
* <dt>value</dt><dd>is associated to bean's property <strong>value</strong></dd>
* <dt>value2</dt><dd>is associated to bean's property <strong>value2</strong></dd>
* </dl>
*
* @return selected bean or <code>null</code>.
*/
@Override
public ByteBean selectOne() {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = SELECT_ONE_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
ByteBean resultBean = null;
if (_cursor.moveToFirst()) {
int index0 = _cursor.getColumnIndex("id");
int index1 = _cursor.getColumnIndex("value");
int index2 = _cursor.getColumnIndex("value2");
resultBean = new ByteBean();
resultBean.setId(_cursor.getLong(index0));
if (!_cursor.isNull(index1)) {
resultBean.setValue(_cursor.getBlob(index1));
}
if (!_cursor.isNull(index2)) {
resultBean.setValue2(ByteBeanTable.parseValue2(_cursor.getBlob(index2)));
}
}
return resultBean;
}
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class ByteDaoImpl method selectList.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT id, value, value2 FROM byte_bean WHERE value=${value} and value2=${value2}</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
* <dt>value</dt><dd>is associated to bean's property <strong>value</strong></dd>
* <dt>value2</dt><dd>is associated to bean's property <strong>value2</strong></dd>
* </dl>
*
* <h2>Query's parameters:</h2>
* <dl>
* <dt>${value}</dt><dd>is binded to method's parameter <strong>value</strong></dd>
* <dt>${value2}</dt><dd>is binded to method's parameter <strong>value2</strong></dd>
* </dl>
*
* @param value
* is binded to <code>${value}</code>
* @param value2
* is binded to <code>${value2}</code>
* @return collection of bean or empty collection.
*/
@Override
public List<ByteBean> selectList(byte[] value, Byte[] value2) {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = SELECT_LIST_SQL5;
// add where arguments
_contentValues.addWhereArgs((value == null ? "" : new String(value, StandardCharsets.UTF_8)));
_contentValues.addWhereArgs((value2 == null ? "" : new String(serializer1(value2), StandardCharsets.UTF_8)));
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<ByteBean> resultList = new ArrayList<ByteBean>(_cursor.getCount());
ByteBean resultBean = null;
if (_cursor.moveToFirst()) {
int index0 = _cursor.getColumnIndex("id");
int index1 = _cursor.getColumnIndex("value");
int index2 = _cursor.getColumnIndex("value2");
do {
resultBean = new ByteBean();
resultBean.setId(_cursor.getLong(index0));
if (!_cursor.isNull(index1)) {
resultBean.setValue(_cursor.getBlob(index1));
}
if (!_cursor.isNull(index2)) {
resultBean.setValue2(ByteBeanTable.parseValue2(_cursor.getBlob(index2)));
}
resultList.add(resultBean);
} while (_cursor.moveToNext());
}
return resultList;
}
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class ByteDaoImpl method selectOne.
/**
* <h2>Select SQL:</h2>
*
* <pre>SELECT id, value, value2 FROM byte_bean WHERE value=${value} and value2=${value2}</pre>
*
* <h2>Projected columns:</h2>
* <dl>
* <dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
* <dt>value</dt><dd>is associated to bean's property <strong>value</strong></dd>
* <dt>value2</dt><dd>is associated to bean's property <strong>value2</strong></dd>
* </dl>
*
* <h2>Query's parameters:</h2>
* <dl>
* <dt>${value}</dt><dd>is binded to method's parameter <strong>value</strong></dd>
* <dt>${value2}</dt><dd>is binded to method's parameter <strong>value2</strong></dd>
* </dl>
*
* @param value
* is binded to <code>${value}</code>
* @param value2
* is binded to <code>${value2}</code>
* @param listener
* is the cursor listener
*/
@Override
public void selectOne(byte[] value, Byte[] value2, OnReadCursorListener listener) {
KriptonContentValues _contentValues = contentValues();
// query SQL is statically defined
String _sql = SELECT_ONE_SQL4;
// add where arguments
_contentValues.addWhereArgs((value == null ? "" : new String(value, StandardCharsets.UTF_8)));
_contentValues.addWhereArgs((value2 == null ? "" : new String(serializer1(value2), StandardCharsets.UTF_8)));
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());
}
if (_cursor.moveToFirst()) {
do {
listener.onRead(_cursor);
} while (_cursor.moveToNext());
}
}
}
use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.
the class ByteDaoImpl method insert.
/**
* <p>SQL insert:</p>
* <pre>INSERT INTO byte_bean (value, value2) VALUES (${bean.value}, ${bean.value2})</pre>
*
* <p><code>bean.id</code> is automatically updated because it is the primary key</p>
*
* <p><strong>Inserted columns:</strong></p>
* <dl>
* <dt>value</dt><dd>is mapped to <strong>${bean.value}</strong></dd>
* <dt>value2</dt><dd>is mapped to <strong>${bean.value2}</strong></dd>
* </dl>
*
* @param bean
* is mapped to parameter <strong>bean</strong>
*
* @return <strong>id</strong> of inserted record
*/
@Override
public long insert(ByteBean bean) {
if (insertPreparedStatement2 == null) {
// generate static SQL for statement
String _sql = "INSERT INTO byte_bean (value, value2) VALUES (?, ?)";
insertPreparedStatement2 = KriptonDatabaseWrapper.compile(_context, _sql);
}
KriptonContentValues _contentValues = contentValuesForUpdate(insertPreparedStatement2);
_contentValues.put("value", bean.getValue());
_contentValues.put("value2", ByteBeanTable.serializeValue2(bean.getValue2()));
// log section BEGIN
if (_context.isLogEnabled()) {
// log for insert -- BEGIN
StringBuffer _columnNameBuffer = new StringBuffer();
StringBuffer _columnValueBuffer = new StringBuffer();
String _columnSeparator = "";
for (String columnName : _contentValues.keys()) {
_columnNameBuffer.append(_columnSeparator + columnName);
_columnValueBuffer.append(_columnSeparator + ":" + columnName);
_columnSeparator = ", ";
}
Logger.info("INSERT INTO byte_bean (%s) VALUES (%s)", _columnNameBuffer.toString(), _columnValueBuffer.toString());
// 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 insert -- 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
// insert operation
long result = KriptonDatabaseWrapper.insert(insertPreparedStatement2, _contentValues);
bean.setId(result);
return result;
}
Aggregations