Search in sources :

Example 1 with AllJavaTypesUnsupportedTypes

use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.

the class LinkingObjectsQueryTests method query_startWithBacklink.

// All the basic tests for is[Not](Equal|Null) are in RealmQueryTests
// Query on a field descriptor starting with a backlink
// Build a simple object graph.
// The test objects are:
// gen1
// / \
// gen2A gen2B
// \\   //
// gen3
// /  = object ref
// // = list ref
@Test
public void query_startWithBacklink() {
    realm.beginTransaction();
    AllJavaTypesUnsupportedTypes gen1 = realm.createObject(AllJavaTypesUnsupportedTypes.class, 10);
    AllJavaTypesUnsupportedTypes gen2A = realm.createObject(AllJavaTypesUnsupportedTypes.class, 1);
    gen2A.setFieldObject(gen1);
    AllJavaTypesUnsupportedTypes gen2B = realm.createObject(AllJavaTypesUnsupportedTypes.class, 2);
    gen2B.setFieldObject(gen1);
    AllJavaTypesUnsupportedTypes gen3 = realm.createObject(AllJavaTypesUnsupportedTypes.class, 3);
    RealmList<AllJavaTypesUnsupportedTypes> parents = gen3.getFieldList();
    parents.add(gen2A);
    parents.add(gen2B);
    realm.commitTransaction();
    // row 0: backlink to rows 1 and 2; row 1 link to row 0, included
    // row 1: no backlink, not included
    // row 2: no backlink, not included
    // row 3: no backlink, not included
    // summary: 1 row (gen1)
    RealmResults<AllJavaTypesUnsupportedTypes> result = realm.where(AllJavaTypesUnsupportedTypes.class).greaterThan(AllJavaTypesUnsupportedTypes.FIELD_LO_OBJECT + "." + AllJavaTypesUnsupportedTypes.FIELD_OBJECT + "." + AllJavaTypesUnsupportedTypes.FIELD_ID, 1).findAll();
    assertEquals(1, result.size());
    assertTrue(result.contains(gen1));
}
Also used : AllJavaTypesUnsupportedTypes(io.realm.entities.AllJavaTypesUnsupportedTypes) Test(org.junit.Test)

Example 2 with AllJavaTypesUnsupportedTypes

use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.

the class QueryTests method createIsNotEmptyDataSet.

@SuppressWarnings("unchecked")
protected final void createIsNotEmptyDataSet(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<>());
    realm.copyToRealm(emptyValues);
    AllJavaTypesUnsupportedTypes notEmpty = new AllJavaTypesUnsupportedTypes();
    notEmpty.setFieldId(2);
    notEmpty.setFieldString("Foo");
    notEmpty.setFieldBinary(new byte[] { 1, 2, 3 });
    notEmpty.setFieldObject(notEmpty);
    notEmpty.setFieldList(new RealmList<>(emptyValues));
    notEmpty.setFieldIntegerList(new RealmList<>(1));
    notEmpty.setFieldBooleanList(new RealmList<>(true));
    notEmpty.setFieldStringList(new RealmList<>("hello"));
    notEmpty.setFieldBinaryList(new RealmList<>(new byte[1]));
    notEmpty.setFieldDateList(new RealmList<>(new Date()));
    notEmpty.setFieldFloatList(new RealmList<>(1F));
    notEmpty.setFieldDoubleList(new RealmList<>(1.0));
    notEmpty.setFieldDecimal128List(new RealmList<>(new Decimal128(1L)));
    notEmpty.setFieldObjectIdList(new RealmList<>(new ObjectId()));
    notEmpty.setFieldUUIDList(new RealmList<>(UUID.randomUUID()));
    notEmpty.setFieldRealmAnyList(new RealmList<>(RealmAny.valueOf(1)));
    notEmpty.setColumnRealmDictionary((RealmDictionary<AllJavaTypesUnsupportedTypes>) getDictionary(RealmFieldType.STRING_TO_LINK_MAP, notEmpty));
    notEmpty.setColumnIntegerDictionary((RealmDictionary<Integer>) getDictionary(RealmFieldType.STRING_TO_INTEGER_MAP));
    notEmpty.setColumnBooleanDictionary((RealmDictionary<Boolean>) getDictionary(RealmFieldType.STRING_TO_BOOLEAN_MAP));
    notEmpty.setColumnStringDictionary((RealmDictionary<String>) getDictionary(RealmFieldType.STRING_TO_STRING_MAP));
    notEmpty.setColumnBinaryDictionary((RealmDictionary<byte[]>) getDictionary(RealmFieldType.STRING_TO_BINARY_MAP));
    notEmpty.setColumnDateDictionary((RealmDictionary<Date>) getDictionary(RealmFieldType.STRING_TO_DATE_MAP));
    notEmpty.setColumnFloatDictionary((RealmDictionary<Float>) getDictionary(RealmFieldType.STRING_TO_FLOAT_MAP));
    notEmpty.setColumnDoubleDictionary((RealmDictionary<Double>) getDictionary(RealmFieldType.STRING_TO_DOUBLE_MAP));
    notEmpty.setColumnDecimal128Dictionary((RealmDictionary<Decimal128>) getDictionary(RealmFieldType.STRING_TO_DECIMAL128_MAP));
    notEmpty.setColumnObjectIdDictionary((RealmDictionary<ObjectId>) getDictionary(RealmFieldType.STRING_TO_OBJECT_ID_MAP));
    notEmpty.setColumnUUIDDictionary((RealmDictionary<UUID>) getDictionary(RealmFieldType.STRING_TO_UUID_MAP));
    notEmpty.setColumnRealmAnyDictionary((RealmDictionary<RealmAny>) getDictionary(RealmFieldType.STRING_TO_MIXED_MAP));
    notEmpty.setColumnRealmSet((RealmSet<AllJavaTypesUnsupportedTypes>) getSet(RealmFieldType.LINK_SET, notEmpty));
    notEmpty.setColumnIntegerSet((RealmSet<Integer>) getSet(RealmFieldType.INTEGER_SET));
    notEmpty.setColumnBooleanSet((RealmSet<Boolean>) getSet(RealmFieldType.BOOLEAN_SET));
    notEmpty.setColumnStringSet((RealmSet<String>) getSet(RealmFieldType.STRING_SET));
    notEmpty.setColumnBinarySet((RealmSet<byte[]>) getSet(RealmFieldType.BINARY_SET));
    notEmpty.setColumnDateSet((RealmSet<Date>) getSet(RealmFieldType.DATE_SET));
    notEmpty.setColumnFloatSet((RealmSet<Float>) getSet(RealmFieldType.FLOAT_SET));
    notEmpty.setColumnDoubleSet((RealmSet<Double>) getSet(RealmFieldType.DOUBLE_SET));
    notEmpty.setColumnDecimal128Set((RealmSet<Decimal128>) getSet(RealmFieldType.DECIMAL128_SET));
    notEmpty.setColumnObjectIdSet((RealmSet<ObjectId>) getSet(RealmFieldType.OBJECT_ID_SET));
    notEmpty.setColumnUUIDSet((RealmSet<UUID>) getSet(RealmFieldType.UUID_SET));
    notEmpty.setColumnRealmAnySet((RealmSet<RealmAny>) getSet(RealmFieldType.MIXED_SET));
    realm.copyToRealmOrUpdate(notEmpty);
    realm.commitTransaction();
}
Also used : ObjectId(org.bson.types.ObjectId) AllJavaTypesUnsupportedTypes(io.realm.entities.AllJavaTypesUnsupportedTypes) Decimal128(org.bson.types.Decimal128) UUID(java.util.UUID) Date(java.util.Date)

Example 3 with AllJavaTypesUnsupportedTypes

use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.

the class RealmQueryTests method callThreadConfinedMethodsFromWrongThread.

@Test
public void callThreadConfinedMethodsFromWrongThread() throws Throwable {
    final RealmQuery<AllJavaTypesUnsupportedTypes> query = realm.where(AllJavaTypesUnsupportedTypes.class);
    final CountDownLatch testFinished = new CountDownLatch(1);
    final String expectedMessage;
    // noinspection TryWithIdenticalCatches
    try {
        final Field expectedMessageField = BaseRealm.class.getDeclaredField("INCORRECT_THREAD_MESSAGE");
        expectedMessageField.setAccessible(true);
        expectedMessage = (String) expectedMessageField.get(null);
    } catch (NoSuchFieldException e) {
        throw new AssertionError(e);
    } catch (IllegalAccessException e) {
        throw new AssertionError(e);
    }
    final Thread thread = new Thread("callThreadConfinedMethodsFromWrongThread") {

        @Override
        public void run() {
            try {
                for (ThreadConfinedMethods method : ThreadConfinedMethods.values()) {
                    try {
                        callThreadConfinedMethod(query, method);
                        fail("IllegalStateException must be thrown.");
                    } catch (IllegalStateException e) {
                        assertEquals(expectedMessage, e.getMessage());
                    }
                }
            } finally {
                testFinished.countDown();
            }
        }
    };
    thread.start();
    TestHelper.awaitOrFail(testFinished);
}
Also used : Field(java.lang.reflect.Field) AllJavaTypesUnsupportedTypes(io.realm.entities.AllJavaTypesUnsupportedTypes) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) CountDownLatch(java.util.concurrent.CountDownLatch) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 4 with AllJavaTypesUnsupportedTypes

use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.

the class LinkingObjectsQueryTests method query_backlinkInMiddle.

// Query on a field descriptor that has a backlink in the middle
// Build a simple object graph.
// The test objects are:
// gen1
// / \
// gen2A gen2B
// \\   //
// gen3
// /  = object ref
// // = list ref
@Test
public void query_backlinkInMiddle() {
    realm.beginTransaction();
    AllJavaTypesUnsupportedTypes gen1 = realm.createObject(AllJavaTypesUnsupportedTypes.class, 10);
    AllJavaTypesUnsupportedTypes gen2A = realm.createObject(AllJavaTypesUnsupportedTypes.class, 1);
    gen2A.setFieldObject(gen1);
    AllJavaTypesUnsupportedTypes gen2B = realm.createObject(AllJavaTypesUnsupportedTypes.class, 2);
    gen2B.setFieldObject(gen1);
    AllJavaTypesUnsupportedTypes gen3 = realm.createObject(AllJavaTypesUnsupportedTypes.class, 3);
    RealmList<AllJavaTypesUnsupportedTypes> parents = gen3.getFieldList();
    parents.add(gen2A);
    parents.add(gen2B);
    realm.commitTransaction();
    // row 0: no link, not included
    // row 1: link to row 0, backlink to rows 1 and 2, row 2 has id < 2, included
    // row 2: link to row 0, backlink to rows 1 and 2, row 2 has id < 2, included
    // row 3: no link, not included
    // summary: 2 rows (gen2A and gen2B)
    RealmResults<AllJavaTypesUnsupportedTypes> result = realm.where(AllJavaTypesUnsupportedTypes.class).lessThan(AllJavaTypesUnsupportedTypes.FIELD_OBJECT + "." + AllJavaTypesUnsupportedTypes.FIELD_LO_OBJECT + "." + AllJavaTypesUnsupportedTypes.FIELD_ID, 2).findAll();
    assertEquals(2, result.size());
    assertTrue(result.contains(gen2A));
    assertTrue(result.contains(gen2B));
}
Also used : AllJavaTypesUnsupportedTypes(io.realm.entities.AllJavaTypesUnsupportedTypes) Test(org.junit.Test)

Example 5 with AllJavaTypesUnsupportedTypes

use of io.realm.entities.AllJavaTypesUnsupportedTypes in project realm-java by realm.

the class RealmQueryTests method createBinaryOnlyDataSet.

private void createBinaryOnlyDataSet() {
    realm.beginTransaction();
    for (int i = 0; i < binaries.length; i++) {
        AllJavaTypesUnsupportedTypes binaryOnly = new AllJavaTypesUnsupportedTypes((long) i);
        binaryOnly.setFieldBinary(binaries[i]);
        realm.copyToRealm(binaryOnly);
    }
    realm.commitTransaction();
}
Also used : AllJavaTypesUnsupportedTypes(io.realm.entities.AllJavaTypesUnsupportedTypes)

Aggregations

AllJavaTypesUnsupportedTypes (io.realm.entities.AllJavaTypesUnsupportedTypes)8 Test (org.junit.Test)4 UiThreadTest (androidx.test.annotation.UiThreadTest)2 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)1 Field (java.lang.reflect.Field)1 Date (java.util.Date)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Decimal128 (org.bson.types.Decimal128)1 ObjectId (org.bson.types.ObjectId)1