use of io.realm.internal.RealmObjectProxy in project realm-java by realm.
the class RealmList method add.
/**
* Adds the specified object at the end of this List.
* <ol>
* <li><b>Unmanaged RealmLists</b>: It is possible to add both managed and unmanaged objects. If adding managed
* objects to an unmanaged RealmList they will not be copied to the Realm again if using
* {@link Realm#copyToRealm(RealmModel)} afterwards.</li>
*
* <li><b>Managed RealmLists</b>: It is possible to add unmanaged objects to a RealmList that is already managed. In
* that case the object will transparently be copied to Realm using {@link Realm#copyToRealm(RealmModel)}
* or {@link Realm#copyToRealmOrUpdate(RealmModel)} if it has a primary key.</li>
* </ol>
*
* @param object the object to add.
* @return always {@code true}.
* @throws IllegalStateException if Realm instance has been closed or parent object has been removed.
*/
@Override
public boolean add(E object) {
checkValidObject(object);
if (isManaged()) {
checkValidView();
RealmObjectProxy proxy = (RealmObjectProxy) copyToRealmIfNeeded(object);
view.add(proxy.realmGet$proxyState().getRow$realm().getIndex());
} else {
unmanagedList.add(object);
}
modCount++;
return true;
}
use of io.realm.internal.RealmObjectProxy in project realm-java by realm.
the class RealmList method set.
/**
* Replaces the element at the specified location in this list with the specified object.
* <ol>
* <li><b>Unmanaged RealmLists</b>: It is possible to add both managed and unmanaged objects. If adding managed
* objects to an unmanaged RealmList they will not be copied to the Realm again if using
* {@link Realm#copyToRealm(RealmModel)} afterwards.</li>
*
* <li><b>Managed RealmLists</b>: It is possible to add unmanaged objects to a RealmList that is already managed.
* In that case the object will transparently be copied to Realm using {@link Realm#copyToRealm(RealmModel)} or
* {@link Realm#copyToRealmOrUpdate(RealmModel)} if it has a primary key.</li>
* </ol>
*
* @param location the index at which to put the specified object.
* @param object the object to add.
* @return the previous element at the index.
* @throws IllegalStateException if Realm instance has been closed or parent object has been removed.
* @throws IndexOutOfBoundsException if {@code location < 0 || location >= size()}.
*/
@Override
public E set(int location, E object) {
checkValidObject(object);
E oldObject;
if (isManaged()) {
checkValidView();
RealmObjectProxy proxy = (RealmObjectProxy) copyToRealmIfNeeded(object);
oldObject = get(location);
view.set(location, proxy.realmGet$proxyState().getRow$realm().getIndex());
return oldObject;
} else {
oldObject = unmanagedList.set(location, object);
}
return oldObject;
}
use of io.realm.internal.RealmObjectProxy in project realm-java by realm.
the class RealmObject method removeAllChangeListeners.
/**
* Removes all registered listeners from the given RealmObject.
*
* @param object RealmObject to remove all listeners from.
* @throws IllegalArgumentException if object is {@code null} or isn't managed by Realm.
*/
public static <E extends RealmModel> void removeAllChangeListeners(E object) {
if (object instanceof RealmObjectProxy) {
RealmObjectProxy proxy = (RealmObjectProxy) object;
BaseRealm realm = proxy.realmGet$proxyState().getRealm$realm();
realm.checkIfValid();
realm.sharedRealm.capabilities.checkCanDeliverNotification(BaseRealm.LISTENER_NOT_ALLOWED_MESSAGE);
proxy.realmGet$proxyState().removeAllChangeListeners();
} else {
throw new IllegalArgumentException("Cannot remove listeners from this unmanaged RealmObject (created outside of Realm)");
}
}
use of io.realm.internal.RealmObjectProxy 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.RealmObjectProxy in project realm-java by realm.
the class RealmObject method isLoaded.
/**
* Checks if the query used to find this RealmObject has completed.
*
* Async methods like {@link RealmQuery#findFirstAsync()} return an {@link RealmObject} that represents the future result
* of the {@link RealmQuery}. It can be considered similar to a {@link java.util.concurrent.Future} in this regard.
*
* Once {@code isLoaded()} returns {@code true}, the object represents the query result even if the query
* didn't find any object matching the query parameters. In this case the {@link RealmObject} will
* become a "null" object.
*
* "Null" objects represents {@code null}. An exception is throw if any accessor is called, so it is important to also
* check {@link #isValid()} before calling any methods. A common pattern is:
*
* <pre>
* {@code
* Person person = realm.where(Person.class).findFirstAsync();
* RealmObject.isLoaded(person); // == false
* RealmObject.addChangeListener(person, new RealmChangeListener() {
* \@Override
* public void onChange(Person person) {
* RealmObject.isLoaded(person); // always true here
* if (RealmObject.isValid(person)) {
* // It is safe to access the person.
* }
* }
* });
* }
* </pre>
*
* Synchronous RealmObjects are by definition blocking hence this method will always return {@code true} for them.
* This method will return {@code true} if called on an unmanaged object (created outside of Realm).
*
* @param object RealmObject to check.
* @return {@code true} if the query has completed, {@code false} if the query is in
* progress.
*
* @see #isValid(RealmModel)
*/
public static <E extends RealmModel> boolean isLoaded(E object) {
if (object instanceof RealmObjectProxy) {
RealmObjectProxy proxy = (RealmObjectProxy) object;
proxy.realmGet$proxyState().getRealm$realm().checkIfValid();
return proxy.realmGet$proxyState().isLoaded();
}
return true;
}
Aggregations