Search in sources :

Example 1 with SingleEmitter

use of io.reactivex.SingleEmitter in project kripton by xcesco.

the class BindKripton180RawInsertSelectDataSource method execute.

public <T> Single<T> execute(final SingleTransaction<T> transaction) {
    SingleOnSubscribe<T> emitter = new SingleOnSubscribe<T>() {

        @Override
        public void subscribe(SingleEmitter<T> emitter) {
            boolean needToOpened = !BindKripton180RawInsertSelectDataSource.this.isOpenInWriteMode();
            boolean success = false;
            @SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
            // no onComplete;
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                if (needToOpened) {
                    close();
                }
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Single<T> result = Single.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SingleOnSubscribe(io.reactivex.SingleOnSubscribe) SingleEmitter(io.reactivex.SingleEmitter)

Example 2 with SingleEmitter

use of io.reactivex.SingleEmitter in project kripton by xcesco.

the class BindApp0DataSource method execute.

public <T> Single<T> execute(final SingleTransaction<T> transaction) {
    SingleOnSubscribe<T> emitter = new SingleOnSubscribe<T>() {

        @Override
        public void subscribe(SingleEmitter<T> emitter) {
            boolean needToOpened = !BindApp0DataSource.this.isOpenInWriteMode();
            boolean success = false;
            @SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
            // no onComplete;
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                if (needToOpened) {
                    close();
                }
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Single<T> result = Single.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SingleOnSubscribe(io.reactivex.SingleOnSubscribe) SingleEmitter(io.reactivex.SingleEmitter)

Example 3 with SingleEmitter

use of io.reactivex.SingleEmitter in project kripton by xcesco.

the class BindKripton180BeanInsertSelectDataSource method execute.

public <T> Single<T> execute(final SingleTransaction<T> transaction) {
    SingleOnSubscribe<T> emitter = new SingleOnSubscribe<T>() {

        @Override
        public void subscribe(SingleEmitter<T> emitter) {
            boolean needToOpened = !BindKripton180BeanInsertSelectDataSource.this.isOpenInWriteMode();
            boolean success = false;
            @SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
            // no onComplete;
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                if (needToOpened) {
                    close();
                }
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Single<T> result = Single.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SingleOnSubscribe(io.reactivex.SingleOnSubscribe) SingleEmitter(io.reactivex.SingleEmitter)

Example 4 with SingleEmitter

use of io.reactivex.SingleEmitter in project kripton by xcesco.

the class BindXenoDataSource method execute.

public <T> Single<T> execute(final SingleTransaction<T> transaction) {
    SingleOnSubscribe<T> emitter = new SingleOnSubscribe<T>() {

        @Override
        public void subscribe(SingleEmitter<T> emitter) {
            boolean needToOpened = !BindXenoDataSource.this.isOpenInWriteMode();
            boolean success = false;
            @SuppressWarnings("resource") SQLiteDatabase connection = needToOpened ? openWritableDatabase() : database();
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
            // no onComplete;
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                if (needToOpened) {
                    close();
                }
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Single<T> result = Single.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SingleOnSubscribe(io.reactivex.SingleOnSubscribe) SingleEmitter(io.reactivex.SingleEmitter)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 SingleEmitter (io.reactivex.SingleEmitter)4 SingleOnSubscribe (io.reactivex.SingleOnSubscribe)4