use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.
the class RealmQueryTests method limit_withSortAndDistinct.
@Test
public void limit_withSortAndDistinct() {
// The order of operators matter when using limit()
// If applying sort/distinct without limit, any order will result in the same query result.
realm.beginTransaction();
// Root object;
RealmList<AllJavaTypesUnsupportedTypes> list = realm.createObject(AllJavaTypesUnsupportedTypes.class, -1).getFieldList();
for (int i = 0; i < 5; i++) {
AllJavaTypesUnsupportedTypes obj = realm.createObject(AllJavaTypesUnsupportedTypes.class, i);
obj.setFieldLong(i);
list.add(obj);
}
realm.commitTransaction();
RealmResults<AllJavaTypesUnsupportedTypes> results = list.where().sort(AllJavaTypesUnsupportedTypes.FIELD_LONG, // [4, 4, 3, 3, 2, 2, 1, 1, 0, 0]
Sort.DESCENDING).distinct(// [4, 3, 2, 1, 0]
AllJavaTypesUnsupportedTypes.FIELD_LONG).limit(// [4, 3]
2).findAll();
assertEquals(2, results.size());
assertEquals(4, results.first().getFieldLong());
assertEquals(3, results.last().getFieldLong());
results = list.where().limit(// [0, 1]
2).distinct(// [ 0, 1]
AllJavaTypesUnsupportedTypes.FIELD_LONG).sort(AllJavaTypesUnsupportedTypes.FIELD_LONG, // [1, 0]
Sort.DESCENDING).findAll();
assertEquals(2, results.size());
assertEquals(1, results.first().getFieldLong());
assertEquals(0, results.last().getFieldLong());
results = list.where().distinct(// [ 0, 1, 2, 3, 4]
AllJavaTypesUnsupportedTypes.FIELD_LONG).limit(// [0, 1]
2).sort(AllJavaTypesUnsupportedTypes.FIELD_LONG, // [1, 0]
Sort.DESCENDING).findAll();
assertEquals(2, results.size());
assertEquals(1, results.first().getFieldLong());
assertEquals(0, results.last().getFieldLong());
}
use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.
the class RealmQueryTests method populateForDistinctInvalidTypesLinked.
private void populateForDistinctInvalidTypesLinked(Realm realm) {
realm.beginTransaction();
AllJavaTypesUnsupportedTypes notEmpty = new AllJavaTypesUnsupportedTypes();
notEmpty.setFieldBinary(new byte[] { 1, 2, 3 });
notEmpty.setFieldObject(notEmpty);
notEmpty.setFieldList(new RealmList<AllJavaTypesUnsupportedTypes>(notEmpty));
realm.copyToRealm(notEmpty);
realm.commitTransaction();
}
use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.
the class QueryTests method createIsEmptyDataSet.
@SuppressWarnings("unchecked")
protected final void createIsEmptyDataSet(Realm realm) {
realm.beginTransaction();
AllJavaTypesUnsupportedTypes emptyValues = new AllJavaTypesUnsupportedTypes();
emptyValues.setFieldId(1);
emptyValues.setFieldString("");
emptyValues.setFieldBinary(new byte[0]);
emptyValues.setFieldObject(emptyValues);
emptyValues.setFieldList(new RealmList<>());
emptyValues.setColumnRealmDictionary(new RealmDictionary<>());
AllJavaTypesUnsupportedTypes emptyValuesManaged = realm.copyToRealm(emptyValues);
AllJavaTypesUnsupportedTypes nonEmpty = new AllJavaTypesUnsupportedTypes();
nonEmpty.setFieldId(2);
nonEmpty.setFieldString("Foo");
nonEmpty.setFieldBinary(new byte[] { 1, 2, 3 });
nonEmpty.setFieldObject(nonEmpty);
nonEmpty.setFieldList(new RealmList<>(emptyValuesManaged));
AllJavaTypesUnsupportedTypes nonEmptyManaged = realm.copyToRealmOrUpdate(nonEmpty);
AllJavaTypesUnsupportedTypes emptyValues2 = new AllJavaTypesUnsupportedTypes();
emptyValues2.setFieldId(3);
emptyValues2.setFieldString("");
emptyValues2.setFieldBinary(new byte[0]);
emptyValues2.setFieldObject(null);
emptyValues2.setFieldList(new RealmList<>(nonEmptyManaged));
emptyValues2.setColumnRealmDictionary(new RealmDictionary<>());
realm.copyToRealm(emptyValues2);
realm.commitTransaction();
}
Aggregations