public Observable<Void> saveToSentLocationsTable(List<LocationRecord> locationRecords) { return Observable.create( subscriber -> { BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction(); try { mBriteDatabase.delete(RemoteLocationRecordTable.NAME, null); for (LocationRecord locationRecord : locationRecords) { mBriteDatabase.insert( RemoteLocationRecordTable.NAME, RemoteLocationRecordTable.toContentValues(locationRecord)); } transaction.markSuccessful(); subscriber.onCompleted(); } finally { transaction.end(); } }); }
public Completable clearTables() { return Completable.create( subscribe -> { BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction(); try { Cursor cursor = mBriteDatabase.query("SELECT name FROM sqlite_master WHERE type='table'"); while (cursor.moveToNext()) { mBriteDatabase.delete(cursor.getString(cursor.getColumnIndex("name")), null); } cursor.close(); transaction.markSuccessful(); subscribe.onCompleted(); } finally { transaction.end(); } }); }
public Observable<UnsentAndResponseLocationRecordPair> moveLocationRecordToSent( UnsentAndResponseLocationRecordPair unsentAndFromResponse) { return Observable.create( subscriber -> { BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction(); try { mBriteDatabase.delete( LocalUnsentLocationRecordTable.NAME, LocalUnsentLocationRecordTable.COLUMN_ID + "= ?", Integer.toString(unsentAndFromResponse.getUnsentLocationRecord().getId())); mBriteDatabase.insert( RemoteLocationRecordTable.NAME, RemoteLocationRecordTable.toContentValues( unsentAndFromResponse.getLocationRecordFromResponse())); subscriber.onNext(unsentAndFromResponse); transaction.markSuccessful(); subscriber.onCompleted(); } finally { transaction.end(); } }); }