Search in sources :

Example 11 with Employee

use of sqlite.feature.typeadapter.kripton180.Employee in project kripton by xcesco.

the class EmployeeBeanDaoImpl method update.

/**
 * <h2>SQL update:</h2>
 * <pre>UPDATE employees SET last_name=:lastName, first_name=:firstName, birth_date=:birthDate, hire_date=:hireDate, address=:address, field_boolean=:fieldBoolean, field_byte=:fieldByte, field_character=:fieldCharacter, field_short=:fieldShort, field_integer=:fieldInteger, field_long=:fieldLong, field_float=:fieldFloat, field_double=:fieldDouble, field_string=:fieldString, field_byte_array=:fieldByteArray WHERE id=${bean.id} and field_byte=${bean.fieldByte} and field_character=${bean.fieldCharacter} and field_short=${bean.fieldShort} and field_integer=${bean.fieldInteger} and field_long=${bean.fieldLong} and field_float=${bean.fieldFloat} and field_double=${bean.fieldDouble} and field_string=${bean.fieldString} and field_byte_array=${bean.fieldByteArray}</pre>
 *
 * <h2>Updated columns:</h2>
 * <dl>
 * 	<dt>last_name</dt><dd>is mapped to <strong>${bean.lastName}</strong></dd>
 * 	<dt>first_name</dt><dd>is mapped to <strong>${bean.firstName}</strong></dd>
 * 	<dt>birth_date</dt><dd>is mapped to <strong>${bean.birthDate}</strong></dd>
 * 	<dt>hire_date</dt><dd>is mapped to <strong>${bean.hireDate}</strong></dd>
 * 	<dt>address</dt><dd>is mapped to <strong>${bean.address}</strong></dd>
 * 	<dt>field_boolean</dt><dd>is mapped to <strong>${bean.fieldBoolean}</strong></dd>
 * 	<dt>field_byte</dt><dd>is mapped to <strong>${bean.fieldByte}</strong></dd>
 * 	<dt>field_character</dt><dd>is mapped to <strong>${bean.fieldCharacter}</strong></dd>
 * 	<dt>field_short</dt><dd>is mapped to <strong>${bean.fieldShort}</strong></dd>
 * 	<dt>field_integer</dt><dd>is mapped to <strong>${bean.fieldInteger}</strong></dd>
 * 	<dt>field_long</dt><dd>is mapped to <strong>${bean.fieldLong}</strong></dd>
 * 	<dt>field_float</dt><dd>is mapped to <strong>${bean.fieldFloat}</strong></dd>
 * 	<dt>field_double</dt><dd>is mapped to <strong>${bean.fieldDouble}</strong></dd>
 * 	<dt>field_string</dt><dd>is mapped to <strong>${bean.fieldString}</strong></dd>
 * 	<dt>field_byte_array</dt><dd>is mapped to <strong>${bean.fieldByteArray}</strong></dd>
 * </dl>
 *
 * <h2>Parameters used in where conditions:</h2>
 * <dl>
 * 	<dt>${bean.id}</dt><dd>is mapped to method's parameter <strong>bean.id</strong></dd>
 * 	<dt>${bean.fieldByte}</dt><dd>is mapped to method's parameter <strong>bean.fieldByte</strong></dd>
 * 	<dt>${bean.fieldCharacter}</dt><dd>is mapped to method's parameter <strong>bean.fieldCharacter</strong></dd>
 * 	<dt>${bean.fieldShort}</dt><dd>is mapped to method's parameter <strong>bean.fieldShort</strong></dd>
 * 	<dt>${bean.fieldInteger}</dt><dd>is mapped to method's parameter <strong>bean.fieldInteger</strong></dd>
 * 	<dt>${bean.fieldLong}</dt><dd>is mapped to method's parameter <strong>bean.fieldLong</strong></dd>
 * 	<dt>${bean.fieldFloat}</dt><dd>is mapped to method's parameter <strong>bean.fieldFloat</strong></dd>
 * 	<dt>${bean.fieldDouble}</dt><dd>is mapped to method's parameter <strong>bean.fieldDouble</strong></dd>
 * 	<dt>${bean.fieldString}</dt><dd>is mapped to method's parameter <strong>bean.fieldString</strong></dd>
 * 	<dt>${bean.fieldByteArray}</dt><dd>is mapped to method's parameter <strong>bean.fieldByteArray</strong></dd>
 * </dl>
 *
 * @param bean
 * 	is used as ${bean}
 *
 * @return number of updated records
 */
@Override
public long update(Employee bean) {
    if (updatePreparedStatement2 == null) {
        // generate static SQL for statement
        String _sql = "UPDATE employees SET last_name=?, first_name=?, birth_date=?, hire_date=?, address=?, field_boolean=?, field_byte=?, field_character=?, field_short=?, field_integer=?, field_long=?, field_float=?, field_double=?, field_string=?, field_byte_array=? WHERE id=? and field_byte=? and field_character=? and field_short=? and field_integer=? and field_long=? and field_float=? and field_double=? and field_string=? and field_byte_array=?";
        updatePreparedStatement2 = KriptonDatabaseWrapper.compile(_context, _sql);
    }
    KriptonContentValues _contentValues = contentValuesForUpdate(updatePreparedStatement2);
    _contentValues.put("last_name", bean.lastName);
    _contentValues.put("first_name", bean.firstName);
    _contentValues.put("birth_date", SQLDateUtils.write(bean.birthDate));
    _contentValues.put("hire_date", SQLDateUtils.write(bean.hireDate));
    _contentValues.put("address", SQLTypeAdapterUtils.toData(TypeAdapterAddress.class, bean.address));
    _contentValues.put("field_boolean", SQLTypeAdapterUtils.toData(TypeAdapterBoolean.class, bean.fieldBoolean));
    _contentValues.put("field_byte", SQLTypeAdapterUtils.toData(TypeAdapterByte.class, bean.fieldByte));
    _contentValues.put("field_character", SQLTypeAdapterUtils.toData(TypeAdapterChar.class, bean.fieldCharacter));
    _contentValues.put("field_short", SQLTypeAdapterUtils.toData(TypeAdapterShort.class, bean.fieldShort));
    _contentValues.put("field_integer", SQLTypeAdapterUtils.toData(TypeAdapterInteger.class, bean.fieldInteger));
    _contentValues.put("field_long", SQLTypeAdapterUtils.toData(TypeAdapterLong.class, bean.fieldLong));
    _contentValues.put("field_float", SQLTypeAdapterUtils.toData(TypeAdapterFloat.class, bean.fieldFloat));
    _contentValues.put("field_double", SQLTypeAdapterUtils.toData(TypeAdapterDouble.class, bean.fieldDouble));
    _contentValues.put("field_string", SQLTypeAdapterUtils.toData(TypeAdapterString.class, bean.fieldString));
    _contentValues.put("field_byte_array", SQLTypeAdapterUtils.toData(TypeAdapterByteArray.class, bean.fieldByteArray));
    _contentValues.addWhereArgs(String.valueOf(bean.id));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterByte.class, bean.fieldByte));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterChar.class, bean.fieldCharacter));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterShort.class, bean.fieldShort));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterInteger.class, bean.fieldInteger));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterLong.class, bean.fieldLong));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterFloat.class, bean.fieldFloat));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterDouble.class, bean.fieldDouble));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterString.class, bean.fieldString));
    _contentValues.addWhereArgs(SQLTypeAdapterUtils.toString(TypeAdapterByteArray.class, bean.fieldByteArray));
    // log section BEGIN
    if (_context.isLogEnabled()) {
        // display log
        Logger.info("UPDATE employees SET last_name=:last_name, first_name=:first_name, birth_date=:birth_date, hire_date=:hire_date, address=:address, field_boolean=:field_boolean, field_byte=:field_byte, field_character=:field_character, field_short=:field_short, field_integer=:field_integer, field_long=:field_long, field_float=:field_float, field_double=:field_double, field_string=:field_string, field_byte_array=:field_byte_array WHERE id=? and field_byte=? and field_character=? and field_short=? and field_integer=? and field_long=? and field_float=? and field_double=? and field_string=? and field_byte_array=?");
        // 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(updatePreparedStatement2, _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) TypeAdapterAddress(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterAddress) TypeAdapterByte(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByte) TypeAdapterString(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterString)

Example 12 with Employee

use of sqlite.feature.typeadapter.kripton180.Employee in project kripton by xcesco.

the class EmployeeBeanInsertSelectDaoImpl method insertJQL.

/**
 * <p>SQL insert:</p>
 * <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) select field_boolean, field_byte, field_character, field_short, field_integer, field_long, field_float, field_double, field_string, field_byte_array  from employees where field_boolean=${bean.fieldBoolean} and field_byte=${bean.fieldByte} and field_character=${bean.fieldCharacter} and field_short=${bean.fieldShort} and field_integer=${bean.fieldInteger} and field_long=${bean.fieldLong} and field_float=${bean.fieldFloat} and field_double=${bean.fieldDouble} and field_string=${bean.fieldString} and field_byte_array=${bean.fieldByteArray}</pre>
 *
 * <p><code>bean.id</code> is automatically updated because it is the primary key</p>
 *
 * <p><strong>Inserted columns:</strong></p>
 * <dl>
 * 	<dt>field_boolean</dt><dd>is mapped to <strong>${bean.fieldBoolean}</strong></dd>
 * 	<dt>field_byte</dt><dd>is mapped to <strong>${bean.fieldByte}</strong></dd>
 * 	<dt>field_character</dt><dd>is mapped to <strong>${bean.fieldCharacter}</strong></dd>
 * 	<dt>field_short</dt><dd>is mapped to <strong>${bean.fieldShort}</strong></dd>
 * 	<dt>field_integer</dt><dd>is mapped to <strong>${bean.fieldInteger}</strong></dd>
 * 	<dt>field_long</dt><dd>is mapped to <strong>${bean.fieldLong}</strong></dd>
 * 	<dt>field_float</dt><dd>is mapped to <strong>${bean.fieldFloat}</strong></dd>
 * 	<dt>field_double</dt><dd>is mapped to <strong>${bean.fieldDouble}</strong></dd>
 * 	<dt>field_string</dt><dd>is mapped to <strong>${bean.fieldString}</strong></dd>
 * 	<dt>field_byte_array</dt><dd>is mapped to <strong>${bean.fieldByteArray}</strong></dd>
 * </dl>
 *
 * @param bean
 * 	is mapped to parameter <strong>bean</strong>
 */
@Override
public void insertJQL(Employee bean) {
    KriptonContentValues _contentValues = contentValuesForUpdate();
    _contentValues.put("field_boolean", SQLTypeAdapterUtils.toData(TypeAdapterBoolean.class, bean.fieldBoolean));
    _contentValues.put("field_byte", SQLTypeAdapterUtils.toData(TypeAdapterByte.class, bean.fieldByte));
    _contentValues.put("field_character", SQLTypeAdapterUtils.toData(TypeAdapterChar.class, bean.fieldCharacter));
    _contentValues.put("field_short", SQLTypeAdapterUtils.toData(TypeAdapterShort.class, bean.fieldShort));
    _contentValues.put("field_integer", SQLTypeAdapterUtils.toData(TypeAdapterInteger.class, bean.fieldInteger));
    _contentValues.put("field_long", SQLTypeAdapterUtils.toData(TypeAdapterLong.class, bean.fieldLong));
    _contentValues.put("field_float", SQLTypeAdapterUtils.toData(TypeAdapterFloat.class, bean.fieldFloat));
    _contentValues.put("field_double", SQLTypeAdapterUtils.toData(TypeAdapterDouble.class, bean.fieldDouble));
    _contentValues.put("field_string", SQLTypeAdapterUtils.toData(TypeAdapterString.class, bean.fieldString));
    _contentValues.put("field_byte_array", SQLTypeAdapterUtils.toData(TypeAdapterByteArray.class, bean.fieldByteArray));
    // log section BEGIN
    if (_context.isLogEnabled()) {
        // log for insert -- BEGIN
        Logger.info("INSERT INTO employees (field_boolean, field_byte, field_character, field_short, field_integer, field_long, field_float, field_double, field_string, field_byte_array) select field_boolean, field_byte, field_character, field_short, field_integer, field_long, field_float, field_double, field_string, field_byte_array  from employees where field_boolean=? and field_byte=? and field_character=? and field_short=? and field_integer=? and field_long=? and field_float=? and field_double=? and field_string=? and field_byte_array=?");
        // 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
    // generate SQL for insert
    String _sql = String.format("INSERT INTO employees (%s) select field_boolean, field_byte, field_character, field_short, field_integer, field_long, field_float, field_double, field_string, field_byte_array  from employees where field_boolean=? and field_byte=? and field_character=? and field_short=? and field_integer=? and field_long=? and field_float=? and field_double=? and field_string=? and field_byte_array=?", _contentValues.keyList());
    long result = KriptonDatabaseWrapper.insert(_context, _sql, _contentValues);
    if (result > 0) {
        subject.onNext(SQLiteEvent.createInsert(result));
    }
    bean.id = 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 13 with Employee

use of sqlite.feature.typeadapter.kripton180.Employee in project kripton by xcesco.

the class TestKripton180BeanInsertSelectRuntime method testRun.

@Test
public void testRun() {
    final Employee bean = new Employee();
    bean.birthDate = new java.sql.Date((new java.util.Date()).getTime());
    bean.fieldBoolean = "true";
    bean.fieldByte = "42";
    bean.fieldByteArray = "42";
    bean.fieldCharacter = "a";
    bean.fieldDouble = "120";
    bean.fieldFloat = "120";
    bean.fieldInteger = "11";
    bean.fieldLong = "13";
    bean.fieldShort = "2";
    bean.fieldString = "a";
    bean.hireDate = new java.sql.Date((new java.util.Date()).getTime());
    BindKripton180BeanInsertSelectDataSource dataSource = BindKripton180BeanInsertSelectDataSource.instance();
    dataSource.execute(new BindKripton180BeanInsertSelectDataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindKripton180BeanInsertSelectDaoFactory daoFactory) {
            EmployeeBeanInsertSelectDaoImpl dao = daoFactory.getEmployeeBeanInsertSelectDao();
            dao.insertJQL(bean);
            Assert.assertTrue(bean.id > 0);
            return TransactionResult.ROLLBACK;
        }
    });
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) EmployeeBeanInsertSelectDaoImpl(sqlite.feature.typeadapter.kripton180.bean.insertselect.EmployeeBeanInsertSelectDaoImpl) BindKripton180BeanInsertSelectDataSource(sqlite.feature.typeadapter.kripton180.bean.insertselect.BindKripton180BeanInsertSelectDataSource) BindKripton180BeanInsertSelectDaoFactory(sqlite.feature.typeadapter.kripton180.bean.insertselect.BindKripton180BeanInsertSelectDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 14 with Employee

use of sqlite.feature.typeadapter.kripton180.Employee in project kripton by xcesco.

the class EmployeeBeanDaoImpl method insertJQL.

/**
 * <p>SQL insert:</p>
 * <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 (${bean.fieldBoolean}, ${bean.fieldByte}, ${bean.fieldCharacter}, ${bean.fieldShort}, ${bean.fieldInteger}, ${bean.fieldLong}, ${bean.fieldFloat}, ${bean.fieldDouble}, ${bean.fieldString}, ${bean.fieldByteArray})</pre>
 *
 * <p><code>bean.id</code> is automatically updated because it is the primary key</p>
 *
 * <p><strong>Inserted columns:</strong></p>
 * <dl>
 * 	<dt>field_boolean</dt><dd>is mapped to <strong>${bean.fieldBoolean}</strong></dd>
 * 	<dt>field_byte</dt><dd>is mapped to <strong>${bean.fieldByte}</strong></dd>
 * 	<dt>field_character</dt><dd>is mapped to <strong>${bean.fieldCharacter}</strong></dd>
 * 	<dt>field_short</dt><dd>is mapped to <strong>${bean.fieldShort}</strong></dd>
 * 	<dt>field_integer</dt><dd>is mapped to <strong>${bean.fieldInteger}</strong></dd>
 * 	<dt>field_long</dt><dd>is mapped to <strong>${bean.fieldLong}</strong></dd>
 * 	<dt>field_float</dt><dd>is mapped to <strong>${bean.fieldFloat}</strong></dd>
 * 	<dt>field_double</dt><dd>is mapped to <strong>${bean.fieldDouble}</strong></dd>
 * 	<dt>field_string</dt><dd>is mapped to <strong>${bean.fieldString}</strong></dd>
 * 	<dt>field_byte_array</dt><dd>is mapped to <strong>${bean.fieldByteArray}</strong></dd>
 * </dl>
 *
 * @param bean
 * 	is mapped to parameter <strong>bean</strong>
 *
 * @return <strong>id</strong> of inserted record
 */
@Override
public long insertJQL(Employee bean) {
    if (insertJQLPreparedStatement1 == 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        insertJQLPreparedStatement1 = KriptonDatabaseWrapper.compile(_context, _sql);
    }
    KriptonContentValues _contentValues = contentValuesForUpdate(insertJQLPreparedStatement1);
    _contentValues.put("field_boolean", SQLTypeAdapterUtils.toData(TypeAdapterBoolean.class, bean.fieldBoolean));
    _contentValues.put("field_byte", SQLTypeAdapterUtils.toData(TypeAdapterByte.class, bean.fieldByte));
    _contentValues.put("field_character", SQLTypeAdapterUtils.toData(TypeAdapterChar.class, bean.fieldCharacter));
    _contentValues.put("field_short", SQLTypeAdapterUtils.toData(TypeAdapterShort.class, bean.fieldShort));
    _contentValues.put("field_integer", SQLTypeAdapterUtils.toData(TypeAdapterInteger.class, bean.fieldInteger));
    _contentValues.put("field_long", SQLTypeAdapterUtils.toData(TypeAdapterLong.class, bean.fieldLong));
    _contentValues.put("field_float", SQLTypeAdapterUtils.toData(TypeAdapterFloat.class, bean.fieldFloat));
    _contentValues.put("field_double", SQLTypeAdapterUtils.toData(TypeAdapterDouble.class, bean.fieldDouble));
    _contentValues.put("field_string", SQLTypeAdapterUtils.toData(TypeAdapterString.class, bean.fieldString));
    _contentValues.put("field_byte_array", SQLTypeAdapterUtils.toData(TypeAdapterByteArray.class, bean.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(insertJQLPreparedStatement1, _contentValues);
    bean.id = result;
    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 15 with Employee

use of sqlite.feature.typeadapter.kripton180.Employee in project kripton by xcesco.

the class EmployeeBeanDaoImpl method selectById.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, last_name, first_name, birth_date, hire_date, address, field_boolean, field_byte, field_character, field_short, field_integer, field_long, field_float, field_double, field_string, field_byte_array FROM employees WHERE id=${bean.id}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>last_name</dt><dd>is associated to bean's property <strong>lastName</strong></dd>
 * 	<dt>first_name</dt><dd>is associated to bean's property <strong>firstName</strong></dd>
 * 	<dt>birth_date</dt><dd>is associated to bean's property <strong>birthDate</strong></dd>
 * 	<dt>hire_date</dt><dd>is associated to bean's property <strong>hireDate</strong></dd>
 * 	<dt>address</dt><dd>is associated to bean's property <strong>address</strong></dd>
 * 	<dt>field_boolean</dt><dd>is associated to bean's property <strong>fieldBoolean</strong></dd>
 * 	<dt>field_byte</dt><dd>is associated to bean's property <strong>fieldByte</strong></dd>
 * 	<dt>field_character</dt><dd>is associated to bean's property <strong>fieldCharacter</strong></dd>
 * 	<dt>field_short</dt><dd>is associated to bean's property <strong>fieldShort</strong></dd>
 * 	<dt>field_integer</dt><dd>is associated to bean's property <strong>fieldInteger</strong></dd>
 * 	<dt>field_long</dt><dd>is associated to bean's property <strong>fieldLong</strong></dd>
 * 	<dt>field_float</dt><dd>is associated to bean's property <strong>fieldFloat</strong></dd>
 * 	<dt>field_double</dt><dd>is associated to bean's property <strong>fieldDouble</strong></dd>
 * 	<dt>field_string</dt><dd>is associated to bean's property <strong>fieldString</strong></dd>
 * 	<dt>field_byte_array</dt><dd>is associated to bean's property <strong>fieldByteArray</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${bean.id}</dt><dd>is binded to method's parameter <strong>bean.id</strong></dd>
 * </dl>
 *
 * @param bean
 * 	is used as ${bean}
 * @return selected bean or <code>null</code>.
 */
@Override
public Employee selectById(Employee bean) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_ID_SQL1;
    // add where arguments
    _contentValues.addWhereArgs(String.valueOf(bean.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
        Employee resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("last_name");
            int index2 = _cursor.getColumnIndex("first_name");
            int index3 = _cursor.getColumnIndex("birth_date");
            int index4 = _cursor.getColumnIndex("hire_date");
            int index5 = _cursor.getColumnIndex("address");
            TypeAdapterAddress addressAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterAddress.class);
            int index6 = _cursor.getColumnIndex("field_boolean");
            TypeAdapterBoolean fieldBooleanAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterBoolean.class);
            int index7 = _cursor.getColumnIndex("field_byte");
            TypeAdapterByte fieldByteAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterByte.class);
            int index8 = _cursor.getColumnIndex("field_character");
            TypeAdapterChar fieldCharacterAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterChar.class);
            int index9 = _cursor.getColumnIndex("field_short");
            TypeAdapterShort fieldShortAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterShort.class);
            int index10 = _cursor.getColumnIndex("field_integer");
            TypeAdapterInteger fieldIntegerAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterInteger.class);
            int index11 = _cursor.getColumnIndex("field_long");
            TypeAdapterLong fieldLongAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterLong.class);
            int index12 = _cursor.getColumnIndex("field_float");
            TypeAdapterFloat fieldFloatAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterFloat.class);
            int index13 = _cursor.getColumnIndex("field_double");
            TypeAdapterDouble fieldDoubleAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterDouble.class);
            int index14 = _cursor.getColumnIndex("field_string");
            TypeAdapterString fieldStringAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterString.class);
            int index15 = _cursor.getColumnIndex("field_byte_array");
            TypeAdapterByteArray fieldByteArrayAdapter = SQLTypeAdapterUtils.getAdapter(TypeAdapterByteArray.class);
            resultBean = new Employee();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.lastName = _cursor.getString(index1);
            }
            if (!_cursor.isNull(index2)) {
                resultBean.firstName = _cursor.getString(index2);
            }
            if (!_cursor.isNull(index3)) {
                resultBean.birthDate = SQLDateUtils.read(_cursor.getString(index3));
            }
            if (!_cursor.isNull(index4)) {
                resultBean.hireDate = SQLDateUtils.read(_cursor.getString(index4));
            }
            if (!_cursor.isNull(index5)) {
                resultBean.address = addressAdapter.toJava(_cursor.getString(index5));
            }
            if (!_cursor.isNull(index6)) {
                resultBean.fieldBoolean = fieldBooleanAdapter.toJava(_cursor.getInt(index6) == 0 ? false : true);
            }
            if (!_cursor.isNull(index7)) {
                resultBean.fieldByte = fieldByteAdapter.toJava((byte) _cursor.getInt(index7));
            }
            if (!_cursor.isNull(index8)) {
                resultBean.fieldCharacter = fieldCharacterAdapter.toJava((char) _cursor.getInt(index8));
            }
            if (!_cursor.isNull(index9)) {
                resultBean.fieldShort = fieldShortAdapter.toJava(_cursor.getShort(index9));
            }
            if (!_cursor.isNull(index10)) {
                resultBean.fieldInteger = fieldIntegerAdapter.toJava(_cursor.getInt(index10));
            }
            if (!_cursor.isNull(index11)) {
                resultBean.fieldLong = fieldLongAdapter.toJava(_cursor.getLong(index11));
            }
            if (!_cursor.isNull(index12)) {
                resultBean.fieldFloat = fieldFloatAdapter.toJava(_cursor.getFloat(index12));
            }
            if (!_cursor.isNull(index13)) {
                resultBean.fieldDouble = fieldDoubleAdapter.toJava(_cursor.getDouble(index13));
            }
            if (!_cursor.isNull(index14)) {
                resultBean.fieldString = fieldStringAdapter.toJava(_cursor.getString(index14));
            }
            if (!_cursor.isNull(index15)) {
                resultBean.fieldByteArray = fieldByteArrayAdapter.toJava(_cursor.getBlob(index15));
            }
        }
        return resultBean;
    }
}
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) Cursor(android.database.Cursor) TypeAdapterShort(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterShort) Employee(sqlite.feature.typeadapter.kripton180.Employee) 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) TypeAdapterAddress(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterAddress) TypeAdapterByte(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByte) TypeAdapterString(sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterString)

Aggregations

KriptonContentValues (com.abubusoft.kripton.android.sqlite.KriptonContentValues)20 TypeAdapterString (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterString)20 TypeAdapterByte (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByte)18 TypeAdapterByteArray (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterByteArray)18 TypeAdapterChar (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterChar)18 TypeAdapterDouble (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterDouble)18 TypeAdapterFloat (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterFloat)18 TypeAdapterInteger (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterInteger)18 TypeAdapterLong (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterLong)18 TypeAdapterShort (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterShort)18 TypeAdapterAddress (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterAddress)15 TypeAdapterBoolean (sqlite.feature.typeadapter.kripton180.adapters.TypeAdapterBoolean)15 Cursor (android.database.Cursor)10 Employee (sqlite.feature.typeadapter.kripton180.Employee)10 BaseAndroidTest (base.BaseAndroidTest)3 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)3 Test (org.junit.Test)3 BindKripton180BeanDaoFactory (sqlite.feature.typeadapter.kripton180.bean.BindKripton180BeanDaoFactory)2 BindKripton180BeanDataSource (sqlite.feature.typeadapter.kripton180.bean.BindKripton180BeanDataSource)2 EmployeeBeanDaoImpl (sqlite.feature.typeadapter.kripton180.bean.EmployeeBeanDaoImpl)2