Search in sources :

Example 21 with KriptonContentValues

use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.

the class DaoBean03Impl method selectOne.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, text FROM bean03 WHERE id=${id}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>text</dt><dd>is associated to bean's property <strong>text</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${id}</dt><dd>is binded to method's parameter <strong>id</strong></dd>
 * </dl>
 *
 * @param id
 * 	is binded to <code>${id}</code>
 * @return selected bean or <code>null</code>.
 */
@Override
public Bean03 selectOne(long id) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_ONE_SQL1;
    // 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
        Bean03 resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("text");
            resultBean = new Bean03();
            resultBean.setId(_cursor.getLong(index0));
            if (!_cursor.isNull(index1)) {
                resultBean.setText(_cursor.getString(index1));
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 22 with KriptonContentValues

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 content=:content, text=:text WHERE pk=${uid} and creation_time=${valido} and creation_time=${validoIn}</pre>
 *
 * <h2>Updated columns:</h2>
 * <ul>
 * 	<li>content</li>
 * 	<li>text</li>
 * </ul>
 *
 * <h2>Where parameters:</h2>
 * <dl>
 * 	<dt>${uid}</dt><dd>is mapped to method's parameter <strong>uid</strong></dd>
 * 	<dt>${valido}</dt><dd>is mapped to method's parameter <strong>valido</strong></dd>
 * 	<dt>${validoIn}</dt><dd>is mapped to method's parameter <strong>validoIn</strong></dd>
 * </dl>
 *
 * @param content
 * 	is used as updated field <strong>content</strong>
 * @param text
 * 	is used as updated field <strong>text</strong>
 * @param uid
 * 	is used as where parameter <strong>${uid}</strong>
 * @param validoIn
 * 	is used as where parameter <strong>${validoIn}</strong>
 * @param valido
 * 	is used as where parameter <strong>${valido}</strong>
 *
 * @return number of updated records
 */
@Override
public long updateOne(byte[] content, String text, long uid, Date validoIn, Date valido) {
    if (updateOnePreparedStatement3 == null) {
        // generate static SQL for statement
        String _sql = "UPDATE ws_bean SET content=?, text=? WHERE pk=? and creation_time=? and creation_time=?";
        updateOnePreparedStatement3 = KriptonDatabaseWrapper.compile(_context, _sql);
    }
    KriptonContentValues _contentValues = contentValuesForUpdate(updateOnePreparedStatement3);
    _contentValues.put("content", content);
    _contentValues.put("text", text);
    _contentValues.addWhereArgs(String.valueOf(uid));
    _contentValues.addWhereArgs((valido == null ? "" : DateUtils.write(valido)));
    _contentValues.addWhereArgs((validoIn == null ? "" : DateUtils.write(validoIn)));
    // log section BEGIN
    if (_context.isLogEnabled()) {
        // display log
        Logger.info("UPDATE ws_bean SET content=:content, text=:text WHERE pk=? and creation_time=? 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(updateOnePreparedStatement3, _contentValues);
    return result;
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues)

Example 23 with KriptonContentValues

use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.

the class DaoBean05Impl method selectCount.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT count(*) FROM ws_bean WHERE text = ${text}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>count(*)</dt><dd>no bean's property is associated</dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${text}</dt><dd>is binded to method's parameter <strong>text</strong></dd>
 * </dl>
 *
 * @param text
 * 	is binded to <code>${text}</code>
 * @return single value extracted by query.
 */
@Override
public Long selectCount(String text) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_COUNT_SQL5;
    // add where arguments
    _contentValues.addWhereArgs((text == null ? "" : text));
    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
        Long result = null;
        if (_cursor.moveToFirst()) {
            if (_cursor.isNull(0)) {
                return null;
            }
            result = _cursor.getLong(0);
        }
        return result;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 24 with KriptonContentValues

use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.

the class DaoBean05Impl method selectCursorListener.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT pk, number, bean_type, text, content, creation_time FROM ws_bean WHERE pk=${id}</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>${id}</dt><dd>is binded to method's parameter <strong>id</strong></dd>
 * </dl>
 *
 * @param id
 * 	is binded to <code>${id}</code>
 * @param listener
 * 	is the cursor listener
 */
@Override
public void selectCursorListener(Long id, OnReadCursorListener listener) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_CURSOR_LISTENER_SQL6;
    // add where arguments
    _contentValues.addWhereArgs((id == null ? "" : 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());
        }
        if (_cursor.moveToFirst()) {
            do {
                listener.onRead(_cursor);
            } while (_cursor.moveToNext());
        }
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 25 with KriptonContentValues

use of com.abubusoft.kripton.android.sqlite.KriptonContentValues in project kripton by xcesco.

the class DaoBean05Impl method selectBeanListener.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT pk, number, bean_type, text, content, creation_time FROM ws_bean WHERE pk=${id}</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>${id}</dt><dd>is binded to method's parameter <strong>id</strong></dd>
 * </dl>
 *
 * @param id
 * 	is binded to <code>${id}</code>
 * @param listener
 * 	is the Bean05 listener
 */
@Override
public void selectBeanListener(Long id, OnReadBeanListener<Bean05> listener) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BEAN_LISTENER_SQL7;
    // add where arguments
    _contentValues.addWhereArgs((id == null ? "" : 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
        Bean05 resultBean = new Bean05();
        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");
            int rowCount = _cursor.getCount();
            do {
                // reset mapping
                // pk does not need reset
                resultBean.setNumber(0L);
                resultBean.setBeanType(null);
                resultBean.setText(null);
                resultBean.setContent(null);
                resultBean.setCreationTime(null);
                // generate mapping
                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)));
                }
                listener.onRead(resultBean, _cursor.getPosition(), rowCount);
            } while (_cursor.moveToNext());
        }
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Aggregations

KriptonContentValues (com.abubusoft.kripton.android.sqlite.KriptonContentValues)1293 Cursor (android.database.Cursor)574 ArrayList (java.util.ArrayList)174 BigInteger (java.math.BigInteger)70 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)68 BigDecimal (java.math.BigDecimal)68 TypeAdapterString (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterString)27 TypeAdapterByte (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByte)22 TypeAdapterByteArray (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByteArray)22 TypeAdapterChar (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterChar)22 TypeAdapterDouble (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterDouble)22 TypeAdapterFloat (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterFloat)22 TypeAdapterInteger (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterInteger)22 TypeAdapterLong (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterLong)22 TypeAdapterShort (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterShort)22 TypeAdapterBoolean (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterBoolean)19 Person (sqlite.feature.javadoc.Person)15 TypeAdapterAddress (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterAddress)15 Employee (sqlite.feature.typeadapter.kripton180.Employee)10 Person (sqlite.feature.contentprovider.kripton35.entities.Person)8