Search in sources :

Example 36 with RealmObjectProxy

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

the class BaseRealm method get.

// Used by RealmList/RealmResults, to create RealmObject from a Collection.
// Invariant: if dynamicClassName != null -> clazz == DynamicRealmObject
<E extends RealmModel> E get(Class<E> clazz, String dynamicClassName, UncheckedRow row) {
    final boolean isDynamicRealmObject = dynamicClassName != null;
    E result;
    if (isDynamicRealmObject) {
        //noinspection unchecked
        result = (E) new DynamicRealmObject(this, CheckedRow.getFromRow(row));
    } else {
        result = configuration.getSchemaMediator().newInstance(clazz, this, row, schema.getColumnInfo(clazz), false, Collections.<String>emptyList());
    }
    RealmObjectProxy proxy = (RealmObjectProxy) result;
    proxy.realmGet$proxyState().setTableVersion$realm();
    return result;
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Example 37 with RealmObjectProxy

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

the class NullTypesRealmProxy method insertOrUpdate.

public static long insertOrUpdate(Realm realm, some.test.NullTypes 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.NullTypes.class);
    long tableNativePtr = table.getNativeTablePointer();
    NullTypesColumnInfo columnInfo = (NullTypesColumnInfo) realm.schema.getColumnInfo(some.test.NullTypes.class);
    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);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldStringNotNullIndex, rowIndex, false);
    }
    String realmGet$fieldStringNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldStringNull();
    if (realmGet$fieldStringNull != null) {
        Table.nativeSetString(tableNativePtr, columnInfo.fieldStringNullIndex, rowIndex, realmGet$fieldStringNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldStringNullIndex, rowIndex, false);
    }
    Boolean realmGet$fieldBooleanNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBooleanNotNull();
    if (realmGet$fieldBooleanNotNull != null) {
        Table.nativeSetBoolean(tableNativePtr, columnInfo.fieldBooleanNotNullIndex, rowIndex, realmGet$fieldBooleanNotNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldBooleanNotNullIndex, rowIndex, false);
    }
    Boolean realmGet$fieldBooleanNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBooleanNull();
    if (realmGet$fieldBooleanNull != null) {
        Table.nativeSetBoolean(tableNativePtr, columnInfo.fieldBooleanNullIndex, rowIndex, realmGet$fieldBooleanNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldBooleanNullIndex, rowIndex, false);
    }
    byte[] realmGet$fieldBytesNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBytesNotNull();
    if (realmGet$fieldBytesNotNull != null) {
        Table.nativeSetByteArray(tableNativePtr, columnInfo.fieldBytesNotNullIndex, rowIndex, realmGet$fieldBytesNotNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldBytesNotNullIndex, rowIndex, false);
    }
    byte[] realmGet$fieldBytesNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldBytesNull();
    if (realmGet$fieldBytesNull != null) {
        Table.nativeSetByteArray(tableNativePtr, columnInfo.fieldBytesNullIndex, rowIndex, realmGet$fieldBytesNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldBytesNullIndex, rowIndex, false);
    }
    Number realmGet$fieldByteNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldByteNotNull();
    if (realmGet$fieldByteNotNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldByteNotNullIndex, rowIndex, realmGet$fieldByteNotNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldByteNotNullIndex, rowIndex, false);
    }
    Number realmGet$fieldByteNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldByteNull();
    if (realmGet$fieldByteNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldByteNullIndex, rowIndex, realmGet$fieldByteNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldByteNullIndex, rowIndex, false);
    }
    Number realmGet$fieldShortNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldShortNotNull();
    if (realmGet$fieldShortNotNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldShortNotNullIndex, rowIndex, realmGet$fieldShortNotNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldShortNotNullIndex, rowIndex, false);
    }
    Number realmGet$fieldShortNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldShortNull();
    if (realmGet$fieldShortNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldShortNullIndex, rowIndex, realmGet$fieldShortNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldShortNullIndex, rowIndex, false);
    }
    Number realmGet$fieldIntegerNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldIntegerNotNull();
    if (realmGet$fieldIntegerNotNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldIntegerNotNullIndex, rowIndex, realmGet$fieldIntegerNotNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldIntegerNotNullIndex, rowIndex, false);
    }
    Number realmGet$fieldIntegerNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldIntegerNull();
    if (realmGet$fieldIntegerNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldIntegerNullIndex, rowIndex, realmGet$fieldIntegerNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldIntegerNullIndex, rowIndex, false);
    }
    Number realmGet$fieldLongNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldLongNotNull();
    if (realmGet$fieldLongNotNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldLongNotNullIndex, rowIndex, realmGet$fieldLongNotNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldLongNotNullIndex, rowIndex, false);
    }
    Number realmGet$fieldLongNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldLongNull();
    if (realmGet$fieldLongNull != null) {
        Table.nativeSetLong(tableNativePtr, columnInfo.fieldLongNullIndex, rowIndex, realmGet$fieldLongNull.longValue(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldLongNullIndex, rowIndex, false);
    }
    Float realmGet$fieldFloatNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldFloatNotNull();
    if (realmGet$fieldFloatNotNull != null) {
        Table.nativeSetFloat(tableNativePtr, columnInfo.fieldFloatNotNullIndex, rowIndex, realmGet$fieldFloatNotNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldFloatNotNullIndex, rowIndex, false);
    }
    Float realmGet$fieldFloatNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldFloatNull();
    if (realmGet$fieldFloatNull != null) {
        Table.nativeSetFloat(tableNativePtr, columnInfo.fieldFloatNullIndex, rowIndex, realmGet$fieldFloatNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldFloatNullIndex, rowIndex, false);
    }
    Double realmGet$fieldDoubleNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDoubleNotNull();
    if (realmGet$fieldDoubleNotNull != null) {
        Table.nativeSetDouble(tableNativePtr, columnInfo.fieldDoubleNotNullIndex, rowIndex, realmGet$fieldDoubleNotNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldDoubleNotNullIndex, rowIndex, false);
    }
    Double realmGet$fieldDoubleNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDoubleNull();
    if (realmGet$fieldDoubleNull != null) {
        Table.nativeSetDouble(tableNativePtr, columnInfo.fieldDoubleNullIndex, rowIndex, realmGet$fieldDoubleNull, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldDoubleNullIndex, rowIndex, false);
    }
    java.util.Date realmGet$fieldDateNotNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDateNotNull();
    if (realmGet$fieldDateNotNull != null) {
        Table.nativeSetTimestamp(tableNativePtr, columnInfo.fieldDateNotNullIndex, rowIndex, realmGet$fieldDateNotNull.getTime(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldDateNotNullIndex, rowIndex, false);
    }
    java.util.Date realmGet$fieldDateNull = ((NullTypesRealmProxyInterface) object).realmGet$fieldDateNull();
    if (realmGet$fieldDateNull != null) {
        Table.nativeSetTimestamp(tableNativePtr, columnInfo.fieldDateNullIndex, rowIndex, realmGet$fieldDateNull.getTime(), false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.fieldDateNullIndex, rowIndex, false);
    }
    some.test.NullTypes fieldObjectNullObj = ((NullTypesRealmProxyInterface) object).realmGet$fieldObjectNull();
    if (fieldObjectNullObj != null) {
        Long cachefieldObjectNull = cache.get(fieldObjectNullObj);
        if (cachefieldObjectNull == null) {
            cachefieldObjectNull = NullTypesRealmProxy.insertOrUpdate(realm, fieldObjectNullObj, cache);
        }
        Table.nativeSetLink(tableNativePtr, columnInfo.fieldObjectNullIndex, rowIndex, cachefieldObjectNull, false);
    } else {
        Table.nativeNullifyLink(tableNativePtr, columnInfo.fieldObjectNullIndex, rowIndex);
    }
    return rowIndex;
}
Also used : Table(io.realm.internal.Table) Date(java.util.Date) RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Example 38 with RealmObjectProxy

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

the class SimpleRealmProxy method insertOrUpdate.

public static long insertOrUpdate(Realm realm, some.test.Simple 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.Simple.class);
    long tableNativePtr = table.getNativeTablePointer();
    SimpleColumnInfo columnInfo = (SimpleColumnInfo) realm.schema.getColumnInfo(some.test.Simple.class);
    long rowIndex = Table.nativeAddEmptyRow(tableNativePtr, 1);
    cache.put(object, rowIndex);
    String realmGet$name = ((SimpleRealmProxyInterface) object).realmGet$name();
    if (realmGet$name != null) {
        Table.nativeSetString(tableNativePtr, columnInfo.nameIndex, rowIndex, realmGet$name, false);
    } else {
        Table.nativeSetNull(tableNativePtr, columnInfo.nameIndex, rowIndex, false);
    }
    Table.nativeSetLong(tableNativePtr, columnInfo.ageIndex, rowIndex, ((SimpleRealmProxyInterface) object).realmGet$age(), false);
    return rowIndex;
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy) Table(io.realm.internal.Table)

Example 39 with RealmObjectProxy

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

the class SimpleRealmProxy method copyOrUpdate.

public static some.test.Simple copyOrUpdate(Realm realm, some.test.Simple 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.Simple) cachedRealmObject;
    } else {
        return copy(realm, object, update, cache);
    }
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Example 40 with RealmObjectProxy

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

the class SimpleRealmProxy method copy.

public static some.test.Simple copy(Realm realm, some.test.Simple newObject, boolean update, Map<RealmModel, RealmObjectProxy> cache) {
    RealmObjectProxy cachedRealmObject = cache.get(newObject);
    if (cachedRealmObject != null) {
        return (some.test.Simple) cachedRealmObject;
    } else {
        // rejecting default values to avoid creating unexpected objects from RealmModel/RealmList fields.
        some.test.Simple realmObject = realm.createObjectInternal(some.test.Simple.class, false, Collections.<String>emptyList());
        cache.put(newObject, (RealmObjectProxy) realmObject);
        ((SimpleRealmProxyInterface) realmObject).realmSet$name(((SimpleRealmProxyInterface) newObject).realmGet$name());
        ((SimpleRealmProxyInterface) realmObject).realmSet$age(((SimpleRealmProxyInterface) newObject).realmGet$age());
        return realmObject;
    }
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Aggregations

RealmObjectProxy (io.realm.internal.RealmObjectProxy)43 Table (io.realm.internal.Table)20 Date (java.util.Date)8 Row (io.realm.internal.Row)6 InvalidRow (io.realm.internal.InvalidRow)2 LinkView (io.realm.internal.LinkView)2 UiThreadTest (android.support.test.annotation.UiThreadTest)1 AllTypes (io.realm.entities.AllTypes)1 Collection (io.realm.internal.Collection)1 PendingRow (io.realm.internal.PendingRow)1 SharedRealm (io.realm.internal.SharedRealm)1 UncheckedRow (io.realm.internal.UncheckedRow)1 Test (org.junit.Test)1 Observable (rx.Observable)1