Search in sources :

Example 26 with KriptonContentValues

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

the class DaoBean05Impl method deleteOne.

/**
 * <h2>SQL delete</h2>
 * <pre>DELETE FROM ws_bean WHERE pk=${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 (deleteOnePreparedStatement6 == null) {
        // generate static SQL for statement
        String _sql = "DELETE FROM ws_bean WHERE pk=?";
        deleteOnePreparedStatement6 = KriptonDatabaseWrapper.compile(_context, _sql);
    }
    KriptonContentValues _contentValues = contentValuesForUpdate(deleteOnePreparedStatement6);
    _contentValues.addWhereArgs(String.valueOf(id));
    // log section BEGIN
    if (_context.isLogEnabled()) {
        // display log
        Logger.info("DELETE FROM ws_bean WHERE pk=?");
        // 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(deleteOnePreparedStatement6, _contentValues);
    return result;
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues)

Example 27 with KriptonContentValues

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

the class UserDaoImpl method getUserById.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, user_name FROM user WHERE id = ${id}</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>
 *
 * <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 User getUserById(long id) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = GET_USER_BY_ID_SQL4;
    // 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
        User resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("user_name");
            resultBean = new User();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.userName = _cursor.getString(index1);
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor)

Example 28 with KriptonContentValues

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

the class UserDaoImpl method insert.

/**
 * <p>SQL insert:</p>
 * <pre>INSERT INTO user (user_name) VALUES (${user.userName})</pre>
 *
 * <p><code>user.id</code> is automatically updated because it is the primary key</p>
 *
 * <p><strong>Inserted columns:</strong></p>
 * <dl>
 * 	<dt>user_name</dt><dd>is mapped to <strong>${user.userName}</strong></dd>
 * </dl>
 *
 * @param user
 * 	is mapped to parameter <strong>user</strong>
 */
@Override
public void insert(User user) {
    if (insertPreparedStatement0 == null) {
        // generate static SQL for statement
        String _sql = "INSERT INTO user (user_name) VALUES (?)";
        insertPreparedStatement0 = KriptonDatabaseWrapper.compile(_context, _sql);
    }
    KriptonContentValues _contentValues = contentValuesForUpdate(insertPreparedStatement0);
    _contentValues.put("user_name", user.userName);
    // 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 user (%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(insertPreparedStatement0, _contentValues);
    user.id = result;
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues)

Example 29 with KriptonContentValues

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

the class DeviceDaoImpl method getAllDevices.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, name FROM device</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
 * </dl>
 *
 * @return collection of bean or empty collection.
 */
@Override
public List<Device> getAllDevices() {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = GET_ALL_DEVICES_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
        ArrayList<Device> resultList = new ArrayList<Device>(_cursor.getCount());
        Device resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            do {
                resultBean = new Device();
                resultBean.id = _cursor.getLong(index0);
                if (!_cursor.isNull(index1)) {
                    resultBean.name = _cursor.getString(index1);
                }
                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 30 with KriptonContentValues

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

the class DeviceDaoImpl method getUserDevices.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>select * from device inner join user_2_device on device.id = user_2_device.device_id  where user_2_device.user_id = ${userId}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</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<Device> getUserDevices(Long userId) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = GET_USER_DEVICES_SQL2;
    // add where arguments
    _contentValues.addWhereArgs((userId == null ? "" : 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<Device> resultList = new ArrayList<Device>(_cursor.getCount());
        Device resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            do {
                resultBean = new Device();
                resultBean.id = _cursor.getLong(index0);
                if (!_cursor.isNull(index1)) {
                    resultBean.name = _cursor.getString(index1);
                }
                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)

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