Search in sources :

Example 56 with ObservableOnSubscribe

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

the class BindUserDataSource method execute.

public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
    ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {

        @Override
        public void subscribe(ObservableEmitter<T> emitter) {
            // open database in thread safe mode
            Pair<Boolean, SupportSQLiteDatabase> _status = BindUserDataSource.this.openDatabaseThreadSafeMode(true);
            boolean success = false;
            SupportSQLiteDatabase connection = _status.value1;
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
                emitter.onComplete();
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                // close database in thread safe mode
                closeThreadSafeMode(_status);
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Observable<T> result = Observable.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 57 with ObservableOnSubscribe

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

the class BindXenoDataSource method execute.

public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
    ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {

        @Override
        public void subscribe(ObservableEmitter<T> emitter) {
            // open database in thread safe mode
            Pair<Boolean, SupportSQLiteDatabase> _status = BindXenoDataSource.this.openDatabaseThreadSafeMode(true);
            boolean success = false;
            SupportSQLiteDatabase connection = _status.value1;
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
                emitter.onComplete();
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                // close database in thread safe mode
                closeThreadSafeMode(_status);
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Observable<T> result = Observable.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 58 with ObservableOnSubscribe

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

the class BindKripton180RawInsertSelectDataSource method execute.

public <T> Observable<T> execute(final ObservableTransaction<T> transaction) {
    ObservableOnSubscribe<T> emitter = new ObservableOnSubscribe<T>() {

        @Override
        public void subscribe(ObservableEmitter<T> emitter) {
            // open database in thread safe mode
            Pair<Boolean, SupportSQLiteDatabase> _status = BindKripton180RawInsertSelectDataSource.this.openDatabaseThreadSafeMode(true);
            boolean success = false;
            SupportSQLiteDatabase connection = _status.value1;
            DataSourceSingleThread currentDaoFactory = _daoFactorySingleThread.bindToThread();
            currentDaoFactory.onSessionOpened();
            try {
                connection.beginTransaction();
                if (transaction != null && TransactionResult.COMMIT == transaction.onExecute(currentDaoFactory, emitter)) {
                    connection.setTransactionSuccessful();
                    success = true;
                }
                emitter.onComplete();
            } catch (Throwable e) {
                Logger.error(e.getMessage());
                e.printStackTrace();
                emitter.onError(e);
                currentDaoFactory.onSessionClear();
            } finally {
                try {
                    connection.endTransaction();
                } catch (Throwable e) {
                }
                // close database in thread safe mode
                closeThreadSafeMode(_status);
                if (success) {
                    currentDaoFactory.onSessionClosed();
                } else {
                    currentDaoFactory.onSessionClear();
                }
            }
            return;
        }
    };
    Observable<T> result = Observable.create(emitter);
    if (globalSubscribeOn != null)
        result.subscribeOn(globalSubscribeOn);
    if (globalObserveOn != null)
        result.observeOn(globalObserveOn);
    return result;
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) ObservableEmitter(io.reactivex.ObservableEmitter)

Aggregations

ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)58 ObservableEmitter (io.reactivex.ObservableEmitter)48 Disposable (io.reactivex.disposables.Disposable)34 Observable (io.reactivex.Observable)13 ArrayList (java.util.ArrayList)12 List (java.util.List)11 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)9 File (java.io.File)8 IOException (java.io.IOException)8 Intent (android.content.Intent)6 Bundle (android.os.Bundle)6 Consumer (io.reactivex.functions.Consumer)6 Bitmap (android.graphics.Bitmap)5 Uri (android.net.Uri)5 Observer (io.reactivex.Observer)5 NonNull (io.reactivex.annotations.NonNull)5 HashMap (java.util.HashMap)5 Log (android.util.Log)4 View (android.view.View)4 BindView (butterknife.BindView)4