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;
}
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;
}
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;
}
Aggregations