Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
io.realm

Class RealmObjectSchema

java.lang.Object
io.realm.RealmObjectSchema

Class for interacting with the schema for a given RealmObject class. This makes it possible to inspect, add, delete or change the fields for given class.If this RealmObjectSchema is retrieved from an immutable RealmSchema , this RealmObjectSchema will be immutable as well.

Tip

  • io.realm.RealmMigration

Modificador y Tipo
Clase y descripción

public static interface

Modificador y Tipo
Método y descripción

public abstract RealmObjectSchema

Adds a new simple field to the RealmObject class.

public abstract RealmObjectSchema

String fieldName
)

Adds an index to a given field.

public abstract RealmObjectSchema

String fieldName
)

Adds a primary key to a given field.

public abstract RealmObjectSchema

Agrega un nuevo campo que hace referencia a un RealmDictionary con valores primitivos.

public abstract RealmObjectSchema

Agrega un nuevo campo que contiene un RealmDictionary con referencias a otras clases de modelos Realm.

public abstract RealmObjectSchema

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

Adds a new field that references a RealmList with primitive values.

public abstract RealmObjectSchema

String fieldName,
RealmObjectSchema objectSchema
)

Adds a new field that contains a RealmList with references to other Realm model classes.

public abstract RealmObjectSchema

Adds a new field that references another RealmObject .

public abstract RealmObjectSchema

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

Adds a new field that references a RealmSet with primitive values.

public abstract RealmObjectSchema

String fieldName,
RealmObjectSchema objectSchema
)

Agrega un nuevo campo que contiene un RealmSet con referencias a otras clases de modelos Realm.

public String

Returns the name of the RealmObject class being represented by this schema.

public Set

Devuelve todos los campos de esta clase.

String fieldName
)

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

public String

Returns the name of the primary key field.

public booleano

String fieldName
)

Verifica si la clase tiene un campo definido con el nombre dado.

public booleano

String fieldName
)

Checks if a given field has an index defined.

public booleano

Checks if the class has a primary key defined.

public booleano

Returns true if objects of this type are considered "embedded".

public booleano

String fieldName
)

Comprueba si un campo determinado puede ser nulo o, dicho de otro modo, si se permiten valores null.

public booleano

String fieldName
)

Verifica si un campo dado es el campo llave primaria.

public booleano

String fieldName
)

Comprueba si un campo determinado es obligatorio, es decir, no puede contener valores null.

public abstract RealmObjectSchema

String fieldName
)

Removes a field from the class.

public abstract RealmObjectSchema

String fieldName
)

Removes an index from a given field.

public abstract RealmObjectSchema

Removes the primary key from this class.

public abstract RealmObjectSchema

String currentFieldName,
String newFieldName
)

Cambia el nombre de un campo de un nombre a otro.

public abstract RealmObjectSchema

String className
)

Sets a new name for this RealmObject class.

public void

boolean embedded
)

Convierte la clase para que sea embebida o no.

public abstract RealmObjectSchema

String fieldName,
boolean nullable
)

Sets a field to be nullable i.e., it should be able to hold null values.

public abstract RealmObjectSchema

String fieldName,
boolean required
)

Sets a field to be required i.e., it is not allowed to hold null values.

public abstract RealmObjectSchema

Runs a transformation function on each RealmObject instance of the current class.

  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

public abstract RealmObjectSchema addField (
String fieldName,
)

Añade un nuevo campo simple a la clase RealmObject. El tipo debe ser compatible con Realm. Consulta RealmObject para ver la lista de tipos compatibles. Si el campo debe admitir null valores, utiliza el tipo en caja; por ejemplo, Integer.class en lugar int.class de.

Para añadir campos que hagan referencia a otros RealmObjects o RealmLists, utilice addRealmObjectField(String, RealmObjectSchema) o addRealmListField(String, RealmObjectSchema) en su lugar.

Parámetros

  • fieldName - name of the field to add.

  • fieldType - Tipo de campo a agregar. Consulte RealmObject para ver la lista completa.

  • attributes - set of attributes for this field.

Devuelve

El esquema actualizado.

Throws

public abstract RealmObjectSchema addIndex (
String fieldName
)

Adds an index to a given field. This is the equivalent of adding the io.realm.annotations.Index annotation on the field.

Parámetros

  • fieldName - field to add index to.

Devuelve

El esquema actualizado.

Throws

String fieldName
)

Agrega una clave primaria a un campo específico. Esto es lo mismo que agregar la anotación io.realm.annotations.PrimaryKey en el campo. Además, esto agrega implícitamente la anotación io.realm.annotations.índice en el campo también.

Parámetros

  • fieldName - field to set as primary key.

Devuelve

El esquema actualizado.

Throws

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

Agrega un nuevo campo que referencia un RealmDictionary con valores primitivos. Consulta RealmObject para la lista de tipos compatibles.

Nullability of elements are defined by using the correct class e.g., Integer.class instead of int.class . Alternatively setRequired(String, boolean) can be used.

Ejemplo:

// Defines the dictionary of Strings as being non null.
RealmObjectSchema schema = schema.create("Person")
.addRealmDictionaryField("parentAndChild", String.class)
.setRequired("parentAndChild", true)

If the list contains references to other Realm classes, use addRealmDictionaryField(String, RealmObjectSchema) instead.

Parámetros

  • fieldName - name of the field to add.

  • primitiveType - tipo sencillo de elementos en el arreglo.

Devuelve

El esquema actualizado.

Throws

String fieldName,
RealmObjectSchema objectSchema
)

Agrega un nuevo campo que contiene un RealmDictionary con referencias a otras clases de modelos Realm.

Si el diccionario contiene tipos primitivos, utilice addRealmDictionaryField(String, clase) en su lugar.

Parámetros

  • fieldName - name of the field to add.

  • objectSchema - schema for the Realm type being referenced.

Devuelve

El esquema actualizado.

Throws

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

Adds a new field that references a RealmList with primitive values. See RealmObject for the list of supported types.

Nullability of elements are defined by using the correct class e.g., Integer.class instead of int.class . Alternatively setRequired(String, boolean) can be used.

Ejemplo:

// Defines the list of Strings as being non null.
RealmObjectSchema schema = schema.create("Person")
.addRealmListField("children", String.class)
.setRequired("children", true)

Si la lista contiene referencias a otras clases de Realm, utiliza addRealmListField(String, RealmObjectSchema) en su lugar.

Parámetros

  • fieldName - name of the field to add.

  • primitiveType - tipo sencillo de elementos en el arreglo.

Devuelve

El esquema actualizado.

Throws

String fieldName,
RealmObjectSchema objectSchema
)

Adds a new field that contains a RealmList with references to other Realm model classes.

Si la lista contiene tipos primitivos, usa addRealmListField(String, clase) en su lugar.

Parámetros

  • fieldName - name of the field to add.

  • objectSchema - schema for the Realm type being referenced.

Devuelve

El esquema actualizado.

Throws

String fieldName,
RealmObjectSchema objectSchema
)

Adds a new field that references another RealmObject .

Parámetros

  • fieldName - name of the field to add.

  • objectSchema - schema for the Realm type being referenced.

Devuelve

El esquema actualizado.

Throws

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

Agrega un nuevo campo que hace referencia a un RealmSet con valores primitivos. Consulta RealmObject para la lista de tipos compatibles.

Nullability of elements are defined by using the correct class e.g., Integer.class instead of int.class . Alternatively setRequired(String, boolean) can be used.

Ejemplo:

// Defines the set of Strings as being non null.
RealmObjectSchema schema = schema.create("Person")
.addRealmSetField("children", String.class)
.setRequired("children", true)

If the list contains references to other Realm classes, use addRealmSetField(String, RealmObjectSchema) instead.

Parámetros

  • fieldName - name of the field to add.

  • primitiveType - tipo sencillo de elementos en el arreglo.

Devuelve

El esquema actualizado.

Throws

String fieldName,
RealmObjectSchema objectSchema
)

Agrega un nuevo campo que contiene un RealmSet con referencias a otras clases de modelos Realm.

Si el conjunto contiene tipos primitivos, utilice addRealmSetField(String, Class) en su lugar.

Parámetros

  • fieldName - name of the field to add.

  • objectSchema - schema for the Realm type being referenced.

Devuelve

El esquema actualizado.

Throws

Returns the name of the RealmObject class being represented by this schema.

  • When using a normal Realm this name is the same as the RealmObject class.

  • When using a DynamicRealm this is the name used in all API methods requiring a class name.

Devuelve

el nombre de la clase RealmObject representada por este esquema.

Throws

public Set getFieldNames ()

Devuelve todos los campos de esta clase.

Devuelve

una lista de todos los campos en esta clase.

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

Parámetros

  • fieldName - nombre del campo objetivo.

Devuelve

tipo subyacente que utiliza Realm para representar este campo.

Returns the name of the primary key field.

Devuelve

the name of the primary key field.

Throws

public boolean hasField (
String fieldName
)

Verifica si la clase tiene un campo definido con el nombre dado.

Parámetros

  • fieldName - field name to test.

Devuelve

true if the field exists, false otherwise.

public boolean hasIndex (
String fieldName
)

Checks if a given field has an index defined.

Parámetros

  • fieldName - existing field name to check.

Devuelve

true if field is indexed, false otherwise.

Throws

public boolean hasPrimaryKey ()

Checks if the class has a primary key defined.

Devuelve

true if a primary key is defined, false otherwise.

public boolean isEmbedded ()

Returns true if objects of this type are considered "embedded". See RealmClass.embedded() for further details.

Devuelve

true if objects of this type are embedded. false if not.

public boolean isNullable (
String fieldName
)

Comprueba si un campo determinado puede ser nulo o, dicho de otro modo, si se permiten valores null.

Parámetros

  • fieldName - field to check.

Devuelve

true if it is required, false otherwise.

Throws

public boolean isPrimaryKey (
String fieldName
)

Verifica si un campo dado es el campo llave primaria.

Parámetros

  • fieldName - field to check.

Devuelve

true if it is the primary key field, false otherwise.

Throws

public boolean isRequired (
String fieldName
)

Comprueba si un campo determinado es obligatorio, es decir, no puede contener valores null.

Parámetros

  • fieldName - field to check.

Devuelve

true if it is required, false otherwise.

Throws

public abstract RealmObjectSchema removeField (
String fieldName
)

Removes a field from the class.

Parámetros

  • fieldName - field name to remove.

Devuelve

El esquema actualizado.

Throws

public abstract RealmObjectSchema removeIndex (
String fieldName
)

Remueve un índice de un campo dado. Esto es lo mismo que remover la anotación @Index en el campo.

Parámetros

  • fieldName - field to remove index from.

Devuelve

El esquema actualizado.

Throws

Removes the primary key from this class. This is the same as removing the io.realm.annotations.PrimaryKey annotation from the class. Further, this implicitly removes io.realm.annotations.Index annotation from the field as well.

Devuelve

El esquema actualizado.

Throws

public abstract RealmObjectSchema renameField (
String currentFieldName,
String newFieldName
)

Cambia el nombre de un campo de un nombre a otro.

Parámetros

  • currentFieldName - field name to rename.

  • newFieldName - el nuevo nombre del campo.

Devuelve

El esquema actualizado.

Throws

String className
)

Sets a new name for this RealmObject class. This is equivalent to renaming it.

Parámetros

  • className - the new name for this class.

Throws

public void setEmbedded (
boolean embedded
)

Converts the class to be embedded or not.A class can only be marked as embedded if the following invariants are satisfied:

  • The class is not allowed to have a primary key defined.

  • Todos los objetos existentes de este tipo, deben tener uno y un solo objeto principal que ya apunte a él. Si 0 o más de 1 objetos tienen una referencia a un objeto que está a punto de ser marcado como incrustado, se lanzará una IllegalStateException.

Throws

  • IllegalStateException - si la clase no pudo convertirse porque rompió algunas de las invariantes de los objetos incrustados.

public abstract RealmObjectSchema setNullable (
String fieldName,
boolean nullable
)

Sets a field to be nullable i.e., it should be able to hold null values. This is equivalent to switching between primitive types and their boxed variant e.g., int to Integer .

Si el tipo de campo designado es una lista de valores (que no sean RealmObject s, la nulidad especificada solo afecta a sus elementos, no al propio campo). La lista de valores en sí nunca puede ser nula.

Parámetros

  • fieldName - name of field in the class.

  • nullable - true si el campo debe ser anulable, false de lo contrario.

Devuelve

El esquema actualizado.

Throws

public abstract RealmObjectSchema setRequired (
String fieldName,
boolean required
)

Establece que un campo sea obligatorio, es decir, no se permite que contenga valores null. Esto equivale a cambiar entre tipos empaquetados y su variante primitiva, por ejemplo, Integer a int .

Si el tipo de campo designado es una lista de valores (que no sean RealmObject s, la nulidad especificada solo afecta a sus elementos, no al propio campo). La lista de valores en sí nunca puede ser nula.

Parámetros

  • fieldName - name of field in the class.

  • required - true si el campo debe ser obligatorio, false en caso contrario.

Devuelve

El esquema actualizado.

Throws

Runs a transformation function on each RealmObject instance of the current class. The object will be represented as a DynamicRealmObject .

There is no guarantees in which order the objects are returned.

Parámetros

  • function - transformation function.

Devuelve

this schema.

Throws

Volver

RealmObjectChangeListener