Exemple #1
0
 /** Remove todos os objetos RealmVideo salvos no banco. */
 public static void cleanVideos() {
   Realm realm = Realm.getDefaultInstance();
   RealmResults<RealmVideo> results = realm.where(RealmVideo.class).findAll();
   realm.beginTransaction();
   results.clear();
   realm.commitTransaction();
 }
  public void testRemoveLastEmptyList() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    testRealm.beginTransaction();
    resultList.clear();
    assertEquals(0, resultList.size());
    resultList.removeLast();
    testRealm.commitTransaction();

    assertEquals(0, resultList.size());
  }
  // void clear(Class<?> classSpec)
  public void testClearEmptiesTable() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    assertEquals(TEST_DATA_SIZE, resultList.size());

    testRealm.beginTransaction();
    resultList.clear();
    testRealm.commitTransaction();

    assertEquals(0, resultList.size());
  }
Exemple #4
0
  public static void removeFavorite(Context context, MashableNewsItem newsItem) {
    Realm realm = Realm.getInstance(context);
    realm.beginTransaction();

    RealmResults<Favorites> result =
        realm.where(Favorites.class).equalTo("link", newsItem.link).findAll();

    result.clear();
    realm.commitTransaction();
  }
 public void removeAllWatchVod() {
   // Realm Database **********************************************************************
   // Obtain a Realm instance
   Realm realm = Realm.getInstance(mContext);
   realm.beginTransaction();
   RealmResults<WatchVodObject> results = mRealm.where(WatchVodObject.class).findAll();
   if (results.size() > 0) {
     results.clear();
   }
   realm.commitTransaction();
   // Realm Database **********************************************************************
 }
  public void updateFinished(OpenweathermapObject data) {
    String errorMessage = getString(R.string.txt_unknown_error);

    if (data != null) {
      errorMessage = data.getErrorMessage();
    }

    if (errorMessage.isEmpty()) {
      SharedPreferences preferences =
          PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
      Boolean del_old =
          preferences.getBoolean(
              getString(R.string.settings_delete_old_data_key),
              getResources().getBoolean(R.bool.settings_delete_old_data_default));
      Realm realm = null;
      try {
        realm = Realm.getDefaultInstance();
        realm.beginTransaction();
        if (del_old) {
          Long timeStamp = data.getWeatherForecastList().get(0).getTimeStamp();
          RealmResults<ForecastListItem> result =
              realm.where(ForecastListItem.class).lessThan("timeStamp", timeStamp).findAll();
          result.clear();
        }
        realm.copyToRealmOrUpdate(data.getWeatherForecastList());
        realm.commitTransaction();

        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong(getString(R.string.last_update_key), System.currentTimeMillis());
        String city = data.getCityName().concat(", ".concat(data.getCountry()));
        editor.putString(getString(R.string.current_city_key), city);
        editor.commit();

      } finally {
        if (realm != null) {
          realm.close();
        }
      }
    }
    Intent intent = new Intent(BROADCAST_ACTION);
    intent.putExtra(PARAM_STATUS, STATUS_FINISH);
    intent.putExtra(PARAM_RESULT, errorMessage);
    sendBroadcast(intent);
  }
  // Test that all methods that require a transaction (ie. any function that mutates Realm data)
  public void testMutableMethodsOutsideTransactions() {
    RealmResults<AllTypes> result = testRealm.where(AllTypes.class).findAll();

    try {
      result.clear();
      fail();
    } catch (IllegalStateException ignored) {
    }
    try {
      result.remove(0);
      fail();
    } catch (IllegalStateException ignored) {
    }
    try {
      result.removeLast();
      fail();
    } catch (IllegalStateException ignored) {
    }
  }