use of io.realm.entities.DogPrimaryKey in project realm-java by realm.
the class BulkInsertTests method insertOrUpdate.
@Test
public void insertOrUpdate() {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
AllTypesPrimaryKey obj = new AllTypesPrimaryKey();
obj.setColumnString("Foo");
obj.setColumnLong(1);
obj.setColumnFloat(1.23F);
obj.setColumnDouble(1.234D);
obj.setColumnBoolean(false);
obj.setColumnBinary(new byte[] { 1, 2, 3 });
obj.setColumnDate(new Date(1000));
obj.setColumnRealmObject(new DogPrimaryKey(1, "Dog1"));
obj.setColumnRealmList(new RealmList<DogPrimaryKey>(new DogPrimaryKey(2, "Dog2")));
obj.setColumnBoxedBoolean(true);
realm.insert(obj);
AllTypesPrimaryKey obj2 = new AllTypesPrimaryKey();
obj2.setColumnString("Bar");
obj2.setColumnLong(1);
obj2.setColumnFloat(2.23F);
obj2.setColumnDouble(2.234D);
obj2.setColumnBoolean(true);
obj2.setColumnBinary(new byte[] { 2, 3, 4 });
obj2.setColumnDate(new Date(2000));
obj2.setColumnRealmObject(new DogPrimaryKey(3, "Dog3"));
obj2.setColumnRealmList(new RealmList<DogPrimaryKey>(new DogPrimaryKey(4, "Dog4")));
obj2.setColumnBoxedBoolean(false);
realm.insertOrUpdate(obj2);
}
});
assertEquals(1, realm.where(AllTypesPrimaryKey.class).count());
AllTypesPrimaryKey obj = realm.where(AllTypesPrimaryKey.class).findFirst();
// Checks that the only element has all its properties updated.
assertNotNull(obj);
assertEquals("Bar", obj.getColumnString());
assertEquals(1, obj.getColumnLong());
assertEquals(2.23F, obj.getColumnFloat(), 0);
assertEquals(2.234D, obj.getColumnDouble(), 0);
assertEquals(true, obj.isColumnBoolean());
assertArrayEquals(new byte[] { 2, 3, 4 }, obj.getColumnBinary());
assertEquals(new Date(2000), obj.getColumnDate());
assertEquals("Dog3", obj.getColumnRealmObject().getName());
assertEquals(1, obj.getColumnRealmList().size());
assertEquals("Dog4", obj.getColumnRealmList().get(0).getName());
assertEquals(4, realm.where(DogPrimaryKey.class).findAll().size());
assertFalse(obj.getColumnBoxedBoolean());
}
Aggregations