Advertisement
tuttelikz

RealmHelper [[+]

Dec 12th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package com.example.iptea.hearingclub;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import io.realm.Realm;
  6. import io.realm.RealmResults;
  7.  
  8. /**
  9.  * Created by iptea on 12/11/2017.
  10.  */
  11.  
  12. public class RealmHelper {
  13.  
  14.     private static final String TAG = "RealmManager";
  15.     Realm realm;
  16.  
  17.     public RealmHelper(Realm realm) {
  18.         this.realm = realm;
  19.     }
  20.  
  21.     public void save(final HearingResults newHearingResults) {
  22.  
  23.         realm.executeTransaction(new Realm.Transaction() {
  24.             @Override
  25.             public void execute(Realm realm) {
  26.                 HearingResults savedHearingResults = realm.copyToRealm(newHearingResults);
  27.             }
  28.         });
  29.  
  30.     }
  31.  
  32.  
  33.     public ArrayList<String> retrieve() {
  34.         ArrayList<String> hearingResultDates = new ArrayList<>();
  35.  
  36.         if (realm != null) {
  37.             //RealmResults<HearingResults> hearingResults = realm.where(HearingResults.class).findAll();
  38.             RealmResults<HearingResults> hearingResults = realm.where(HearingResults.class).findAllAsync();
  39.             for (HearingResults savedHearingResults:hearingResults) {
  40.                 hearingResultDates.add(savedHearingResults.getId());
  41.             }
  42.         }
  43.  
  44.         return hearingResultDates;
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement