示例#1
0
 public Single<List<LocationRecord>> getLocationRecordList() {
   return Single.create(
       singleSubscriber -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           List<LocationRecord> result = new ArrayList<>();
           Cursor unsentCursor =
               mBriteDatabase.query("SELECT * FROM " + LocalUnsentLocationRecordTable.NAME);
           Cursor sentCursor =
               mBriteDatabase.query("SELECT * FROM " + RemoteLocationRecordTable.NAME);
           if (!singleSubscriber.isUnsubscribed()) {
             while (sentCursor.moveToNext()) {
               result.add(RemoteLocationRecordTable.parseCursor(sentCursor));
             }
           }
           if (!singleSubscriber.isUnsubscribed()) {
             while (unsentCursor.moveToNext()) {
               result.add(LocalUnsentLocationRecordTable.parseCursor(unsentCursor));
             }
           }
           unsentCursor.close();
           sentCursor.close();
           singleSubscriber.onSuccess(result);
         } finally {
           transaction.end();
         }
       });
 }
示例#2
0
 public Completable addUnsentLocationRecord(LocationRecord locationRecord) {
   return Completable.create(
       subscribe -> {
         BriteDatabase.Transaction transaction = mBriteDatabase.newTransaction();
         try {
           mBriteDatabase.insert(
               LocalUnsentLocationRecordTable.NAME,
               LocalUnsentLocationRecordTable.toContentValues(locationRecord));
           transaction.markSuccessful();
           subscribe.onCompleted();
         } finally {
           transaction.end();
         }
       });
 }
示例#3
0
 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();
         }
       });
 }
示例#4
0
 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();
         }
       });
 }
示例#5
0
 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();
         }
       });
 }