Search in sources :

Example 81 with KriptonContentValues

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

the class IntDaoImpl method selectList.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, value, value2 FROM int_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<IntBean> selectList(int[] value, Integer[] value2) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_LIST_SQL5;
    // add where arguments
    _contentValues.addWhereArgs((value == null ? "" : new String(serializer1(value), StandardCharsets.UTF_8)));
    _contentValues.addWhereArgs((value2 == null ? "" : new String(serializer2(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<IntBean> resultList = new ArrayList<IntBean>(_cursor.getCount());
        IntBean resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("value");
            int index2 = _cursor.getColumnIndex("value2");
            do {
                resultBean = new IntBean();
                resultBean.setId(_cursor.getLong(index0));
                if (!_cursor.isNull(index1)) {
                    resultBean.setValue(IntBeanTable.parseValue(_cursor.getBlob(index1)));
                }
                if (!_cursor.isNull(index2)) {
                    resultBean.setValue2(IntBeanTable.parseValue2(_cursor.getBlob(index2)));
                }
                resultList.add(resultBean);
            } while (_cursor.moveToNext());
        }
        return resultList;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 82 with KriptonContentValues

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

the class IntDaoImpl method selectOne.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, value, value2 FROM int_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(int[] value, Integer[] 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(serializer1(value), StandardCharsets.UTF_8)));
    _contentValues.addWhereArgs((value2 == null ? "" : new String(serializer2(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());
        }
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 83 with KriptonContentValues

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

the class IntDaoImpl method selectOne.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, value, value2 FROM int_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 selected bean or <code>null</code>.
 */
@Override
public IntBean selectOne(int[] value, Integer[] value2) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_ONE_SQL2;
    // add where arguments
    _contentValues.addWhereArgs((value == null ? "" : new String(serializer1(value), StandardCharsets.UTF_8)));
    _contentValues.addWhereArgs((value2 == null ? "" : new String(serializer2(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
        IntBean resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("value");
            int index2 = _cursor.getColumnIndex("value2");
            resultBean = new IntBean();
            resultBean.setId(_cursor.getLong(index0));
            if (!_cursor.isNull(index1)) {
                resultBean.setValue(IntBeanTable.parseValue(_cursor.getBlob(index1)));
            }
            if (!_cursor.isNull(index2)) {
                resultBean.setValue2(IntBeanTable.parseValue2(_cursor.getBlob(index2)));
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 84 with KriptonContentValues

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

the class IntDaoImpl method selectOne.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, value, value2 FROM int_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 IntBean listener
 */
@Override
public void selectOne(int[] value, Integer[] value2, OnReadBeanListener<IntBean> listener) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_ONE_SQL3;
    // add where arguments
    _contentValues.addWhereArgs((value == null ? "" : new String(serializer1(value), StandardCharsets.UTF_8)));
    _contentValues.addWhereArgs((value2 == null ? "" : new String(serializer2(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
        IntBean resultBean = new IntBean();
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("value");
            int index2 = _cursor.getColumnIndex("value2");
            int rowCount = _cursor.getCount();
            do {
                // reset mapping
                // id does not need reset
                resultBean.setValue(null);
                resultBean.setValue2(null);
                // generate mapping
                resultBean.setId(_cursor.getLong(index0));
                if (!_cursor.isNull(index1)) {
                    resultBean.setValue(IntBeanTable.parseValue(_cursor.getBlob(index1)));
                }
                if (!_cursor.isNull(index2)) {
                    resultBean.setValue2(IntBeanTable.parseValue2(_cursor.getBlob(index2)));
                }
                listener.onRead(resultBean, _cursor.getPosition(), rowCount);
            } while (_cursor.moveToNext());
        }
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 85 with KriptonContentValues

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

the class IntDaoImpl method delete.

/**
 * <h2>SQL delete</h2>
 * <pre>DELETE FROM int_bean WHERE value=${value} and value2=${value2}</pre>
 *
 * <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 value
 * 	is used as where parameter <strong>${value}</strong>
 * @param value2
 * 	is used as where parameter <strong>${value2}</strong>
 *
 * @return number of deleted records
 */
@Override
public long delete(int[] value, Integer[] value2) {
    if (deletePreparedStatement3 == null) {
        // generate static SQL for statement
        String _sql = "DELETE FROM int_bean WHERE value=? and value2=?";
        deletePreparedStatement3 = KriptonDatabaseWrapper.compile(_context, _sql);
    }
    KriptonContentValues _contentValues = contentValuesForUpdate(deletePreparedStatement3);
    _contentValues.addWhereArgs((value == null ? "" : new String(serializer1(value), StandardCharsets.UTF_8)));
    _contentValues.addWhereArgs((value2 == null ? "" : new String(serializer2(value2), StandardCharsets.UTF_8)));
    // log section BEGIN
    if (_context.isLogEnabled()) {
        // display log
        Logger.info("DELETE FROM int_bean WHERE value=? and value2=?");
        // 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(deletePreparedStatement3, _contentValues);
    return result;
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues)

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