use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class RealmQueryTests method createBinaryOnlyDataSet.
private void createBinaryOnlyDataSet() {
realm.beginTransaction();
for (int i = 0; i < binaries.length; i++) {
AllJavaTypes binaryOnly = new AllJavaTypes((long) i);
binaryOnly.setFieldBinary(binaries[i]);
realm.copyToRealm(binaryOnly);
}
realm.commitTransaction();
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class RealmQueryTests method populateForDistinctInvalidTypesLinked.
private void populateForDistinctInvalidTypesLinked(Realm realm) {
realm.beginTransaction();
AllJavaTypes notEmpty = new AllJavaTypes();
notEmpty.setFieldBinary(new byte[] { 1, 2, 3 });
notEmpty.setFieldObject(notEmpty);
notEmpty.setFieldList(new RealmList<AllJavaTypes>(notEmpty));
realm.copyToRealm(notEmpty);
realm.commitTransaction();
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class BulkInsertTests method insert_duplicatedPrimaryKeyFails.
@Test
public void insert_duplicatedPrimaryKeyFails() {
// Single object with 2 references to two objects with the same ID
AllJavaTypes obj = new AllJavaTypes(2);
obj.setFieldList(new RealmList<AllJavaTypes>(new AllJavaTypes(1), new AllJavaTypes(1)));
realm.beginTransaction();
try {
realm.insert(obj);
fail();
} catch (RealmPrimaryKeyConstraintException ignored) {
} finally {
realm.cancelTransaction();
}
// Two objects with the same ID in a list
realm.beginTransaction();
try {
realm.insert(Arrays.asList(new AllJavaTypes(1), new AllJavaTypes(1)));
fail();
} catch (RealmPrimaryKeyConstraintException ignored) {
} finally {
realm.cancelTransaction();
}
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class BulkInsertTests method insertOrUpdate_linkingManagedToUnmanagedObject.
@Test
public void insertOrUpdate_linkingManagedToUnmanagedObject() {
realm.beginTransaction();
AllJavaTypes managedAllJavaTypes = realm.createObject(AllJavaTypes.class, 42);
realm.commitTransaction();
AllJavaTypes unmanagedObject = new AllJavaTypes(8);
//Linking managed object to unmanaged object
unmanagedObject.setFieldObject(managedAllJavaTypes);
realm.beginTransaction();
realm.insertOrUpdate(unmanagedObject);
realm.commitTransaction();
AllJavaTypes first = realm.where(AllJavaTypes.class).equalTo(AllJavaTypes.FIELD_ID, 8).findFirst();
assertNotNull(first);
assertEquals(8, first.getFieldId(), 0);
assertNotNull(first.getFieldObject());
assertEquals(42, first.getFieldObject().getFieldId());
assertEquals(2, realm.where(AllJavaTypes.class).count());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsUnmanagedTests method copyToAndFromRealm.
// Test round-trip
@Test
public void copyToAndFromRealm() {
AllJavaTypes unmanagedChild = new AllJavaTypes(1);
realm.beginTransaction();
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
realm.commitTransaction();
assertEquals(new AllJavaTypes().getObjectParents(), unmanagedChild.getObjectParents());
realm.beginTransaction();
AllJavaTypes child = realm.copyToRealm(unmanagedChild);
parent.setFieldObject(child);
realm.commitTransaction();
RealmResults<AllJavaTypes> parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertEquals(parent, parents.first());
unmanagedChild = realm.copyFromRealm(child);
assertEquals(unmanagedChild.getFieldId(), 1);
assertEquals(new AllJavaTypes().getObjectParents(), unmanagedChild.getObjectParents());
RealmResults<AllJavaTypes> queryResults = realm.where(AllJavaTypes.class).equalTo("fieldId", 1).findAll();
assertEquals(1, queryResults.size());
child = queryResults.first();
parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertEquals(parent, parents.first());
}
Aggregations