Search in sources :

Example 21 with Table

use of io.realm.internal.Table in project realm-java by realm.

the class BooleansRealmProxy method validateTable.

public static BooleansColumnInfo validateTable(SharedRealm sharedRealm, boolean allowExtraColumns) {
    if (!sharedRealm.hasTable("class_Booleans")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "The 'Booleans' class is missing from the schema for this Realm.");
    }
    Table table = sharedRealm.getTable("class_Booleans");
    final long columnCount = table.getColumnCount();
    if (columnCount != 4) {
        if (columnCount < 4) {
            throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field count is less than expected - expected 4 but was " + columnCount);
        }
        if (allowExtraColumns) {
            RealmLog.debug("Field count is more than expected - expected 4 but was %1$d", columnCount);
        } else {
            throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field count is more than expected - expected 4 but was " + columnCount);
        }
    }
    Map<String, RealmFieldType> columnTypes = new HashMap<String, RealmFieldType>();
    for (long i = 0; i < columnCount; i++) {
        columnTypes.put(table.getColumnName(i), table.getColumnType(i));
    }
    final BooleansColumnInfo columnInfo = new BooleansColumnInfo(sharedRealm.getPath(), table);
    if (table.hasPrimaryKey()) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Primary Key defined for field " + table.getColumnName(table.getPrimaryKey()) + " was removed.");
    }
    if (!columnTypes.containsKey("done")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'done' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("done") != RealmFieldType.BOOLEAN) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'boolean' for field 'done' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.doneIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'done' does support null values in the existing Realm file. Use corresponding boxed type for field 'done' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("isReady")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'isReady' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("isReady") != RealmFieldType.BOOLEAN) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'boolean' for field 'isReady' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.isReadyIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'isReady' does support null values in the existing Realm file. Use corresponding boxed type for field 'isReady' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("mCompleted")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'mCompleted' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("mCompleted") != RealmFieldType.BOOLEAN) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'boolean' for field 'mCompleted' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.mCompletedIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'mCompleted' does support null values in the existing Realm file. Use corresponding boxed type for field 'mCompleted' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("anotherBoolean")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'anotherBoolean' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("anotherBoolean") != RealmFieldType.BOOLEAN) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'boolean' for field 'anotherBoolean' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.anotherBooleanIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'anotherBoolean' does support null values in the existing Realm file. Use corresponding boxed type for field 'anotherBoolean' or migrate using RealmObjectSchema.setNullable().");
    }
    return columnInfo;
}
Also used : Table(io.realm.internal.Table) HashMap(java.util.HashMap) RealmMigrationNeededException(io.realm.exceptions.RealmMigrationNeededException)

Example 22 with Table

use of io.realm.internal.Table in project realm-java by realm.

the class NullTypesRealmProxy method initTable.

public static Table initTable(SharedRealm sharedRealm) {
    if (!sharedRealm.hasTable("class_NullTypes")) {
        Table table = sharedRealm.getTable("class_NullTypes");
        table.addColumn(RealmFieldType.STRING, "fieldStringNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.STRING, "fieldStringNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.BOOLEAN, "fieldBooleanNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.BOOLEAN, "fieldBooleanNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.BINARY, "fieldBytesNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.BINARY, "fieldBytesNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldByteNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldByteNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldShortNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldShortNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldIntegerNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldIntegerNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldLongNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.INTEGER, "fieldLongNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.FLOAT, "fieldFloatNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.FLOAT, "fieldFloatNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.DOUBLE, "fieldDoubleNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.DOUBLE, "fieldDoubleNull", Table.NULLABLE);
        table.addColumn(RealmFieldType.DATE, "fieldDateNotNull", Table.NOT_NULLABLE);
        table.addColumn(RealmFieldType.DATE, "fieldDateNull", Table.NULLABLE);
        if (!sharedRealm.hasTable("class_NullTypes")) {
            NullTypesRealmProxy.initTable(sharedRealm);
        }
        table.addColumnLink(RealmFieldType.OBJECT, "fieldObjectNull", sharedRealm.getTable("class_NullTypes"));
        table.setPrimaryKey("");
        return table;
    }
    return sharedRealm.getTable("class_NullTypes");
}
Also used : Table(io.realm.internal.Table)

Example 23 with Table

use of io.realm.internal.Table in project realm-java by realm.

the class AllTypesRealmProxy method insertOrUpdate.

public static long insertOrUpdate(Realm realm, some.test.AllTypes 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.AllTypes.class);
    long tableNativePtr = table.getNativeTablePointer();
    AllTypesColumnInfo columnInfo = (AllTypesColumnInfo) realm.schema.getColumnInfo(some.test.AllTypes.class);
    long pkColumnIndex = table.getPrimaryKey();
    String primaryKeyValue = ((AllTypesRealmProxyInterface) object).realmGet$columnString();
    long rowIndex = Table.NO_MATCH;
    if (primaryKeyValue == null) {
        rowIndex = Table.nativeFindFirstNull(tableNativePtr, pkColumnIndex);
    } else {
        rowIndex = Table.nativeFindFirstString(tableNativePtr, pkColumnIndex, primaryKeyValue);
    }
    if (rowIndex == Table.NO_MATCH) {
        rowIndex = table.addEmptyRowWithPrimaryKey(primaryKeyValue, false);
    }
    cache.put(object, rowIndex);
    Table.nativeSetLong(tableNativePtr, columnInfo.columnLongIndex, rowIndex, ((AllTypesRealmProxyInterface) object).realmGet$columnLong(), false);
    Table.nativeSetFloat(tableNativePtr, columnInfo.columnFloatIndex, rowIndex, ((AllTypesRealmProxyInterface) object).realmGet$columnFloat(), false);
    Table.nativeSetDouble(tableNativePtr, columnInfo.columnDoubleIndex, rowIndex, ((AllTypesRealmProxyInterface) object).realmGet$columnDouble(), false);
    Table.nativeSetBoolean(tableNativePtr, columnInfo.columnBooleanIndex, rowIndex, ((AllTypesRealmProxyInterface) object).realmGet$columnBoolean(), false);
    java.util.Date realmGet$columnDate = ((AllTypesRealmProxyInterface) object).realmGet$columnDate();
    if (realmGet$columnDate != null) {
        Table.nativeSetTimestamp(tableNativePtr, columnInfo.columnDateIndex, rowIndex, realmGet$columnDate.getTime(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.columnDateIndex, rowIndex, false);
    }
    byte[] realmGet$columnBinary = ((AllTypesRealmProxyInterface) object).realmGet$columnBinary();
    if (realmGet$columnBinary != null) {
        Table.nativeSetByteArray(tableNativePtr, columnInfo.columnBinaryIndex, rowIndex, realmGet$columnBinary, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.columnBinaryIndex, rowIndex, false);
    }
    some.test.AllTypes columnObjectObj = ((AllTypesRealmProxyInterface) object).realmGet$columnObject();
    if (columnObjectObj != null) {
        Long cachecolumnObject = cache.get(columnObjectObj);
        if (cachecolumnObject == null) {
            cachecolumnObject = AllTypesRealmProxy.insertOrUpdate(realm, columnObjectObj, cache);
        }
        Table.nativeSetLink(tableNativePtr, columnInfo.columnObjectIndex, rowIndex, cachecolumnObject, false);
    } else {
        Table.nativeNullifyLink(tableNativePtr, columnInfo.columnObjectIndex, rowIndex);
    }
    long columnRealmListNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.columnRealmListIndex, rowIndex);
    LinkView.nativeClear(columnRealmListNativeLinkViewPtr);
    RealmList<some.test.AllTypes> columnRealmListList = ((AllTypesRealmProxyInterface) object).realmGet$columnRealmList();
    if (columnRealmListList != null) {
        for (some.test.AllTypes columnRealmListItem : columnRealmListList) {
            Long cacheItemIndexcolumnRealmList = cache.get(columnRealmListItem);
            if (cacheItemIndexcolumnRealmList == null) {
                cacheItemIndexcolumnRealmList = AllTypesRealmProxy.insertOrUpdate(realm, columnRealmListItem, cache);
            }
            LinkView.nativeAdd(columnRealmListNativeLinkViewPtr, cacheItemIndexcolumnRealmList);
        }
    }
    return rowIndex;
}
Also used : Table(io.realm.internal.Table) Date(java.util.Date) RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Example 24 with Table

use of io.realm.internal.Table in project realm-java by realm.

the class AllTypesRealmProxy method copyOrUpdate.

public static some.test.AllTypes copyOrUpdate(Realm realm, some.test.AllTypes object, boolean update, Map<RealmModel, RealmObjectProxy> cache) {
    if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().threadId != realm.threadId) {
        throw new IllegalArgumentException("Objects which belong to Realm instances in other threads cannot be copied into this Realm instance.");
    }
    if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().getPath().equals(realm.getPath())) {
        return object;
    }
    final BaseRealm.RealmObjectContext objectContext = BaseRealm.objectContext.get();
    RealmObjectProxy cachedRealmObject = cache.get(object);
    if (cachedRealmObject != null) {
        return (some.test.AllTypes) cachedRealmObject;
    } else {
        some.test.AllTypes realmObject = null;
        boolean canUpdate = update;
        if (canUpdate) {
            Table table = realm.getTable(some.test.AllTypes.class);
            long pkColumnIndex = table.getPrimaryKey();
            String value = ((AllTypesRealmProxyInterface) object).realmGet$columnString();
            long rowIndex = Table.NO_MATCH;
            if (value == null) {
                rowIndex = table.findFirstNull(pkColumnIndex);
            } else {
                rowIndex = table.findFirstString(pkColumnIndex, value);
            }
            if (rowIndex != Table.NO_MATCH) {
                try {
                    objectContext.set(realm, table.getUncheckedRow(rowIndex), realm.schema.getColumnInfo(some.test.AllTypes.class), false, Collections.<String>emptyList());
                    realmObject = new io.realm.AllTypesRealmProxy();
                    cache.put(object, (RealmObjectProxy) realmObject);
                } finally {
                    objectContext.clear();
                }
            } else {
                canUpdate = false;
            }
        }
        if (canUpdate) {
            return update(realm, realmObject, object, cache);
        } else {
            return copy(realm, object, update, cache);
        }
    }
}
Also used : Table(io.realm.internal.Table) RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Example 25 with Table

use of io.realm.internal.Table in project realm-java by realm.

the class AllTypesRealmProxy method validateTable.

public static AllTypesColumnInfo validateTable(SharedRealm sharedRealm, boolean allowExtraColumns) {
    if (!sharedRealm.hasTable("class_AllTypes")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "The 'AllTypes' class is missing from the schema for this Realm.");
    }
    Table table = sharedRealm.getTable("class_AllTypes");
    final long columnCount = table.getColumnCount();
    if (columnCount != 9) {
        if (columnCount < 9) {
            throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field count is less than expected - expected 9 but was " + columnCount);
        }
        if (allowExtraColumns) {
            RealmLog.debug("Field count is more than expected - expected 9 but was %1$d", columnCount);
        } else {
            throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field count is more than expected - expected 9 but was " + columnCount);
        }
    }
    Map<String, RealmFieldType> columnTypes = new HashMap<String, RealmFieldType>();
    for (long i = 0; i < columnCount; i++) {
        columnTypes.put(table.getColumnName(i), table.getColumnType(i));
    }
    final AllTypesColumnInfo columnInfo = new AllTypesColumnInfo(sharedRealm.getPath(), table);
    if (!table.hasPrimaryKey()) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Primary key not defined for field 'columnString' in existing Realm file. @PrimaryKey was added.");
    } else {
        if (table.getPrimaryKey() != columnInfo.columnStringIndex) {
            throw new RealmMigrationNeededException(sharedRealm.getPath(), "Primary Key annotation definition was changed, from field " + table.getColumnName(table.getPrimaryKey()) + " to field columnString");
        }
    }
    if (!columnTypes.containsKey("columnString")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnString' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnString") != RealmFieldType.STRING) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'String' for field 'columnString' in existing Realm file.");
    }
    if (!table.isColumnNullable(columnInfo.columnStringIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "@PrimaryKey field 'columnString' does not support null values in the existing Realm file. Migrate using RealmObjectSchema.setNullable(), or mark the field as @Required.");
    }
    if (!table.hasSearchIndex(table.getColumnIndex("columnString"))) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Index not defined for field 'columnString' in existing Realm file. Either set @Index or migrate using io.realm.internal.Table.removeSearchIndex().");
    }
    if (!columnTypes.containsKey("columnLong")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnLong' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnLong") != RealmFieldType.INTEGER) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'long' for field 'columnLong' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.columnLongIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'columnLong' does support null values in the existing Realm file. Use corresponding boxed type for field 'columnLong' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("columnFloat")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnFloat' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnFloat") != RealmFieldType.FLOAT) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'float' for field 'columnFloat' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.columnFloatIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'columnFloat' does support null values in the existing Realm file. Use corresponding boxed type for field 'columnFloat' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("columnDouble")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnDouble' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnDouble") != RealmFieldType.DOUBLE) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'double' for field 'columnDouble' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.columnDoubleIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'columnDouble' does support null values in the existing Realm file. Use corresponding boxed type for field 'columnDouble' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("columnBoolean")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnBoolean' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnBoolean") != RealmFieldType.BOOLEAN) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'boolean' for field 'columnBoolean' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.columnBooleanIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'columnBoolean' does support null values in the existing Realm file. Use corresponding boxed type for field 'columnBoolean' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("columnDate")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnDate' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnDate") != RealmFieldType.DATE) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'Date' for field 'columnDate' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.columnDateIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'columnDate' does support null values in the existing Realm file. Remove @Required or @PrimaryKey from field 'columnDate' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("columnBinary")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnBinary' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnBinary") != RealmFieldType.BINARY) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'byte[]' for field 'columnBinary' in existing Realm file.");
    }
    if (table.isColumnNullable(columnInfo.columnBinaryIndex)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Field 'columnBinary' does support null values in the existing Realm file. Remove @Required or @PrimaryKey from field 'columnBinary' or migrate using RealmObjectSchema.setNullable().");
    }
    if (!columnTypes.containsKey("columnObject")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnObject' in existing Realm file. Either remove field or migrate using io.realm.internal.Table.addColumn().");
    }
    if (columnTypes.get("columnObject") != RealmFieldType.OBJECT) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'AllTypes' for field 'columnObject'");
    }
    if (!sharedRealm.hasTable("class_AllTypes")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing class 'class_AllTypes' for field 'columnObject'");
    }
    Table table_7 = sharedRealm.getTable("class_AllTypes");
    if (!table.getLinkTarget(columnInfo.columnObjectIndex).hasSameSchema(table_7)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid RealmObject for field 'columnObject': '" + table.getLinkTarget(columnInfo.columnObjectIndex).getName() + "' expected - was '" + table_7.getName() + "'");
    }
    if (!columnTypes.containsKey("columnRealmList")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing field 'columnRealmList'");
    }
    if (columnTypes.get("columnRealmList") != RealmFieldType.LIST) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid type 'AllTypes' for field 'columnRealmList'");
    }
    if (!sharedRealm.hasTable("class_AllTypes")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Missing class 'class_AllTypes' for field 'columnRealmList'");
    }
    Table table_8 = sharedRealm.getTable("class_AllTypes");
    if (!table.getLinkTarget(columnInfo.columnRealmListIndex).hasSameSchema(table_8)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Invalid RealmList type for field 'columnRealmList': '" + table.getLinkTarget(columnInfo.columnRealmListIndex).getName() + "' expected - was '" + table_8.getName() + "'");
    }
    long backlinkFieldIndex;
    Table backlinkSourceTable;
    Table backlinkTargetTable;
    RealmFieldType backlinkFieldType;
    if (!sharedRealm.hasTable("class_AllTypes")) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Cannot find source class 'some.test.AllTypes' for @LinkingObjects field 'some.test.AllTypes.parentObjects'");
    }
    backlinkSourceTable = sharedRealm.getTable("class_AllTypes");
    backlinkFieldIndex = backlinkSourceTable.getColumnIndex("columnObject");
    if (backlinkFieldIndex == Table.NO_MATCH) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Cannot find source field 'some.test.AllTypes.columnObject' for @LinkingObjects field 'some.test.AllTypes.parentObjects'");
    }
    backlinkFieldType = backlinkSourceTable.getColumnType(backlinkFieldIndex);
    if ((backlinkFieldType != RealmFieldType.OBJECT) && (backlinkFieldType != RealmFieldType.LIST)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Source field 'some.test.AllTypes.columnObject' for @LinkingObjects field 'some.test.AllTypes.parentObjects' is not a RealmObject type");
    }
    backlinkTargetTable = backlinkSourceTable.getLinkTarget(backlinkFieldIndex);
    if (!table.hasSameSchema(backlinkTargetTable)) {
        throw new RealmMigrationNeededException(sharedRealm.getPath(), "Source field 'some.test.AllTypes.columnObject' for @LinkingObjects field 'some.test.AllTypes.parentObjects' has wrong type '" + backlinkTargetTable.getName() + "'");
    }
    return columnInfo;
}
Also used : Table(io.realm.internal.Table) HashMap(java.util.HashMap) RealmMigrationNeededException(io.realm.exceptions.RealmMigrationNeededException)

Aggregations

Table (io.realm.internal.Table)68 RealmObjectProxy (io.realm.internal.RealmObjectProxy)20 Test (org.junit.Test)19 Date (java.util.Date)10 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)5 RealmMigrationNeededException (io.realm.exceptions.RealmMigrationNeededException)4 HashMap (java.util.HashMap)4 PrimaryKeyAsLong (io.realm.entities.PrimaryKeyAsLong)3 RealmException (io.realm.exceptions.RealmException)3 UncheckedRow (io.realm.internal.UncheckedRow)2 JSONObject (org.json.JSONObject)2 TargetApi (android.annotation.TargetApi)1 JsonReader (android.util.JsonReader)1 AllTypes (io.realm.entities.AllTypes)1 Cat (io.realm.entities.Cat)1 IOSAllTypes (io.realm.entities.IOSAllTypes)1 StringOnly (io.realm.entities.StringOnly)1 MigrationFieldTypeToInt (io.realm.entities.migration.MigrationFieldTypeToInt)1 MigrationFieldTypeToInteger (io.realm.entities.migration.MigrationFieldTypeToInteger)1 LinkView (io.realm.internal.LinkView)1