use of io.realm.entities.PrimaryKeyAsLong in project realm-java by realm.
the class RealmAnnotationTests method primaryKey_migration_stringDuplicateValues.
// Tests migrating primary key from long to str with existing data.
@Test
public void primaryKey_migration_stringDuplicateValues() {
realm.beginTransaction();
for (int i = 1; i <= 2; i++) {
PrimaryKeyAsLong obj = realm.createObject(PrimaryKeyAsLong.class, i);
// Creates duplicate values.
obj.setName("String");
}
Table table = realm.getTable(PrimaryKeyAsLong.class);
try {
table.setPrimaryKey("name");
fail("It should not be possible to set a primary key column which already contains duplicate values.");
} catch (IllegalArgumentException ignored) {
assertEquals(0, table.getPrimaryKey());
} finally {
realm.cancelTransaction();
}
}
use of io.realm.entities.PrimaryKeyAsLong in project realm-java by realm.
the class RealmTests method isEmpty.
@Test
public void isEmpty() {
RealmConfiguration realmConfig = configFactory.createConfiguration("empty_test.realm");
Realm emptyRealm = Realm.getInstance(realmConfig);
assertTrue(emptyRealm.isEmpty());
emptyRealm.beginTransaction();
PrimaryKeyAsLong obj = new PrimaryKeyAsLong();
obj.setId(1);
obj.setName("Foo");
emptyRealm.copyToRealm(obj);
assertFalse(emptyRealm.isEmpty());
emptyRealm.cancelTransaction();
assertTrue(emptyRealm.isEmpty());
emptyRealm.beginTransaction();
obj = new PrimaryKeyAsLong();
obj.setId(1);
obj.setName("Foo");
emptyRealm.copyToRealm(obj);
emptyRealm.commitTransaction();
assertFalse(emptyRealm.isEmpty());
emptyRealm.close();
}
Aggregations