Search in sources :

Example 1 with CheckedRow

use of io.realm.internal.CheckedRow in project realm-java by realm.

the class MutableRealmObjectSchema method transform.

@Override
public RealmObjectSchema transform(Function function) {
    // noinspection ConstantConditions
    if (function != null) {
        // Users might delete object being transformed or accidentally delete other objects
        // in the same table. E.g. cascading deletes if it is referenced by an object being deleted.
        OsResults result = OsResults.createFromQuery(realm.sharedRealm, table.where()).createSnapshot();
        long original_size = result.size();
        if (original_size > Integer.MAX_VALUE) {
            throw new UnsupportedOperationException("Too many results to iterate: " + original_size);
        }
        int size = (int) result.size();
        for (int i = 0; i < size; i++) {
            DynamicRealmObject obj = new DynamicRealmObject(realm, new CheckedRow(result.getUncheckedRow(i)));
            if (obj.isValid()) {
                function.apply(obj);
            }
        }
    }
    return this;
}
Also used : CheckedRow(io.realm.internal.CheckedRow) OsResults(io.realm.internal.OsResults)

Example 2 with CheckedRow

use of io.realm.internal.CheckedRow in project realm-java by realm.

the class DynamicRealmObject method getObject.

/**
 * Returns the object being linked to from this field.
 *
 * @param fieldName the name of the field.
 * @return the {@link DynamicRealmObject} representation of the linked object or {@code null} if no object is linked.
 * @throws IllegalArgumentException if field name doesn't exist or it doesn't contain links to other objects.
 */
@Nullable
public DynamicRealmObject getObject(String fieldName) {
    proxyState.getRealm$realm().checkIfValid();
    long columnKey = proxyState.getRow$realm().getColumnKey(fieldName);
    checkFieldType(fieldName, columnKey, RealmFieldType.OBJECT);
    if (proxyState.getRow$realm().isNullLink(columnKey)) {
        return null;
    } else {
        long linkObjectKey = proxyState.getRow$realm().getLink(columnKey);
        CheckedRow linkRow = proxyState.getRow$realm().getTable().getLinkTarget(columnKey).getCheckedRow(linkObjectKey);
        return new DynamicRealmObject(proxyState.getRealm$realm(), linkRow);
    }
}
Also used : CheckedRow(io.realm.internal.CheckedRow) Nullable(javax.annotation.Nullable)

Aggregations

CheckedRow (io.realm.internal.CheckedRow)2 OsResults (io.realm.internal.OsResults)1 Nullable (javax.annotation.Nullable)1