Esempio n. 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();
         }
       });
 }
Esempio n. 2
0
 public Observable<LocationRecord> getUnsentLocationRecords() {
   return Observable.create(
       subscriber -> {
         Cursor cursor =
             mBriteDatabase.query("SELECT * FROM " + LocalUnsentLocationRecordTable.NAME);
         if (!subscriber.isUnsubscribed()) {
           while (cursor.moveToNext()) {
             subscriber.onNext(LocalUnsentLocationRecordTable.parseCursor(cursor));
           }
         }
         cursor.close();
         subscriber.onCompleted();
       });
 }
Esempio n. 3
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();
         }
       });
 }