use of io.realm.internal.Table in project realm-java by realm.
the class BooleansRealmProxy method insertOrUpdate.
public static long insertOrUpdate(Realm realm, some.test.Booleans object, Map<RealmModel, Long> cache) {
if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().getPath().equals(realm.getPath())) {
return ((RealmObjectProxy) object).realmGet$proxyState().getRow$realm().getIndex();
}
Table table = realm.getTable(some.test.Booleans.class);
long tableNativePtr = table.getNativeTablePointer();
BooleansColumnInfo columnInfo = (BooleansColumnInfo) realm.schema.getColumnInfo(some.test.Booleans.class);
long rowIndex = Table.nativeAddEmptyRow(tableNativePtr, 1);
cache.put(object, rowIndex);
Table.nativeSetBoolean(tableNativePtr, columnInfo.doneIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$done(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.isReadyIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$isReady(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.mCompletedIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$mCompleted(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.anotherBooleanIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$anotherBoolean(), false);
return rowIndex;
}
use of io.realm.internal.Table in project realm-java by realm.
the class BooleansRealmProxy method initTable.
public static Table initTable(SharedRealm sharedRealm) {
if (!sharedRealm.hasTable("class_Booleans")) {
Table table = sharedRealm.getTable("class_Booleans");
table.addColumn(RealmFieldType.BOOLEAN, "done", Table.NOT_NULLABLE);
table.addColumn(RealmFieldType.BOOLEAN, "isReady", Table.NOT_NULLABLE);
table.addColumn(RealmFieldType.BOOLEAN, "mCompleted", Table.NOT_NULLABLE);
table.addColumn(RealmFieldType.BOOLEAN, "anotherBoolean", Table.NOT_NULLABLE);
table.setPrimaryKey("");
return table;
}
return sharedRealm.getTable("class_Booleans");
}
use of io.realm.internal.Table in project realm-java by realm.
the class BooleansRealmProxy method insert.
public static void insert(Realm realm, Iterator<? extends RealmModel> objects, Map<RealmModel, Long> cache) {
Table table = realm.getTable(some.test.Booleans.class);
long tableNativePtr = table.getNativeTablePointer();
BooleansColumnInfo columnInfo = (BooleansColumnInfo) realm.schema.getColumnInfo(some.test.Booleans.class);
some.test.Booleans object = null;
while (objects.hasNext()) {
object = (some.test.Booleans) objects.next();
if (!cache.containsKey(object)) {
if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().getPath().equals(realm.getPath())) {
cache.put(object, ((RealmObjectProxy) object).realmGet$proxyState().getRow$realm().getIndex());
continue;
}
long rowIndex = Table.nativeAddEmptyRow(tableNativePtr, 1);
cache.put(object, rowIndex);
Table.nativeSetBoolean(tableNativePtr, columnInfo.doneIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$done(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.isReadyIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$isReady(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.mCompletedIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$mCompleted(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.anotherBooleanIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$anotherBoolean(), false);
}
}
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmMigrationTests method removeFieldsBeforePrimaryKey.
// Removing fields before a pk field does not affect the pk.
@Test
public void removeFieldsBeforePrimaryKey() {
buildInitialMigrationSchema(MigrationPosteriorIndexOnly.CLASS_NAME, false);
RealmMigration migration = new RealmMigration() {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
realm.getSchema().get(MigrationPosteriorIndexOnly.CLASS_NAME).removeField(MigrationPrimaryKey.FIELD_FIRST).removeField(MigrationPrimaryKey.FIELD_SECOND);
}
};
RealmConfiguration realmConfig = configFactory.createConfigurationBuilder().schemaVersion(1).schema(MigrationPosteriorIndexOnly.class).migration(migration).build();
Realm realm = Realm.getInstance(realmConfig);
Table table = realm.getSchema().getTable(MigrationPosteriorIndexOnly.class);
assertTrue(table.hasPrimaryKey());
assertEquals(MigrationPosteriorIndexOnly.DEFAULT_FIELDS_COUNT, table.getColumnCount());
assertEquals(MigrationPosteriorIndexOnly.DEFAULT_PRIMARY_INDEX, table.getPrimaryKey());
assertEquals(MigrationPosteriorIndexOnly.FIELD_PRIMARY, table.getColumnName(table.getPrimaryKey()));
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmMigrationTests method addingSearchIndexTwice.
// Adding search index is idempotent.
@Test
public void addingSearchIndexTwice() throws IOException {
final Class[] classes = { PrimaryKeyAsLong.class, PrimaryKeyAsString.class };
for (final Class clazz : classes) {
final AtomicBoolean didMigrate = new AtomicBoolean(false);
RealmMigration migration = new RealmMigration() {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
RealmObjectSchema schema = realm.getSchema().getSchemaForClass(clazz.getSimpleName());
schema.addIndex("id");
// @PrimaryKey fields in PrimaryKeyAsLong and PrimaryKeyAsString.class should be set 'nullable'.
schema.setNullable("name", true);
didMigrate.set(true);
}
};
RealmConfiguration realmConfig = configFactory.createConfigurationBuilder().schemaVersion(42).schema(clazz).migration(migration).build();
Realm.deleteRealm(realmConfig);
configFactory.copyRealmFromAssets(context, "default-before-migration.realm", Realm.DEFAULT_REALM_NAME);
Realm.migrateRealm(realmConfig);
realm = Realm.getInstance(realmConfig);
assertEquals(42, realm.getVersion());
assertTrue(didMigrate.get());
Table table = realm.getTable(clazz);
assertEquals(true, table.hasSearchIndex(table.getColumnIndex("id")));
realm.close();
}
}
Aggregations