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;
}
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;
}
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);
}
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());
}
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);
}
Aggregations