use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method query_endWithBacklink.
// Query on a field descriptor that ends with a backlink
// The test objects are:
// gen1
// / \
// gen2A gen2B
// \\ //
// gen3
// / = object ref
// // = list ref
@Test
@Ignore
public void query_endWithBacklink() {
realm.beginTransaction();
AllJavaTypes gen1 = realm.createObject(AllJavaTypes.class, 10);
AllJavaTypes gen2A = realm.createObject(AllJavaTypes.class, 1);
gen2A.setFieldObject(gen1);
AllJavaTypes gen2B = realm.createObject(AllJavaTypes.class, 2);
gen2B.setFieldObject(gen1);
AllJavaTypes gen3 = realm.createObject(AllJavaTypes.class, 3);
RealmList<AllJavaTypes> parents = gen3.getFieldList();
parents.add(gen2A);
parents.add(gen2B);
realm.commitTransaction();
RealmResults<AllJavaTypes> result = realm.where(AllJavaTypes.class).isNotNull("objectParents.listParents").findAll();
assertEquals(2, result.size());
assertTrue(result.contains(gen2A));
assertTrue(result.contains(gen2B));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method notification_notSentOnUnrelatedChangeRealmResults.
// A listener registered on the backlinked object should not called for an unrelated change
@Test
@RunTestInLooperThread
public void notification_notSentOnUnrelatedChangeRealmResults() {
final Realm looperThreadRealm = looperThread.realm;
looperThreadRealm.beginTransaction();
AllJavaTypes child = looperThreadRealm.createObject(AllJavaTypes.class, 10);
AllJavaTypes parent = looperThreadRealm.createObject(AllJavaTypes.class, 1);
looperThreadRealm.commitTransaction();
RealmChangeListener<RealmResults<AllJavaTypes>> listener = new RealmChangeListener<RealmResults<AllJavaTypes>>() {
@Override
public void onChange(RealmResults<AllJavaTypes> object) {
fail("Not expecting notification after unregister");
}
};
child.getObjectParents().addChangeListener(listener);
looperThreadRealm.beginTransaction();
looperThreadRealm.where(AllJavaTypes.class).equalTo("fieldId", 1).findAll().deleteAllFromRealm();
looperThreadRealm.commitTransaction();
verifyPostConditions(looperThreadRealm, new PostConditions() {
public void run(Realm realm) {
assertEquals(1, looperThreadRealm.where(AllJavaTypes.class).findAll().size());
}
}, child, parent);
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method query_multipleReferencesWithDistinct.
// Distinct works for backlinks
@Test
public void query_multipleReferencesWithDistinct() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
parent.getFieldList().add(child);
parent.getFieldList().add(child);
realm.commitTransaction();
assertEquals(2, child.getListParents().size());
RealmResults<AllJavaTypes> distinctParents = child.getListParents().where().distinct("fieldId");
assertEquals(1, distinctParents.size());
assertTrue(child.getListParents().contains(parent));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method json_updateObject.
// Fields annotated with @LinkingObjects should not be affected by JSON updates
@Test
public void json_updateObject() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
parent.setFieldObject(child);
realm.commitTransaction();
RealmResults<AllJavaTypes> parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
realm.beginTransaction();
try {
realm.createOrUpdateAllFromJson(AllJavaTypes.class, "[{ \"fieldId\" : 1, \"objectParents\" : null }]");
} catch (RealmException e) {
fail("Failed loading JSON" + e);
}
realm.commitTransaction();
parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method notification_onCommitModelObject.
// A listener registered on the backlinked object should be called when a commit adds a backlink
@Test
@RunTestInLooperThread
public void notification_onCommitModelObject() {
final Realm looperThreadRealm = looperThread.realm;
looperThreadRealm.beginTransaction();
AllJavaTypes child = looperThreadRealm.createObject(AllJavaTypes.class, 10);
looperThreadRealm.commitTransaction();
final AtomicInteger counter = new AtomicInteger(0);
RealmChangeListener<AllJavaTypes> listener = new RealmChangeListener<AllJavaTypes>() {
@Override
public void onChange(AllJavaTypes object) {
counter.incrementAndGet();
}
};
child.addChangeListener(listener);
looperThreadRealm.beginTransaction();
AllJavaTypes parent = looperThreadRealm.createObject(AllJavaTypes.class, 1);
parent.setFieldObject(child);
looperThreadRealm.commitTransaction();
verifyPostConditions(looperThreadRealm, new PostConditions() {
public void run(Realm realm) {
assertEquals(2, looperThreadRealm.where(AllJavaTypes.class).findAll().size());
assertEquals(1, counter.get());
}
}, child, parent);
}
Aggregations