use of io.realm.internal.Row in project realm-java by realm.
the class NullTypesRealmProxy method realmSet$fieldStringNull.
public void realmSet$fieldStringNull(String value) {
if (proxyState.isUnderConstruction()) {
if (!proxyState.getAcceptDefaultValue$realm()) {
return;
}
final Row row = proxyState.getRow$realm();
if (value == null) {
row.getTable().setNull(columnInfo.fieldStringNullIndex, row.getIndex(), true);
return;
}
row.getTable().setString(columnInfo.fieldStringNullIndex, row.getIndex(), value, true);
return;
}
proxyState.getRealm$realm().checkIfValid();
if (value == null) {
proxyState.getRow$realm().setNull(columnInfo.fieldStringNullIndex);
return;
}
proxyState.getRow$realm().setString(columnInfo.fieldStringNullIndex, value);
}
use of io.realm.internal.Row in project realm-java by realm.
the class RealmObject method isValid.
/**
* Checks if the RealmObject is still valid to use i.e., the RealmObject hasn't been deleted nor has the
* {@link io.realm.Realm} been closed. It will always return {@code true} for unmanaged objects.
*
* @param object RealmObject to check validity for.
* @return {@code true} if the object is still accessible or an unmanaged object, {@code false} otherwise.
*/
public static <E extends RealmModel> boolean isValid(E object) {
if (object instanceof RealmObjectProxy) {
RealmObjectProxy proxy = (RealmObjectProxy) object;
Row row = proxy.realmGet$proxyState().getRow$realm();
return row != null && row.isAttached();
} else {
return true;
}
}
use of io.realm.internal.Row in project realm-java by realm.
the class RealmQuery method findFirstAsync.
/**
* Similar to {@link #findFirst()} but runs asynchronously on a worker thread
* This method is only available from a Looper thread.
*
* @return immediately an empty {@link RealmObject}. Trying to access any field on the returned object
* before it is loaded will throw an {@code IllegalStateException}. Use {@link RealmObject#isLoaded()} to check if
* the object is fully loaded or register a listener {@link io.realm.RealmObject#addChangeListener}
* to be notified when the query completes. If no RealmObject was found after the query completed, the returned
* RealmObject will have {@link RealmObject#isLoaded()} set to {@code true} and {@link RealmObject#isValid()} set to
* {@code false}.
*/
public E findFirstAsync() {
realm.checkIfValid();
realm.sharedRealm.capabilities.checkCanDeliverNotification(ASYNC_QUERY_WRONG_THREAD_MESSAGE);
Row row;
if (realm.isInTransaction()) {
// It is not possible to create async query inside a transaction. So immediately query the first object.
// See OS Results::prepare_async()
row = new Collection(realm.sharedRealm, query).firstUncheckedRow();
} else {
// prepares an empty reference of the RealmObject which is backed by a pending query,
// then update it once the query complete in the background.
// TODO: The performance by the pending query will be a little bit worse than directly calling core's
// Query.find(). The overhead comes with core needs to add all the row indices to the vector. However this
// can be optimized by adding support of limit in OS's Results which is supported by core already.
row = new PendingRow(realm.sharedRealm, query, null, isDynamicQuery());
}
final E result;
if (isDynamicQuery()) {
//noinspection unchecked
result = (E) new DynamicRealmObject(realm, row);
} else {
result = realm.getConfiguration().getSchemaMediator().newInstance(clazz, realm, row, realm.getSchema().getColumnInfo(clazz), false, Collections.<String>emptyList());
}
if (row instanceof PendingRow) {
final RealmObjectProxy proxy = (RealmObjectProxy) result;
((PendingRow) row).setFrontEnd(proxy.realmGet$proxyState());
}
return result;
}
use of io.realm.internal.Row in project realm-java by realm.
the class AllTypesRealmProxy method realmSet$columnLong.
public void realmSet$columnLong(long value) {
if (proxyState.isUnderConstruction()) {
if (!proxyState.getAcceptDefaultValue$realm()) {
return;
}
final Row row = proxyState.getRow$realm();
row.getTable().setLong(columnInfo.columnLongIndex, row.getIndex(), value, true);
return;
}
proxyState.getRealm$realm().checkIfValid();
proxyState.getRow$realm().setLong(columnInfo.columnLongIndex, value);
}
use of io.realm.internal.Row in project realm-java by realm.
the class AllTypesRealmProxy method realmSet$columnObject.
public void realmSet$columnObject(some.test.AllTypes value) {
if (proxyState.isUnderConstruction()) {
if (!proxyState.getAcceptDefaultValue$realm()) {
return;
}
if (proxyState.getExcludeFields$realm().contains("columnObject")) {
return;
}
if (value != null && !RealmObject.isManaged(value)) {
value = ((Realm) proxyState.getRealm$realm()).copyToRealm(value);
}
final Row row = proxyState.getRow$realm();
if (value == null) {
// Table#nullifyLink() does not support default value. Just using Row.
row.nullifyLink(columnInfo.columnObjectIndex);
return;
}
if (!RealmObject.isValid(value)) {
throw new IllegalArgumentException("'value' is not a valid managed object.");
}
if (((RealmObjectProxy) value).realmGet$proxyState().getRealm$realm() != proxyState.getRealm$realm()) {
throw new IllegalArgumentException("'value' belongs to a different Realm.");
}
row.getTable().setLink(columnInfo.columnObjectIndex, row.getIndex(), ((RealmObjectProxy) value).realmGet$proxyState().getRow$realm().getIndex(), true);
return;
}
proxyState.getRealm$realm().checkIfValid();
if (value == null) {
proxyState.getRow$realm().nullifyLink(columnInfo.columnObjectIndex);
return;
}
if (!(RealmObject.isManaged(value) && RealmObject.isValid(value))) {
throw new IllegalArgumentException("'value' is not a valid managed object.");
}
if (((RealmObjectProxy) value).realmGet$proxyState().getRealm$realm() != proxyState.getRealm$realm()) {
throw new IllegalArgumentException("'value' belongs to a different Realm.");
}
proxyState.getRow$realm().setLink(columnInfo.columnObjectIndex, ((RealmObjectProxy) value).realmGet$proxyState().getRow$realm().getIndex());
}
Aggregations