use of io.realm.internal.LinkView in project realm-java by realm.
the class DynamicRealmObject method getList.
/**
* Returns the {@link RealmList} of objects being linked to from this field.
*
* @param fieldName the name of the field.
* @return the {@link RealmList} data for this field.
* @throws IllegalArgumentException if field name doesn't exist or it doesn't contain a list of links.
*/
public RealmList<DynamicRealmObject> getList(String fieldName) {
proxyState.getRealm$realm().checkIfValid();
long columnIndex = proxyState.getRow$realm().getColumnIndex(fieldName);
try {
LinkView linkView = proxyState.getRow$realm().getLinkList(columnIndex);
String className = RealmSchema.getSchemaForTable(linkView.getTargetTable());
return new RealmList<DynamicRealmObject>(className, linkView, proxyState.getRealm$realm());
} catch (IllegalArgumentException e) {
checkFieldType(fieldName, columnIndex, RealmFieldType.LIST);
throw e;
}
}
use of io.realm.internal.LinkView in project realm-java by realm.
the class AllTypesRealmProxy method realmGet$columnRealmList.
public RealmList<some.test.AllTypes> realmGet$columnRealmList() {
proxyState.getRealm$realm().checkIfValid();
// use the cached value if available
if (columnRealmListRealmList != null) {
return columnRealmListRealmList;
} else {
LinkView linkView = proxyState.getRow$realm().getLinkList(columnInfo.columnRealmListIndex);
columnRealmListRealmList = new RealmList<some.test.AllTypes>(some.test.AllTypes.class, linkView, proxyState.getRealm$realm());
return columnRealmListRealmList;
}
}
use of io.realm.internal.LinkView in project realm-java by realm.
the class AllTypesRealmProxy method realmSet$columnRealmList.
public void realmSet$columnRealmList(RealmList<some.test.AllTypes> value) {
if (proxyState.isUnderConstruction()) {
if (!proxyState.getAcceptDefaultValue$realm()) {
return;
}
if (proxyState.getExcludeFields$realm().contains("columnRealmList")) {
return;
}
if (value != null && !value.isManaged()) {
final Realm realm = (Realm) proxyState.getRealm$realm();
final RealmList<some.test.AllTypes> original = value;
value = new RealmList<some.test.AllTypes>();
for (some.test.AllTypes item : original) {
if (item == null || RealmObject.isManaged(item)) {
value.add(item);
} else {
value.add(realm.copyToRealm(item));
}
}
}
}
proxyState.getRealm$realm().checkIfValid();
LinkView links = proxyState.getRow$realm().getLinkList(columnInfo.columnRealmListIndex);
links.clear();
if (value == null) {
return;
}
for (RealmModel linkedObject : (RealmList<? extends RealmModel>) value) {
if (!(RealmObject.isManaged(linkedObject) && RealmObject.isValid(linkedObject))) {
throw new IllegalArgumentException("Each element of 'value' must be a valid managed object.");
}
if (((RealmObjectProxy) linkedObject).realmGet$proxyState().getRealm$realm() != proxyState.getRealm$realm()) {
throw new IllegalArgumentException("Each element of 'value' must belong to the same Realm.");
}
links.add(((RealmObjectProxy) linkedObject).realmGet$proxyState().getRow$realm().getIndex());
}
}
use of io.realm.internal.LinkView in project realm-java by realm.
the class DynamicRealmObject method setList.
/**
* Sets the reference to a {@link RealmList} on the given field.
*
* @param fieldName field name.
* @param list list of references.
* @throws IllegalArgumentException if field name doesn't exist, it is not a list field, the type
* of the object represented by the DynamicRealmObject doesn't match or any element in the list belongs to a
* different Realm.
*/
public void setList(String fieldName, RealmList<DynamicRealmObject> list) {
proxyState.getRealm$realm().checkIfValid();
if (list == null) {
throw new IllegalArgumentException("Null values not allowed for lists");
}
long columnIndex = proxyState.getRow$realm().getColumnIndex(fieldName);
LinkView links = proxyState.getRow$realm().getLinkList(columnIndex);
Table linkTargetTable = links.getTargetTable();
final String linkTargetTableName = Table.tableNameToClassName(linkTargetTable.getName());
boolean typeValidated;
if (list.className == null && list.clazz == null) {
// Unmanaged lists don't know anything about the types they contain. They might even hold objects of
// multiple types :(, so we have to check each item in the list.
typeValidated = false;
} else {
String listType = list.className != null ? list.className : Table.tableNameToClassName(proxyState.getRealm$realm().schema.getTable(list.clazz).getName());
if (!linkTargetTableName.equals(listType)) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "The elements in the list are not the proper type. " + "Was %s expected %s.", listType, linkTargetTableName));
}
typeValidated = true;
}
final int listLength = list.size();
final long[] indices = new long[listLength];
for (int i = 0; i < listLength; i++) {
RealmObjectProxy obj = list.get(i);
if (obj.realmGet$proxyState().getRealm$realm() != proxyState.getRealm$realm()) {
throw new IllegalArgumentException("Each element in 'list' must belong to the same Realm instance.");
}
if (!typeValidated && !linkTargetTable.hasSameSchema(obj.realmGet$proxyState().getRow$realm().getTable())) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Element at index %d is not the proper type. " + "Was '%s' expected '%s'.", i, Table.tableNameToClassName(obj.realmGet$proxyState().getRow$realm().getTable().getName()), linkTargetTableName));
}
indices[i] = obj.realmGet$proxyState().getRow$realm().getIndex();
}
links.clear();
for (int i = 0; i < listLength; i++) {
links.add(indices[i]);
}
}
Aggregations