use of io.realm.internal.Table in project realm-java by realm.
the class IOSRealmTests method iOSDataTypes.
@Test
public void iOSDataTypes() throws IOException {
for (String iosVersion : IOS_VERSIONS) {
configFactory.copyRealmFromAssets(context, "ios/" + iosVersion + "-alltypes.realm", REALM_NAME);
realm = Realm.getDefaultInstance();
RealmResults<IOSAllTypes> result = realm.where(IOSAllTypes.class).findAllSorted("id", Sort.ASCENDING);
// Verifies metadata.
Table table = realm.getTable(IOSAllTypes.class);
assertTrue(table.hasPrimaryKey());
assertTrue(table.hasSearchIndex(table.getColumnIndex("id")));
// Iterative check.
for (int i = 0; i < 10; i++) {
IOSAllTypes obj = result.get(i);
assertTrue(obj.isBoolCol());
assertEquals(i + 1, obj.getShortCol());
assertEquals(10 + i, obj.getIntCol());
assertEquals(100 + i, obj.getLongCol());
assertEquals(100000000L + (long) i, obj.getLongLongCol());
assertEquals(1.23F + (float) i, obj.getFloatCol(), 0F);
assertEquals(1.234D + (double) i, obj.getDoubleCol(), 0D);
assertArrayEquals(new byte[] { 1, 2, 3 }, obj.getByteCol());
assertEquals("String " + Integer.toString(i), obj.getStringCol());
assertEquals(new Date((1000 + i) * 1000), obj.getDateCol());
assertEquals("Foo", result.get(i).getChild().getName());
assertEquals(10, result.get(i).getChildren().size());
for (int j = 0; j < 10; j++) {
assertEquals("Name: " + Integer.toString(i), result.get(i).getChildren().get(j).getName());
}
}
}
}
use of io.realm.internal.Table in project realm-java by realm.
the class NullTypesRealmProxy method insert.
public static void insert(Realm realm, Iterator<? extends RealmModel> objects, Map<RealmModel, Long> cache) {
Table table = realm.getTable(some.test.NullTypes.class);
long tableNativePtr = table.getNativeTablePointer();
NullTypesColumnInfo columnInfo = (NullTypesColumnInfo) realm.schema.getColumnInfo(some.test.NullTypes.class);
some.test.NullTypes object = null;
while (objects.hasNext()) {
object = (some.test.NullTypes) 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);
String realmGet$fieldStringNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldStringNotNull();
if (realmGet$fieldStringNotNull != null) {
Table.nativeSetString(tableNativePtr, columnInfo.fieldStringNotNullIndex, rowIndex, realmGet$fieldStringNotNull, false);
}
String realmGet$fieldStringNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldStringNull();
if (realmGet$fieldStringNull != null) {
Table.nativeSetString(tableNativePtr, columnInfo.fieldStringNullIndex, rowIndex, realmGet$fieldStringNull, false);
}
Boolean realmGet$fieldBooleanNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBooleanNotNull();
if (realmGet$fieldBooleanNotNull != null) {
Table.nativeSetBoolean(tableNativePtr, columnInfo.fieldBooleanNotNullIndex, rowIndex, realmGet$fieldBooleanNotNull, false);
}
Boolean realmGet$fieldBooleanNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBooleanNull();
if (realmGet$fieldBooleanNull != null) {
Table.nativeSetBoolean(tableNativePtr, columnInfo.fieldBooleanNullIndex, rowIndex, realmGet$fieldBooleanNull, false);
}
byte[] realmGet$fieldBytesNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBytesNotNull();
if (realmGet$fieldBytesNotNull != null) {
Table.nativeSetByteArray(tableNativePtr, columnInfo.fieldBytesNotNullIndex, rowIndex, realmGet$fieldBytesNotNull, false);
}
byte[] realmGet$fieldBytesNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBytesNull();
if (realmGet$fieldBytesNull != null) {
Table.nativeSetByteArray(tableNativePtr, columnInfo.fieldBytesNullIndex, rowIndex, realmGet$fieldBytesNull, false);
}
Number realmGet$fieldByteNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldByteNotNull();
if (realmGet$fieldByteNotNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldByteNotNullIndex, rowIndex, realmGet$fieldByteNotNull.longValue(), false);
}
Number realmGet$fieldByteNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldByteNull();
if (realmGet$fieldByteNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldByteNullIndex, rowIndex, realmGet$fieldByteNull.longValue(), false);
}
Number realmGet$fieldShortNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldShortNotNull();
if (realmGet$fieldShortNotNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldShortNotNullIndex, rowIndex, realmGet$fieldShortNotNull.longValue(), false);
}
Number realmGet$fieldShortNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldShortNull();
if (realmGet$fieldShortNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldShortNullIndex, rowIndex, realmGet$fieldShortNull.longValue(), false);
}
Number realmGet$fieldIntegerNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldIntegerNotNull();
if (realmGet$fieldIntegerNotNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldIntegerNotNullIndex, rowIndex, realmGet$fieldIntegerNotNull.longValue(), false);
}
Number realmGet$fieldIntegerNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldIntegerNull();
if (realmGet$fieldIntegerNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldIntegerNullIndex, rowIndex, realmGet$fieldIntegerNull.longValue(), false);
}
Number realmGet$fieldLongNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldLongNotNull();
if (realmGet$fieldLongNotNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldLongNotNullIndex, rowIndex, realmGet$fieldLongNotNull.longValue(), false);
}
Number realmGet$fieldLongNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldLongNull();
if (realmGet$fieldLongNull != null) {
Table.nativeSetLong(tableNativePtr, columnInfo.fieldLongNullIndex, rowIndex, realmGet$fieldLongNull.longValue(), false);
}
Float realmGet$fieldFloatNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldFloatNotNull();
if (realmGet$fieldFloatNotNull != null) {
Table.nativeSetFloat(tableNativePtr, columnInfo.fieldFloatNotNullIndex, rowIndex, realmGet$fieldFloatNotNull, false);
}
Float realmGet$fieldFloatNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldFloatNull();
if (realmGet$fieldFloatNull != null) {
Table.nativeSetFloat(tableNativePtr, columnInfo.fieldFloatNullIndex, rowIndex, realmGet$fieldFloatNull, false);
}
Double realmGet$fieldDoubleNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDoubleNotNull();
if (realmGet$fieldDoubleNotNull != null) {
Table.nativeSetDouble(tableNativePtr, columnInfo.fieldDoubleNotNullIndex, rowIndex, realmGet$fieldDoubleNotNull, false);
}
Double realmGet$fieldDoubleNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDoubleNull();
if (realmGet$fieldDoubleNull != null) {
Table.nativeSetDouble(tableNativePtr, columnInfo.fieldDoubleNullIndex, rowIndex, realmGet$fieldDoubleNull, false);
}
java.util.Date realmGet$fieldDateNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDateNotNull();
if (realmGet$fieldDateNotNull != null) {
Table.nativeSetTimestamp(tableNativePtr, columnInfo.fieldDateNotNullIndex, rowIndex, realmGet$fieldDateNotNull.getTime(), false);
}
java.util.Date realmGet$fieldDateNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDateNull();
if (realmGet$fieldDateNull != null) {
Table.nativeSetTimestamp(tableNativePtr, columnInfo.fieldDateNullIndex, rowIndex, realmGet$fieldDateNull.getTime(), false);
}
some.test.NullTypes fieldObjectNullObj = ((NullTypesRealmProxyInterface) object).realmGet$fieldObjectNull();
if (fieldObjectNullObj != null) {
Long cachefieldObjectNull = cache.get(fieldObjectNullObj);
if (cachefieldObjectNull == null) {
cachefieldObjectNull = NullTypesRealmProxy.insert(realm, fieldObjectNullObj, cache);
}
table.setLink(columnInfo.fieldObjectNullIndex, rowIndex, cachefieldObjectNull, false);
}
}
}
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmTests method schemaIndexCacheIsUpdatedAfterSchemaChange.
@Test
public void schemaIndexCacheIsUpdatedAfterSchemaChange() {
final CatRealmProxy.CatColumnInfo catColumnInfo;
catColumnInfo = (CatRealmProxy.CatColumnInfo) realm.schema.columnIndices.getColumnInfo(Cat.class);
final long nameIndex = catColumnInfo.nameIndex;
final AtomicLong nameIndexNew = new AtomicLong(-1L);
// Changes column index of "name".
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
final Table catTable = realm.getSchema().getTable(Cat.CLASS_NAME);
final long nameIndex = catTable.getColumnIndex(Cat.FIELD_NAME);
catTable.removeColumn(nameIndex);
final long newIndex = catTable.addColumn(RealmFieldType.STRING, Cat.FIELD_NAME, true);
realm.setVersion(realm.getConfiguration().getSchemaVersion() + 1);
nameIndexNew.set(newIndex);
}
});
// We need to update index cache if the schema version was changed in the same thread.
realm.sharedRealm.invokeSchemaChangeListenerIfSchemaChanged();
// Checks if the index was changed.
assertNotEquals(nameIndex, nameIndexNew);
// Checks if index in the ColumnInfo is updated.
assertEquals(nameIndexNew.get(), catColumnInfo.nameIndex);
assertEquals(nameIndexNew.get(), (long) catColumnInfo.getIndicesMap().get(Cat.FIELD_NAME));
// Checks by actual get and set.
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
final Cat cat = realm.createObject(Cat.class);
cat.setName("pochi");
}
});
//noinspection ConstantConditions
assertEquals("pochi", realm.where(Cat.class).findFirst().getName());
}
Aggregations