Ejemplo n.º 1
0
 /**
  * Sets a reference to another object on the given field.
  *
  * @param fieldName the field name.
  * @param value the object to link to.
  * @throws IllegalArgumentException if field name doesn't exists, it doesn't link to other Realm
  *     objects, or the type of DynamicRealmObject doesn't match.
  */
 public void setObject(String fieldName, DynamicRealmObject value) {
   long columnIndex = row.getColumnIndex(fieldName);
   if (value == null) {
     row.nullifyLink(columnIndex);
   } else {
     if (value.realm == null || value.row == null) {
       throw new IllegalArgumentException(
           "Cannot link to objects that are not part of the Realm.");
     }
     if (!realm.getConfiguration().equals(value.realm.getConfiguration())) {
       throw new IllegalArgumentException("Cannot add an object from another Realm");
     }
     Table table = row.getTable();
     Table inputTable = value.row.getTable();
     if (!table.hasSameSchema(inputTable)) {
       throw new IllegalArgumentException(
           String.format(
               "Type of object is wrong. Was %s, expected %s",
               inputTable.getName(), table.getName()));
     }
     row.setLink(columnIndex, value.row.getIndex());
   }
 }