예제 #1
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();
         }
       });
 }
예제 #2
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();
         }
       });
 }
예제 #3
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();
         }
       });
 }