Docs Menu

Class DynamicRealmObject

On this page

java.lang.Object
io.realm.DynamicRealmObject

Class that wraps a normal RealmObject in order to allow dynamic access instead of a typed interface. Using a DynamicRealmObject is slower than using the regular RealmObject class.

Constructor and Description

Creates a dynamic Realm object based on an existing object.

Modifier and Type
Method and Description
public boolean
public E
get <E >(
String fieldName
)

Returns the value for the given field.

public byte
String fieldName
)

Returns the byte[] value for a given field.

public boolean
String fieldName
)

Returns the boolean value for a given field.

public byte
String fieldName
)

Returns the byte value for a given field.

public Date
String fieldName
)

Returns the Date value for a given field.

public Decimal128
String fieldName
)

Returns the Decimal128 value for a given field.

String fieldName,
java.lang.Class<E> primitiveType
)

Returns the RealmDictionary containing only primitive values.

String fieldName
)

Returns the RealmDictionary of DynamicRealmObject s being linked from the given field.

public double
String fieldName
)

Returns the double value for a given field.

Returns DynamicRealm instance where this DynamicRealmObject belongs.

public String

Returns the list of field names on this object.

String fieldName
)

Returns the type used by the underlying storage engine to represent this field.

public float
String fieldName
)

Returns the float value for a given field.

public int
String fieldName
)

Returns the int value for a given field.

public RealmList
getList <E >(
String fieldName,
java.lang.Class<E> primitiveType
)

Returns the RealmList containing only primitive values.

public RealmList
String fieldName
)

Returns the RealmList of DynamicRealmObject s being linked from the given field.

public long
String fieldName
)

Returns the long value for a given field.

String fieldName
)

Returns the object being linked to from this field.

public ObjectId
String fieldName
)

Returns the ObjectId value for a given field.

public RealmAny
String fieldName
)

Returns the RealmAny value for a given field.

public RealmSet
String fieldName,
java.lang.Class<E> primitiveType
)

Returns the RealmSet containing only primitive values.

public RealmSet
String fieldName
)

Returns the RealmSet of DynamicRealmObject s being linked from the given field.

public short
String fieldName
)

Returns the short value for a given field.

public String
String fieldName
)

Returns the String value for a given field.

public String

Returns the type of object.

public UUID
String fieldName
)

Returns the UUID value for a given field.

public boolean
String fieldName
)

Checks whether an object has the given field or not.

public int

Returns a hash code value for the DynamicRealmObject object.

public boolean
String fieldName
)

Checks if the value of a given field is null .

String srcClassName,
String srcFieldName
)

Returns RealmResults containing all srcClassName class objects that have a relationship to this object from srcFieldName field.

public void
public ProxyState
public void
set (
String fieldName,
Object value
)

Sets the value for the given field.

public void
String fieldName,
byte[] value
)

Sets the binary value of the given field.

public void
String fieldName,
boolean value
)

Sets the boolean value of the given field.

public void
String fieldName,
byte value
)

Sets the byte value of the given field.

public void
String fieldName,
Date value
)

Sets the Date value of the given field.

public void
String fieldName,
Decimal128 value
)

Sets the Decimal128 value of the given field.

public void

Sets the reference to a RealmDictionary on the given field.

public void
String fieldName,
double value
)

Sets the double value of the given field.

public void
String fieldName,
float value
)

Sets the float value of the given field.

public void
String fieldName,
int value
)

Sets the int value of the given field.

public void
setList <E >(
)

Sets the reference to a RealmList on the given field.

public void
String fieldName,
long value
)

Sets the long value of the given field.

public void
String fieldName
)

Sets the value to null for the given field.

public void

Sets a reference to another object on the given field.

public void
String fieldName,
ObjectId value
)

Sets the ObjectId value of the given field.

public void
String fieldName,
RealmAny value
)

Sets the RealmAny value of the given field.

public void

Sets the reference to a RealmSet on the given field.

public void
String fieldName,
short value
)

Sets the short value of the given field.

public void
String fieldName,
String value
)

Sets the String value of the given field.

public void
String fieldName,
UUID value
)

Sets the UUID value of the given field.

public String
  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize
  • Methods inherited from class io.realm.RealmObject : deleteFromRealm , deleteFromRealm , isValid , isValid , isFrozen , freeze , isFrozen , freeze , isLoaded , isLoaded , isManaged , isManaged , getRealm , getRealm , load , load , addChangeListener , addChangeListener , addChangeListener , addChangeListener , removeChangeListener , removeChangeListener , removeChangeListener , removeChangeListener , removeAllChangeListeners , removeAllChangeListeners , asFlowable , asChangesetObservable , asFlowable , asChangesetObservable

Creates a dynamic Realm object based on an existing object.

Parameters

  • obj - the Realm object to convert to a dynamic object. Only objects managed by Realm can be used.
public boolean equals (
)

Overrides

equals in class Object

public E get <E >(
String fieldName
)

Returns the value for the given field.

Parameters

  • fieldName - name of the field.

Returns

the field value.

Throws

public byte getBlob (
String fieldName
)

Returns the byte[] value for a given field.

Parameters

  • fieldName - the name of the field.

Returns

the byte[] value.

Throws

public boolean getBoolean (
String fieldName
)

Returns the boolean value for a given field.

If the field is nullable, use isNull(String) to check for null instead of using this method.

Parameters

  • fieldName - the name of the field.

Returns

the boolean value.

Throws

public byte getByte (
String fieldName
)

Returns the byte value for a given field.

If the field is nullable, use isNull(String) to check for null instead of using this method.

Parameters

  • fieldName - the name of the field.

Returns

the byte value.

Throws

public Date getDate (
String fieldName
)

Returns the Date value for a given field.

Parameters

  • fieldName - the name of the field.

Returns

the Date value.

Throws

public Decimal128 getDecimal128 (
String fieldName
)

Returns the Decimal128 value for a given field.

Parameters

  • fieldName - the name of the field.

Returns

the Decimal128 value.

Throws

String fieldName,
java.lang.Class<E> primitiveType
)

Returns the RealmDictionary containing only primitive values.

If the dictionary contains references to other Realm objects, use getDictionary(String) instead.

Parameters

  • fieldName - the name of the field.
  • primitiveType - the type of elements in the dictionary. Only primitive types are supported.

Returns

the RealmDictionary data for this field.

Throws

Returns the RealmDictionary of DynamicRealmObject s being linked from the given field.

If the dictionary contains primitive types, use getDictionary(String, Class) instead.

Parameters

  • fieldName - the name of the field.

Returns

the RealmDictionary data for this field.

Throws

public double getDouble (
String fieldName
)

Returns the double value for a given field.

If the field is nullable, use isNull(String) to check for null instead of using this method.

Parameters

  • fieldName - the name of the field.

Returns

the double value.

Throws

Returns DynamicRealm instance where this DynamicRealmObject belongs.

You must not call DynamicRealm.close() against returned instance.

Returns

DynamicRealm instance where this object belongs.

Throws

Returns the list of field names on this object.

Returns

list of field names on this objects or the empty list if the object doesn't have any fields.

Returns the type used by the underlying storage engine to represent this field.

Returns

the underlying type used by Realm to represent this field.

public float getFloat (
String fieldName
)

Returns the float value for a given field.

If the field is nullable, use isNull(String) to check for null instead of using this method.

Parameters

  • fieldName - the name of the field.

Returns

the float value.

Throws

public int getInt (
String fieldName
)

Returns the int value for a given field.

If the field is nullable, use isNull(String) to check for null instead of using this method.

Parameters

  • fieldName - the name of the field.

Returns

the int value. Integer values exceeding Integer.MAX_VALUE will wrap.

Throws

public RealmList getList <E >(
String fieldName,
java.lang.Class<E> primitiveType
)

Returns the RealmList containing only primitive values.

If the list contains references to other Realm objects, use getList(String) instead.

Parameters

  • fieldName - the name of the field.
  • primitiveType - the type of elements in the list. Only primitive types are supported.

Returns

the RealmList data for this field.

Throws

String fieldName
)

Returns the RealmList of DynamicRealmObject s being linked from the given field.

If the list contains primitive types, use getList(String, Class) instead.

Parameters

  • fieldName - the name of the field.

Returns

the RealmList data for this field.

Throws

public long getLong (
String fieldName
)

Returns the long value for a given field.

If the field is nullable, use isNull(String) to check for null instead of using this method.

Parameters

  • fieldName - the name of the field.

Returns

the long value. Integer values exceeding Long.MAX_VALUE will wrap.

Throws

Returns the object being linked to from this field.

Parameters

  • fieldName - the name of the field.

Returns

the DynamicRealmObject representation of the linked object or null if no object is linked.

Throws

public ObjectId getObjectId (
String fieldName
)

Returns the ObjectId value for a given field.

Parameters

  • fieldName - the name of the field.

Returns

the ObjectId value.

Throws

String fieldName
)

Returns the RealmAny value for a given field.

Parameters

  • fieldName - the name of the field.

Returns

the RealmAny value.

Throws

public RealmSet getRealmSet <E >(
String fieldName,
java.lang.Class<E> primitiveType
)

Returns the RealmSet containing only primitive values.

If the set contains references to other Realm objects, use getRealmSet(String) instead.

Parameters

  • fieldName - the name of the field.
  • primitiveType - the type of elements in the set. Only primitive types are supported.

Returns

the RealmSet data for this field.

Throws

String fieldName
)

Returns the RealmSet of DynamicRealmObject s being linked from the given field.

If the set contains primitive types, use getRealmSet(String, Class) instead.

Parameters

  • fieldName - the name of the field.

Returns

the RealmSet data for this field.

Throws

public short getShort (
String fieldName
)

Returns the short value for a given field.

If the field is nullable, use isNull(String) to check for null instead of using this method.

Parameters

  • fieldName - the name of the field.

Returns

the short value. Integer values exceeding Short.MAX_VALUE will wrap.

Throws

public String getString (
String fieldName
)

Returns the String value for a given field.

Parameters

  • fieldName - the name of the field.

Returns

the String value.

Throws

public String getType ()

Returns the type of object. This will normally correspond to the name of a class that is extending RealmObject .

Returns

this objects type.

public UUID getUUID (
String fieldName
)

Returns the UUID value for a given field.

Parameters

  • fieldName - the name of the field.

Returns

the UUID value.

Throws

public boolean hasField (
String fieldName
)

Checks whether an object has the given field or not.

Parameters

  • fieldName - field name to check.

Returns

true if the object has a field with the given name, false otherwise.

public int hashCode ()

Returns a hash code value for the DynamicRealmObject object.

By the general contract of Object.hashCode() , any two objects for which equals returns true must return the same hash code value.

Note that a RealmObject is a live object, and it might be updated by changes from other threads. This means that a hash code value of the object is not stable, and the value should be neither used as a key in HashMap nor saved in HashSet.

Returns

a hash code value for the object.

Overrides

hashCode in class Object

Tip
See also:
public boolean isNull (
String fieldName
)

Checks if the value of a given field is null .

Parameters

  • fieldName - the name of the field.

Returns

true if field value is null, false otherwise.

Throws

String srcClassName,
String srcFieldName
)

Returns RealmResults containing all srcClassName class objects that have a relationship to this object from srcFieldName field.

An entry is added for each reference, e.g. if the same reference is in a list multiple times, the src object will show up here multiple times.

Parameters

  • srcClassName - name of the class returned objects belong to.
  • srcFieldName - name of the field in the source class that holds a reference to this object. Field type must be either io.realm.RealmFieldType.OBJECT or io.realm.RealmFieldType.LIST .

Returns

the result.

Throws

  • IllegalArgumentException - if the srcClassName is null or does not exist, the srcFieldName is null or does not exist, type of the source field is not supported.
public void set (
String fieldName,
Object value
)

Sets the value for the given field. This method will automatically try to convert numbers and booleans that are given as String to their appropriate type. For example "10" will be converted to 10 if the field type is int .

Using the typed setters will be faster than using this method.

Throws

public void setBlob (
String fieldName,
byte[] value
)

Sets the binary value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setBoolean (
String fieldName,
boolean value
)

Sets the boolean value of the given field.

Parameters

  • fieldName - field name to update.
  • value - value to insert.

Throws

public void setByte (
String fieldName,
byte value
)

Sets the byte value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setDate (
String fieldName,
Date value
)

Sets the Date value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setDecimal128 (
String fieldName,
Decimal128 value
)

Sets the Decimal128 value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setDictionary <E >(
String fieldName,
)

Sets the reference to a RealmDictionary on the given field.

This will copy all the elements in the dictionary into Realm, but any further changes to the dictionary will not be reflected in the Realm. Use getDictionary(String) in order to get a reference to the managed dictionary.

Parameters

  • fieldName - field name.
  • dictionary - dictionary of objects. Must either be primitive types or DynamicRealmObject s.

Throws

  • IllegalArgumentException - if field name doesn't exist, it is not a dictionary field, the objects in the dictionary doesn't match the expected type or any Realm object in the dictionary belongs to a different Realm.
public void setDouble (
String fieldName,
double value
)

Sets the double value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setFloat (
String fieldName,
float value
)

Sets the float value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setInt (
String fieldName,
int value
)

Sets the int value of the given field.

Parameters

  • fieldName - field name to update.
  • value - value to insert.

Throws

public void setList <E >(
)

Sets the reference to a RealmList on the given field.

This will copy all the elements in the list into Realm, but any further changes to the list will not be reflected in the Realm. Use getList(String) in order to get a reference to the managed list.

Parameters

  • fieldName - field name.
  • list - list of objects. Must either be primitive types or DynamicRealmObject s.

Throws

  • IllegalArgumentException - if field name doesn't exist, it is not a list field, the objects in the list doesn't match the expected type or any Realm object in the list belongs to a different Realm.
public void setLong (
String fieldName,
long value
)

Sets the long value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setNull (
String fieldName
)

Sets the value to null for the given field.

Parameters

  • fieldName - field name.

Throws

public void setObject (
String fieldName,
)

Sets a reference to another object on the given field.

Parameters

  • fieldName - field name.
  • value - object to link to.

Throws

  • IllegalArgumentException - if field name doesn't exist, it doesn't link to other Realm objects, the type of DynamicRealmObject doesn't match or it belongs to a different Realm.
public void setObjectId (
String fieldName,
ObjectId value
)

Sets the ObjectId value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setRealmAny (
String fieldName,
RealmAny value
)

Sets the RealmAny value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setRealmSet <E >(
)

Sets the reference to a RealmSet on the given field.

This will copy all the elements in the set into Realm, but any further changes to the set will not be reflected in the Realm. Use getRealmSet(String) in order to get a reference to the managed set.

Parameters

  • fieldName - field name.
  • set - set of objects. Must either be primitive types or DynamicRealmObject s.

Throws

  • IllegalArgumentException - if field name doesn't exist, it is not a set field, the objects in the set doesn't match the expected type or any Realm object in the set belongs to a different Realm.
public void setShort (
String fieldName,
short value
)

Sets the short value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setString (
String fieldName,
String value
)

Sets the String value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public void setUUID (
String fieldName,
UUID value
)

Sets the UUID value of the given field.

Parameters

  • fieldName - field name.
  • value - value to insert.

Throws

public String toString ()

Overrides

toString in class Object

←  Interface DynamicRealm.Transaction.OnSuccessEnum FieldAttribute →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.