コード例 #1
0
  public static SatsClass copyOrUpdate(
      Realm realm, SatsClass object, boolean update, Map<RealmObject, RealmObject> cache) {
    if (object.realm != null && object.realm.getId() == realm.getId()) {
      return object;
    }
    SatsClass realmObject = null;
    boolean canUpdate = update;
    if (canUpdate) {
      Table table = realm.getTable(SatsClass.class);
      long pkColumnIndex = table.getPrimaryKey();
      long rowIndex = table.findFirstString(pkColumnIndex, object.getId());
      if (rowIndex != TableOrView.NO_MATCH) {
        realmObject = new SatsClassRealmProxy();
        realmObject.realm = realm;
        realmObject.row = table.getRow(rowIndex);
        cache.put(object, realmObject);
      } else {
        canUpdate = false;
      }
    }

    if (canUpdate) {
      return update(realm, realmObject, object, cache);
    } else {
      return copy(realm, object, update, cache);
    }
  }
コード例 #2
0
 public static SatsClass createOrUpdateUsingJsonObject(
     Realm realm, JSONObject json, boolean update) throws JSONException {
   SatsClass obj = null;
   if (update) {
     Table table = realm.getTable(SatsClass.class);
     long pkColumnIndex = table.getPrimaryKey();
     if (!json.isNull("id")) {
       long rowIndex = table.findFirstString(pkColumnIndex, json.getString("id"));
       if (rowIndex != TableOrView.NO_MATCH) {
         obj = new SatsClassRealmProxy();
         obj.realm = realm;
         obj.row = table.getRow(rowIndex);
       }
     }
   }
   if (obj == null) {
     obj = realm.createObject(SatsClass.class);
   }
   if (!json.isNull("id")) {
     obj.setId((String) json.getString("id"));
   }
   if (!json.isNull("centerFilterId")) {
     obj.setCenterFilterId((String) json.getString("centerFilterId"));
   }
   if (!json.isNull("classTypeId")) {
     obj.setClassTypeId((String) json.getString("classTypeId"));
   }
   if (!json.isNull("durationInMinutes")) {
     obj.setDurationInMinutes((int) json.getInt("durationInMinutes"));
   }
   if (!json.isNull("instructorId")) {
     obj.setInstructorId((String) json.getString("instructorId"));
   }
   if (!json.isNull("name")) {
     obj.setName((String) json.getString("name"));
   }
   if (!json.isNull("startTime")) {
     obj.setStartTime((String) json.getString("startTime"));
   }
   if (!json.isNull("bookedPersonsCount")) {
     obj.setBookedPersonsCount((int) json.getInt("bookedPersonsCount"));
   }
   if (!json.isNull("maxPersonsCount")) {
     obj.setMaxPersonsCount((int) json.getInt("maxPersonsCount"));
   }
   if (!json.isNull("regionId")) {
     obj.setRegionId((String) json.getString("regionId"));
   }
   if (!json.isNull("waitingListCount")) {
     obj.setWaitingListCount((int) json.getInt("waitingListCount"));
   }
   if (!json.isNull("classCategoryIds")) {
     obj.getClassCategoryIds().clear();
     JSONArray array = json.getJSONArray("classCategoryIds");
     for (int i = 0; i < array.length(); i++) {
       se.greatbrain.sats.data.model.ClassCategoryIds item =
           ClassCategoryIdsRealmProxy.createOrUpdateUsingJsonObject(
               realm, array.getJSONObject(i), update);
       obj.getClassCategoryIds().add(item);
     }
   }
   return obj;
 }