use of io.realm.entities.pojo.AllTypesRealmModel in project realm-java by realm.
the class RealmChangeListenerTests method returnedRealmResultsOfModelIsNotNull.
@Test
@RunTestInLooperThread
public void returnedRealmResultsOfModelIsNotNull() {
Realm realm = looperThread.realm;
RealmResults<AllTypesRealmModel> alltypes = realm.where(AllTypesRealmModel.class).findAll();
looperThread.keepStrongReference.add(alltypes);
alltypes.addChangeListener(new RealmChangeListener<RealmResults<AllTypesRealmModel>>() {
@Override
public void onChange(RealmResults<AllTypesRealmModel> result) {
assertEquals("data 1", result.first().columnString);
looperThread.testComplete();
}
});
realm.beginTransaction();
AllTypesRealmModel model = realm.createObject(AllTypesRealmModel.class, 0);
model.columnString = "data 1";
realm.commitTransaction();
}
use of io.realm.entities.pojo.AllTypesRealmModel in project realm-java by realm.
the class RealmModelTests method populateTestRealm.
private void populateTestRealm(Realm realm, int objects) {
realm.beginTransaction();
realm.delete(AllTypesRealmModel.class);
for (int i = 0; i < objects; ++i) {
AllTypesRealmModel allTypes = new AllTypesRealmModel();
allTypes.columnLong = i;
allTypes.columnBoolean = (i % 3) == 0;
allTypes.columnBinary = new byte[] { 1, 2, 3 };
allTypes.columnDate = new Date();
allTypes.columnDouble = 3.1415 + i;
allTypes.columnFloat = 1.234567f;
allTypes.columnString = "test data ";
allTypes.columnByte = 0x2A;
realm.copyToRealm(allTypes);
}
realm.commitTransaction();
}
use of io.realm.entities.pojo.AllTypesRealmModel in project realm-java by realm.
the class RealmModelTests method copyFromRealm.
@Test
public void copyFromRealm() {
populateTestRealm(realm, TEST_DATA_SIZE);
AllTypesRealmModel realmObject = realm.where(AllTypesRealmModel.class).findAllSorted(AllTypesRealmModel.FIELD_LONG).first();
AllTypesRealmModel unmanagedObject = realm.copyFromRealm(realmObject);
assertArrayEquals(realmObject.columnBinary, unmanagedObject.columnBinary);
assertEquals(realmObject.columnString, unmanagedObject.columnString);
assertEquals(realmObject.columnLong, unmanagedObject.columnLong);
assertEquals(realmObject.columnFloat, unmanagedObject.columnFloat, 0.00000000001);
assertEquals(realmObject.columnDouble, unmanagedObject.columnDouble, 0.00000000001);
assertEquals(realmObject.columnBoolean, unmanagedObject.columnBoolean);
assertEquals(realmObject.columnDate, unmanagedObject.columnDate);
assertEquals(realmObject.hashCode(), unmanagedObject.hashCode());
}
use of io.realm.entities.pojo.AllTypesRealmModel in project realm-java by realm.
the class RealmModelTests method dynamicObject.
@Test
public void dynamicObject() {
populateTestRealm(realm, TEST_DATA_SIZE);
AllTypesRealmModel typedObj = realm.where(AllTypesRealmModel.class).findFirst();
assertNotNull(typedObj);
DynamicRealmObject dObj = new DynamicRealmObject(typedObj);
realm.beginTransaction();
dObj.setByte(AllTypesRealmModel.FIELD_BYTE, (byte) 42);
assertEquals(42, dObj.getLong(AllTypesRealmModel.FIELD_BYTE));
assertEquals(42, typedObj.columnByte);
dObj.setBlob(AllTypesRealmModel.FIELD_BINARY, new byte[] { 1, 2, 3 });
Assert.assertArrayEquals(new byte[] { 1, 2, 3 }, dObj.getBlob(AllTypesRealmModel.FIELD_BINARY));
Assert.assertArrayEquals(new byte[] { 1, 2, 3 }, typedObj.columnBinary);
realm.cancelTransaction();
}
use of io.realm.entities.pojo.AllTypesRealmModel in project realm-java by realm.
the class RealmModelTests method realmModelWithRealmModelField.
// Tests the behaviour of a RealmModel, containing a RealmModel field.
@Test
public void realmModelWithRealmModelField() {
RealmModelWithRealmModelField realmModelWithRealmModelField = new RealmModelWithRealmModelField();
AllTypesRealmModel allTypePojo = new AllTypesRealmModel();
allTypePojo.columnLong = 42;
realmModelWithRealmModelField.setAllTypesRealmModel(allTypePojo);
realm.beginTransaction();
realm.copyToRealm(realmModelWithRealmModelField);
realm.commitTransaction();
RealmResults<RealmModelWithRealmModelField> all = realm.where(RealmModelWithRealmModelField.class).findAll();
assertEquals(1, all.size());
assertEquals(42, all.first().getAllTypesRealmModel().columnLong);
}
Aggregations