Search in sources :

Example 16 with KriptonContentValues

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

the class EmployeeRawDaoImpl method insertWithAdapter.

/**
 * <h2>SQL insert</h2>
 * <pre>INSERT INTO employees (field_boolean, field_byte, field_character, field_short, field_integer, field_long, field_float, field_double, field_string, field_byte_array) VALUES (${fieldBoolean}, ${fieldByte}, ${fieldCharacter}, ${fieldShort}, ${fieldInteger}, ${fieldLong}, ${fieldFloat}, ${fieldDouble}, ${fieldString}, ${fieldByteArray})</pre>
 *
 * <h2>Inserted columns:</strong></h2>
 * <dl>
 * 	<dt>fieldBoolean</dt><dd>is binded to query's parameter <strong>${fieldBoolean}</strong> and method's parameter <strong>fieldBoolean</strong></dd>
 * 	<dt>fieldByte</dt><dd>is binded to query's parameter <strong>${fieldByte}</strong> and method's parameter <strong>fieldByte</strong></dd>
 * 	<dt>fieldCharacter</dt><dd>is binded to query's parameter <strong>${fieldCharacter}</strong> and method's parameter <strong>fieldCharacter</strong></dd>
 * 	<dt>fieldShort</dt><dd>is binded to query's parameter <strong>${fieldShort}</strong> and method's parameter <strong>fieldShort</strong></dd>
 * 	<dt>fieldInteger</dt><dd>is binded to query's parameter <strong>${fieldInteger}</strong> and method's parameter <strong>fieldInteger</strong></dd>
 * 	<dt>fieldLong</dt><dd>is binded to query's parameter <strong>${fieldLong}</strong> and method's parameter <strong>fieldLong</strong></dd>
 * 	<dt>fieldFloat</dt><dd>is binded to query's parameter <strong>${fieldFloat}</strong> and method's parameter <strong>fieldFloat</strong></dd>
 * 	<dt>fieldDouble</dt><dd>is binded to query's parameter <strong>${fieldDouble}</strong> and method's parameter <strong>fieldDouble</strong></dd>
 * 	<dt>fieldString</dt><dd>is binded to query's parameter <strong>${fieldString}</strong> and method's parameter <strong>fieldString</strong></dd>
 * 	<dt>fieldByteArray</dt><dd>is binded to query's parameter <strong>${fieldByteArray}</strong> and method's parameter <strong>fieldByteArray</strong></dd>
 * </dl>
 *
 * @param fieldBoolean
 * 	is binded to column value <strong>field_boolean</strong>
 * @param fieldByte
 * 	is binded to column value <strong>field_byte</strong>
 * @param fieldCharacter
 * 	is binded to column value <strong>field_character</strong>
 * @param fieldShort
 * 	is binded to column value <strong>field_short</strong>
 * @param fieldInteger
 * 	is binded to column value <strong>field_integer</strong>
 * @param fieldLong
 * 	is binded to column value <strong>field_long</strong>
 * @param fieldFloat
 * 	is binded to column value <strong>field_float</strong>
 * @param fieldDouble
 * 	is binded to column value <strong>field_double</strong>
 * @param fieldString
 * 	is binded to column value <strong>field_string</strong>
 * @param fieldByteArray
 * 	is binded to column value <strong>field_byte_array</strong>
 *
 * @return <strong>id</strong> of inserted record
 */
@Override
public long insertWithAdapter(String fieldBoolean, String fieldByte, String fieldCharacter, String fieldShort, String fieldInteger, String fieldLong, String fieldFloat, String fieldDouble, String fieldString, String fieldByteArray) {
    if (insertWithAdapterPreparedStatement1 == null) {
        // generate static SQL for statement
        String _sql = "INSERT INTO employees (field_boolean, field_byte, field_character, field_short, field_integer, field_long, field_float, field_double, field_string, field_byte_array) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        insertWithAdapterPreparedStatement1 = KriptonDatabaseWrapper.compile(_context, _sql);
    }
    KriptonContentValues _contentValues = contentValuesForUpdate(insertWithAdapterPreparedStatement1);
    _contentValues.put("field_boolean", SQLTypeAdapterUtils.toData(TypeAdapterBoolean.class, fieldBoolean));
    _contentValues.put("field_byte", SQLTypeAdapterUtils.toData(TypeAdapterByte.class, fieldByte));
    _contentValues.put("field_character", SQLTypeAdapterUtils.toData(TypeAdapterChar.class, fieldCharacter));
    _contentValues.put("field_short", SQLTypeAdapterUtils.toData(TypeAdapterShort.class, fieldShort));
    _contentValues.put("field_integer", SQLTypeAdapterUtils.toData(TypeAdapterInteger.class, fieldInteger));
    _contentValues.put("field_long", SQLTypeAdapterUtils.toData(TypeAdapterLong.class, fieldLong));
    _contentValues.put("field_float", SQLTypeAdapterUtils.toData(TypeAdapterFloat.class, fieldFloat));
    _contentValues.put("field_double", SQLTypeAdapterUtils.toData(TypeAdapterDouble.class, fieldDouble));
    _contentValues.put("field_string", SQLTypeAdapterUtils.toData(TypeAdapterString.class, fieldString));
    _contentValues.put("field_byte_array", SQLTypeAdapterUtils.toData(TypeAdapterByteArray.class, fieldByteArray));
    // 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 employees (%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(insertWithAdapterPreparedStatement1, _contentValues);
    return result;
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) TypeAdapterInteger(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterInteger) TypeAdapterChar(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterChar) TypeAdapterString(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterString) TypeAdapterShort(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterShort) TypeAdapterFloat(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterFloat) TypeAdapterBoolean(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterBoolean) TypeAdapterLong(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterLong) TypeAdapterByteArray(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByteArray) TypeAdapterDouble(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterDouble) TypeAdapterByte(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByte) TypeAdapterString(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterString)

Example 17 with KriptonContentValues

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

the class DaoBean01Impl method selectOne.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT temp, id, text FROM bean01 WHERE id=${id}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>temp</dt><dd>is associated to bean's property <strong>temp</strong></dd>
 * 	<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 Bean01 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
        Bean01 resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("temp");
            int index1 = _cursor.getColumnIndex("id");
            int index2 = _cursor.getColumnIndex("text");
            resultBean = new Bean01();
            if (!_cursor.isNull(index0)) {
                resultBean.temp = Bean01Table.parseTemp(_cursor.getBlob(index0));
            }
            resultBean.setId(_cursor.getLong(index1));
            if (!_cursor.isNull(index2)) {
                resultBean.setText(_cursor.getString(index2));
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 18 with KriptonContentValues

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;
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues)

Example 19 with KriptonContentValues

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

the class DaoBean02Impl method selectOne.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, text FROM bean02 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 Bean02 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
        Bean02 resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("text");
            resultBean = new Bean02();
            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 20 with KriptonContentValues

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

the class DaoBean03Impl method deleteOne.

/**
 * <h2>SQL delete</h2>
 * <pre>DELETE FROM bean03 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 bean03 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 bean03 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;
}
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