Search in sources :

Example 1 with Country

use of sqlite.feature.rx.model.Country in project kripton by xcesco.

the class TestRx method testRunAsync.

@Test
public void testRunAsync() {
    BindXenoDataSource dataSource = prepareDataSource();
    dataSource.execute(new BindXenoDataSource.ObservableTransaction<Country>() {

        @Override
        public TransactionResult onExecute(BindXenoDaoFactory daoFactory, ObservableEmitter<Country> emitter) {
            CountryDaoImpl dao = daoFactory.getCountryDao();
            List<Country> list = dao.selectAll();
            for (Country item : list) {
                emitter.onNext(item);
            }
            return TransactionResult.COMMIT;
        }
    }).subscribeOn(Schedulers.newThread()).subscribe(new Observer<Country>() {

        @Override
        public void onSubscribe(Disposable d) {
            System.out.println(Thread.currentThread().getName() + " onSubscribe");
        }

        @Override
        public void onNext(Country t) {
            System.out.println(Thread.currentThread().getName() + " onNext " + t.name);
        }

        @Override
        public void onError(Throwable e) {
            System.out.println(Thread.currentThread().getName() + " onNext");
        }

        @Override
        public void onComplete() {
            System.out.println(Thread.currentThread().getName() + " onComplete");
        }
    });
    System.out.println(Thread.currentThread().getName() + " Finished");
    try {
        Thread.currentThread().sleep(5000);
    } catch (Throwable e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}
Also used : CountryDaoImpl(sqlite.feature.rx.persistence.CountryDaoImpl) Disposable(io.reactivex.disposables.Disposable) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) Country(sqlite.feature.rx.model.Country) List(java.util.List) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 2 with Country

use of sqlite.feature.rx.model.Country in project kripton by xcesco.

the class TestRx method prepareDataSource.

public BindXenoDataSource prepareDataSource() {
    BindXenoDataSource dataSource = BindXenoDataSource.instance();
    dataSource.executeBatch(new BindXenoDataSource.Batch<Void>() {

        @Override
        public Void onExecute(BindXenoDaoFactory daoFactory) {
            CountryDaoImpl dao = daoFactory.getCountryDao();
            for (int i = 0; i < COUNTER; i++) {
                Country bean = new Country();
                bean.code = "code" + i;
                bean.callingCode = "" + i;
                bean.name = "name" + i;
                // Object bean = new
                dao.insert(bean);
            }
            return null;
        // dao.selectAll();
        }
    });
    return dataSource;
}
Also used : CountryDaoImpl(sqlite.feature.rx.persistence.CountryDaoImpl) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) Country(sqlite.feature.rx.model.Country) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory)

Example 3 with Country

use of sqlite.feature.rx.model.Country in project kripton by xcesco.

the class TestRx method testRunSyncWithListener.

@Test
public void testRunSyncWithListener() {
    BindXenoDataSource dataSource = BindXenoDataSource.instance();
    dataSource.execute(new BindXenoDataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindXenoDaoFactory daoFactory) {
            CountryDaoImpl dao = daoFactory.getCountryDao();
            for (int i = 0; i < COUNTER; i++) {
                Country bean = new Country();
                bean.code = "code" + i;
                bean.callingCode = "" + i;
                bean.name = "name" + i;
                // Object bean = new
                dao.insert(bean);
            }
            dao.selectAll();
            return TransactionResult.COMMIT;
        }
    });
    dataSource.execute(new BindXenoDataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindXenoDaoFactory daoFactory) {
            System.out.println("onSubscribe");
            CountryDaoImpl dao = daoFactory.getCountryDao();
            dao.selectAll(new OnReadBeanListener<Country>() {

                @Override
                public void onRead(Country bean, int row, int rowCount) {
                    System.out.println("onNext" + bean);
                }
            });
            System.out.println("onComplete");
            return TransactionResult.COMMIT;
        }
    });
}
Also used : CountryDaoImpl(sqlite.feature.rx.persistence.CountryDaoImpl) BindXenoDataSource(sqlite.feature.rx.persistence.BindXenoDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) OnReadBeanListener(com.abubusoft.kripton.android.sqlite.OnReadBeanListener) Country(sqlite.feature.rx.model.Country) BindXenoDaoFactory(sqlite.feature.rx.persistence.BindXenoDaoFactory) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Example 4 with Country

use of sqlite.feature.rx.model.Country in project kripton by xcesco.

the class CountryDaoImpl method selectByCallingCode.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, area, code, calling_code, region, name, translated_name FROM country WHERE calling_code = ${callingCode}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>area</dt><dd>is associated to bean's property <strong>area</strong></dd>
 * 	<dt>code</dt><dd>is associated to bean's property <strong>code</strong></dd>
 * 	<dt>calling_code</dt><dd>is associated to bean's property <strong>callingCode</strong></dd>
 * 	<dt>region</dt><dd>is associated to bean's property <strong>region</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
 * 	<dt>translated_name</dt><dd>is associated to bean's property <strong>translatedName</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${callingCode}</dt><dd>is binded to method's parameter <strong>callingCode</strong></dd>
 * </dl>
 *
 * @param callingCode
 * 	is binded to <code>${callingCode}</code>
 * @return selected bean or <code>null</code>.
 */
@Override
public Country selectByCallingCode(String callingCode) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_CALLING_CODE_SQL9;
    // add where arguments
    _contentValues.addWhereArgs((callingCode == null ? "" : callingCode));
    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
        Country resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("area");
            int index2 = _cursor.getColumnIndex("code");
            int index3 = _cursor.getColumnIndex("calling_code");
            int index4 = _cursor.getColumnIndex("region");
            int index5 = _cursor.getColumnIndex("name");
            int index6 = _cursor.getColumnIndex("translated_name");
            resultBean = new Country();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.area = _cursor.getLong(index1);
            }
            resultBean.code = _cursor.getString(index2);
            resultBean.callingCode = _cursor.getString(index3);
            if (!_cursor.isNull(index4)) {
                resultBean.region = _cursor.getString(index4);
            }
            resultBean.name = _cursor.getString(index5);
            if (!_cursor.isNull(index6)) {
                resultBean.translatedName = CountryTable.parseTranslatedName(_cursor.getBlob(index6));
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Country(sqlite.feature.rx.model.Country) Cursor(android.database.Cursor)

Example 5 with Country

use of sqlite.feature.rx.model.Country in project kripton by xcesco.

the class CountryDaoImpl method selectByCountry.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, area, code, calling_code, region, name, translated_name FROM country WHERE code = ${code}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>area</dt><dd>is associated to bean's property <strong>area</strong></dd>
 * 	<dt>code</dt><dd>is associated to bean's property <strong>code</strong></dd>
 * 	<dt>calling_code</dt><dd>is associated to bean's property <strong>callingCode</strong></dd>
 * 	<dt>region</dt><dd>is associated to bean's property <strong>region</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
 * 	<dt>translated_name</dt><dd>is associated to bean's property <strong>translatedName</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${code}</dt><dd>is binded to method's parameter <strong>code</strong></dd>
 * </dl>
 *
 * @param code
 * 	is binded to <code>${code}</code>
 * @return selected bean or <code>null</code>.
 */
@Override
public Country selectByCountry(String code) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_COUNTRY_SQL10;
    // add where arguments
    _contentValues.addWhereArgs((code == null ? "" : code));
    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
        Country resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("area");
            int index2 = _cursor.getColumnIndex("code");
            int index3 = _cursor.getColumnIndex("calling_code");
            int index4 = _cursor.getColumnIndex("region");
            int index5 = _cursor.getColumnIndex("name");
            int index6 = _cursor.getColumnIndex("translated_name");
            resultBean = new Country();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.area = _cursor.getLong(index1);
            }
            resultBean.code = _cursor.getString(index2);
            resultBean.callingCode = _cursor.getString(index3);
            if (!_cursor.isNull(index4)) {
                resultBean.region = _cursor.getString(index4);
            }
            resultBean.name = _cursor.getString(index5);
            if (!_cursor.isNull(index6)) {
                resultBean.translatedName = CountryTable.parseTranslatedName(_cursor.getBlob(index6));
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Country(sqlite.feature.rx.model.Country) Cursor(android.database.Cursor)

Aggregations

Country (sqlite.feature.rx.model.Country)10 Cursor (android.database.Cursor)5 KriptonContentValues (com.abubusoft.kripton.android.sqlite.KriptonContentValues)5 BindXenoDaoFactory (sqlite.feature.rx.persistence.BindXenoDaoFactory)5 BindXenoDataSource (sqlite.feature.rx.persistence.BindXenoDataSource)5 BaseAndroidTest (base.BaseAndroidTest)4 Test (org.junit.Test)4 CountryDaoImpl (sqlite.feature.rx.persistence.CountryDaoImpl)4 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)3 List (java.util.List)3 Disposable (io.reactivex.disposables.Disposable)2 OnReadBeanListener (com.abubusoft.kripton.android.sqlite.OnReadBeanListener)1 SQLiteEvent (com.abubusoft.kripton.android.sqlite.SQLiteEvent)1 Function (io.reactivex.functions.Function)1 ArrayList (java.util.ArrayList)1