Search in sources :

Example 16 with RealmObjectProxy

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

the class NullTypesRealmProxy method insert.

public static long insert(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);
    }
    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.nativeSetLink(tableNativePtr, columnInfo.fieldObjectNullIndex, rowIndex, cachefieldObjectNull, false);
    }
    return rowIndex;
}
Also used : Table(io.realm.internal.Table) Date(java.util.Date) RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Example 17 with RealmObjectProxy

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

the class NullTypesRealmProxy method copy.

public static some.test.NullTypes copy(Realm realm, some.test.NullTypes newObject, boolean update, Map<RealmModel, RealmObjectProxy> cache) {
    RealmObjectProxy cachedRealmObject = cache.get(newObject);
    if (cachedRealmObject != null) {
        return (some.test.NullTypes) cachedRealmObject;
    } else {
        // rejecting default values to avoid creating unexpected objects from RealmModel/RealmList fields.
        some.test.NullTypes realmObject = realm.createObjectInternal(some.test.NullTypes.class, false, Collections.<String>emptyList());
        cache.put(newObject, (RealmObjectProxy) realmObject);
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldStringNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldStringNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldStringNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldStringNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldBooleanNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldBooleanNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldBooleanNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldBooleanNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldBytesNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldBytesNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldBytesNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldBytesNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldByteNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldByteNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldByteNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldByteNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldShortNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldShortNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldShortNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldShortNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldIntegerNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldIntegerNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldIntegerNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldIntegerNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldLongNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldLongNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldLongNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldLongNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldFloatNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldFloatNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldFloatNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldFloatNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldDoubleNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldDoubleNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldDoubleNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldDoubleNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldDateNotNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldDateNotNull());
        ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldDateNull(((NullTypesRealmProxyInterface) newObject).realmGet$fieldDateNull());
        some.test.NullTypes fieldObjectNullObj = ((NullTypesRealmProxyInterface) newObject).realmGet$fieldObjectNull();
        if (fieldObjectNullObj != null) {
            some.test.NullTypes cachefieldObjectNull = (some.test.NullTypes) cache.get(fieldObjectNullObj);
            if (cachefieldObjectNull != null) {
                ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldObjectNull(cachefieldObjectNull);
            } else {
                ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldObjectNull(NullTypesRealmProxy.copyOrUpdate(realm, fieldObjectNullObj, update, cache));
            }
        } else {
            ((NullTypesRealmProxyInterface) realmObject).realmSet$fieldObjectNull(null);
        }
        return realmObject;
    }
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy)

Example 18 with RealmObjectProxy

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

the class SimpleRealmProxy method insert.

public static long insert(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);
    }
    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 19 with RealmObjectProxy

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

the class SimpleRealmProxy method insertOrUpdate.

public static void insertOrUpdate(Realm realm, Iterator<? extends RealmModel> objects, Map<RealmModel, Long> cache) {
    Table table = realm.getTable(some.test.Simple.class);
    long tableNativePtr = table.getNativeTablePointer();
    SimpleColumnInfo columnInfo = (SimpleColumnInfo) realm.schema.getColumnInfo(some.test.Simple.class);
    some.test.Simple object = null;
    while (objects.hasNext()) {
        object = (some.test.Simple) 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$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);
        }
    }
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy) Table(io.realm.internal.Table)

Example 20 with RealmObjectProxy

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

the class BaseRealm method get.

// Used by RealmList/RealmResults
// Invariant: if dynamicClassName != null -> clazz == DynamicRealmObject
// TODO: Remove this after RealmList is backed by OS Results.
<E extends RealmModel> E get(Class<E> clazz, String dynamicClassName, long rowIndex) {
    final boolean isDynamicRealmObject = dynamicClassName != null;
    final Table table = isDynamicRealmObject ? schema.getTable(dynamicClassName) : schema.getTable(clazz);
    E result;
    if (isDynamicRealmObject) {
        @SuppressWarnings("unchecked") E dynamicObj = (E) new DynamicRealmObject(this, (rowIndex != Table.NO_MATCH) ? table.getCheckedRow(rowIndex) : InvalidRow.INSTANCE);
        result = dynamicObj;
    } else {
        result = configuration.getSchemaMediator().newInstance(clazz, this, (rowIndex != Table.NO_MATCH) ? table.getUncheckedRow(rowIndex) : InvalidRow.INSTANCE, schema.getColumnInfo(clazz), false, Collections.<String>emptyList());
    }
    RealmObjectProxy proxy = (RealmObjectProxy) result;
    if (rowIndex != Table.NO_MATCH) {
        proxy.realmGet$proxyState().setTableVersion$realm();
    }
    return result;
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy) Table(io.realm.internal.Table)

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