Search in sources :

Example 1 with OsResults

use of io.realm.internal.OsResults 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 OsResults

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

the class RealmQuery method createRealmResults.

private RealmResults<E> createRealmResults(TableQuery query, boolean loadResults) {
    RealmResults<E> results;
    OsResults osResults;
    osResults = OsResults.createFromQuery(realm.sharedRealm, query);
    if (isDynamicQuery()) {
        results = new RealmResults<>(realm, osResults, className);
    } else {
        results = new RealmResults<>(realm, osResults, clazz);
    }
    if (loadResults) {
        results.load();
    }
    return results;
}
Also used : OsResults(io.realm.internal.OsResults)

Example 3 with OsResults

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

the class DynamicSelectorForMap method produceResults.

// Do not use <K> or <V> as this method can be used for either keys or values
private <T> RealmResults<T> produceResults(BaseRealm baseRealm, Pair<Table, Long> tableAndValuesPtr, boolean forPrimitives, Class<T> clazz) {
    Long valuesPtr = tableAndValuesPtr.second;
    OsResults osResults = OsResults.createFromMap(baseRealm.sharedRealm, valuesPtr);
    return new RealmResults<>(baseRealm, osResults, clazz, forPrimitives);
}
Also used : OsResults(io.realm.internal.OsResults)

Example 4 with OsResults

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

the class RealmResultsTests method size_returns_Integer_MAX_VALUE_for_huge_results.

@Test
public void size_returns_Integer_MAX_VALUE_for_huge_results() {
    final OsResults osResults = Mockito.mock(OsResults.class);
    final RealmResults<AllTypes> targetResult = TestHelper.newRealmResults(realm, osResults, AllTypes.class);
    Mockito.when(osResults.isLoaded()).thenReturn(true);
    Mockito.when(osResults.size()).thenReturn(((long) Integer.MAX_VALUE) - 1);
    assertEquals(Integer.MAX_VALUE - 1, targetResult.size());
    Mockito.when(osResults.size()).thenReturn(((long) Integer.MAX_VALUE));
    assertEquals(Integer.MAX_VALUE, targetResult.size());
    Mockito.when(osResults.size()).thenReturn(((long) Integer.MAX_VALUE) + 1);
    assertEquals(Integer.MAX_VALUE, targetResult.size());
}
Also used : AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) OsResults(io.realm.internal.OsResults) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 5 with OsResults

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

the class DynamicSelectorForMap method produceResults.

// Do not use <K> or <V> as this method can be used for either keys or values
private <T> RealmResults<T> produceResults(BaseRealm baseRealm, Pair<Table, Long> tableAndValuesPtr, String className) {
    Long valuesPtr = tableAndValuesPtr.second;
    OsResults osResults = OsResults.createFromMap(baseRealm.sharedRealm, valuesPtr);
    return new RealmResults<>(baseRealm, osResults, className, false);
}
Also used : OsResults(io.realm.internal.OsResults)

Aggregations

OsResults (io.realm.internal.OsResults)6 UiThreadTest (androidx.test.annotation.UiThreadTest)1 AllTypes (io.realm.entities.AllTypes)1 DictionaryAllTypes (io.realm.entities.DictionaryAllTypes)1 CheckedRow (io.realm.internal.CheckedRow)1 Test (org.junit.Test)1