Search in sources :

Example 1 with Row

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

the class RealmObject method deleteFromRealm.

/**
     * Deletes the object from the Realm it is currently associated with.
     * <p>
     * After this method is called the object will be invalid and any operation (read or write) performed on it will
     * fail with an IllegalStateException.
     *
     * @throws IllegalStateException if the corresponding Realm is closed or in an incorrect thread.
     * @see #isValid()
     */
public static <E extends RealmModel> void deleteFromRealm(E object) {
    if (!(object instanceof RealmObjectProxy)) {
        // TODO What type of exception IllegalArgument/IllegalState?
        throw new IllegalArgumentException("Object not managed by Realm, so it cannot be removed.");
    }
    RealmObjectProxy proxy = (RealmObjectProxy) object;
    if (proxy.realmGet$proxyState().getRow$realm() == null) {
        throw new IllegalStateException("Object malformed: missing object in Realm. Make sure to instantiate RealmObjects with Realm.createObject()");
    }
    if (proxy.realmGet$proxyState().getRealm$realm() == null) {
        throw new IllegalStateException("Object malformed: missing Realm. Make sure to instantiate RealmObjects with Realm.createObject()");
    }
    proxy.realmGet$proxyState().getRealm$realm().checkIfValid();
    Row row = proxy.realmGet$proxyState().getRow$realm();
    row.getTable().moveLastOver(row.getIndex());
    proxy.realmGet$proxyState().setRow$realm(InvalidRow.INSTANCE);
}
Also used : RealmObjectProxy(io.realm.internal.RealmObjectProxy) Row(io.realm.internal.Row) InvalidRow(io.realm.internal.InvalidRow)

Example 2 with Row

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

the class AllTypesRealmProxy method realmSet$columnBoolean.

public void realmSet$columnBoolean(boolean value) {
    if (proxyState.isUnderConstruction()) {
        if (!proxyState.getAcceptDefaultValue$realm()) {
            return;
        }
        final Row row = proxyState.getRow$realm();
        row.getTable().setBoolean(columnInfo.columnBooleanIndex, row.getIndex(), value, true);
        return;
    }
    proxyState.getRealm$realm().checkIfValid();
    proxyState.getRow$realm().setBoolean(columnInfo.columnBooleanIndex, value);
}
Also used : Row(io.realm.internal.Row)

Example 3 with Row

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

the class AllTypesRealmProxy method realmSet$columnDate.

public void realmSet$columnDate(Date value) {
    if (proxyState.isUnderConstruction()) {
        if (!proxyState.getAcceptDefaultValue$realm()) {
            return;
        }
        final Row row = proxyState.getRow$realm();
        if (value == null) {
            throw new IllegalArgumentException("Trying to set non-nullable field 'columnDate' to null.");
        }
        row.getTable().setDate(columnInfo.columnDateIndex, row.getIndex(), value, true);
        return;
    }
    proxyState.getRealm$realm().checkIfValid();
    if (value == null) {
        throw new IllegalArgumentException("Trying to set non-nullable field 'columnDate' to null.");
    }
    proxyState.getRow$realm().setDate(columnInfo.columnDateIndex, value);
}
Also used : Row(io.realm.internal.Row)

Example 4 with Row

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

the class NullTypesRealmProxy method realmSet$fieldShortNull.

public void realmSet$fieldShortNull(Short value) {
    if (proxyState.isUnderConstruction()) {
        if (!proxyState.getAcceptDefaultValue$realm()) {
            return;
        }
        final Row row = proxyState.getRow$realm();
        if (value == null) {
            row.getTable().setNull(columnInfo.fieldShortNullIndex, row.getIndex(), true);
            return;
        }
        row.getTable().setLong(columnInfo.fieldShortNullIndex, row.getIndex(), value, true);
        return;
    }
    proxyState.getRealm$realm().checkIfValid();
    if (value == null) {
        proxyState.getRow$realm().setNull(columnInfo.fieldShortNullIndex);
        return;
    }
    proxyState.getRow$realm().setLong(columnInfo.fieldShortNullIndex, value);
}
Also used : Row(io.realm.internal.Row)

Example 5 with Row

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

the class NullTypesRealmProxy method realmSet$fieldByteNull.

public void realmSet$fieldByteNull(Byte value) {
    if (proxyState.isUnderConstruction()) {
        if (!proxyState.getAcceptDefaultValue$realm()) {
            return;
        }
        final Row row = proxyState.getRow$realm();
        if (value == null) {
            row.getTable().setNull(columnInfo.fieldByteNullIndex, row.getIndex(), true);
            return;
        }
        row.getTable().setLong(columnInfo.fieldByteNullIndex, row.getIndex(), value, true);
        return;
    }
    proxyState.getRealm$realm().checkIfValid();
    if (value == null) {
        proxyState.getRow$realm().setNull(columnInfo.fieldByteNullIndex);
        return;
    }
    proxyState.getRow$realm().setLong(columnInfo.fieldByteNullIndex, value);
}
Also used : Row(io.realm.internal.Row)

Aggregations

Row (io.realm.internal.Row)38 RealmObjectProxy (io.realm.internal.RealmObjectProxy)6 InvalidRow (io.realm.internal.InvalidRow)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 Test (org.junit.Test)1