use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method basic_multipleBacklinksObject.
// Setting multiple object links creates multiple backlinks
@Test
public void basic_multipleBacklinksObject() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent1 = realm.createObject(AllJavaTypes.class, 2);
AllJavaTypes parent2 = realm.createObject(AllJavaTypes.class, 3);
parent1.setFieldObject(child);
parent2.setFieldObject(child);
realm.commitTransaction();
assertEquals(2, child.getObjectParents().size());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method notification_onDeleteModelObject.
// A listener registered on the backlinked object should be called when a backlinked object is deleted
@Test
@RunTestInLooperThread
public void notification_onDeleteModelObject() {
final Realm looperThreadRealm = looperThread.realm;
looperThreadRealm.beginTransaction();
AllJavaTypes child = looperThreadRealm.createObject(AllJavaTypes.class, 10);
AllJavaTypes parent = looperThreadRealm.createObject(AllJavaTypes.class, 1);
parent.setFieldObject(child);
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();
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());
assertEquals(1, counter.get());
}
}, child, parent);
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method notification_notSentAfterUnregisterListenerModelObject.
// A listener registered on the backlinked object should not be called after the listener is removed
@Test
@RunTestInLooperThread
public void notification_notSentAfterUnregisterListenerModelObject() {
final Realm looperThreadRealm = looperThread.realm;
looperThreadRealm.beginTransaction();
AllJavaTypes child = looperThreadRealm.createObject(AllJavaTypes.class, 10);
looperThreadRealm.commitTransaction();
RealmChangeListener<AllJavaTypes> listener = new RealmChangeListener<AllJavaTypes>() {
@Override
public void onChange(AllJavaTypes object) {
fail("Not expecting notification after unregister");
}
};
child.addChangeListener(listener);
child.removeChangeListener(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());
}
}, child, parent);
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method query_startWithBacklink.
// Query on a field descriptor starting with a backlink
// The test objects are:
// gen1
// / \
// gen2A gen2B
// \\ //
// gen3
// / = object ref
// // = list ref
@Test
@Ignore
public void query_startWithBacklink() {
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).greaterThan("objectParents.fieldId", 1).findAll();
assertEquals(1, result.size());
assertTrue(result.contains(gen2B));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsUnmanagedTests method copyFromRealm.
// When unmanaged, an object's backlinks fields have their initialized value (probably null).
@Test
public void copyFromRealm() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
parent.setFieldObject(child);
realm.commitTransaction();
assertEquals(1, child.getObjectParents().size());
assertEquals(parent, child.getObjectParents().first());
AllJavaTypes unmanagedChild = realm.copyFromRealm(child);
assertEquals(new AllJavaTypes().getObjectParents(), unmanagedChild.getObjectParents());
}
Aggregations