use of io.realm.internal.Table in project realm-java by realm.
the class RealmAnnotationTests method index.
// Tests if "index" annotation works with supported types.
@Test
public void index() {
Table table = realm.getTable(AnnotationIndexTypes.class);
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexString")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexString")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexInt")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexInt")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexByte")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexByte")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexShort")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexShort")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexLong")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexLong")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexBoolean")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexBoolean")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexDate")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexDate")));
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmAnnotationTests method primaryKey_migration_longDuplicateValues.
// Tests migrating primary key from string to long with existing data.
@Test
public void primaryKey_migration_longDuplicateValues() {
realm.beginTransaction();
for (int i = 1; i <= 2; i++) {
PrimaryKeyAsString obj = realm.createObject(PrimaryKeyAsString.class, "String" + i);
// Creates duplicate values.
obj.setId(1);
}
Table table = realm.getTable(PrimaryKeyAsString.class);
try {
table.setPrimaryKey("id");
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.internal.Table in project realm-java by realm.
the class RealmAnnotationTests method ignore.
@Test
public void ignore() {
Table table = realm.getTable(AnnotationTypes.class);
assertEquals(-1, table.getColumnIndex("ignoreString"));
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmAnnotationTests method primaryKey_migration_string.
// Tests migrating primary key from long to str with existing data.
@Test
public void primaryKey_migration_string() {
realm.beginTransaction();
for (int i = 1; i <= 2; i++) {
PrimaryKeyAsLong obj = realm.createObject(PrimaryKeyAsLong.class, i);
obj.setName("String" + i);
}
Table table = realm.getTable(PrimaryKeyAsLong.class);
table.setPrimaryKey("name");
assertEquals(1, table.getPrimaryKey());
realm.cancelTransaction();
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmMigrationTests method renamePrimaryKeyFieldInMigration.
// Renaming the class should also rename the the class entry in the pk metadata table that tracks primary keys.
@Test
public void renamePrimaryKeyFieldInMigration() {
buildInitialMigrationSchema(MigrationFieldRenamed.CLASS_NAME, false);
RealmMigration migration = new RealmMigration() {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
realm.getSchema().get(MigrationFieldRenamed.CLASS_NAME).renameField(MigrationPrimaryKey.FIELD_PRIMARY, MigrationFieldRenamed.FIELD_PRIMARY);
}
};
RealmConfiguration realmConfig = configFactory.createConfigurationBuilder().schemaVersion(1).schema(MigrationFieldRenamed.class).migration(migration).build();
Realm realm = Realm.getInstance(realmConfig);
Table table = realm.getSchema().getTable(MigrationFieldRenamed.class);
assertTrue(table.hasPrimaryKey());
assertEquals(MigrationFieldRenamed.DEFAULT_FIELDS_COUNT, table.getColumnCount());
assertEquals(MigrationFieldRenamed.DEFAULT_PRIMARY_INDEX, table.getPrimaryKey());
RealmObjectSchema objectSchema = realm.getSchema().getSchemaForClass(MigrationFieldRenamed.class);
assertFalse(objectSchema.hasField(MigrationPrimaryKey.FIELD_PRIMARY));
assertEquals(MigrationFieldRenamed.FIELD_PRIMARY, objectSchema.getPrimaryKey());
}
Aggregations