public final class RealmObjectSchema
extends java.lang.Object
RealmMigration| Modifier and Type | Class and Description |
|---|---|
static interface |
RealmObjectSchema.Function
Function interface, used when traversing all objects of the current class and apply a function on each.
|
| Modifier and Type | Method and Description |
|---|---|
RealmObjectSchema |
addField(java.lang.String fieldName,
java.lang.Class<?> fieldType,
FieldAttribute... attributes)
Adds a new simple field to the RealmObject class.
|
RealmObjectSchema |
addIndex(java.lang.String fieldName)
Adds an index to a given field.
|
RealmObjectSchema |
addPrimaryKey(java.lang.String fieldName)
Adds a primary key to a given field.
|
RealmObjectSchema |
addRealmListField(java.lang.String fieldName,
RealmObjectSchema objectSchema)
Adds a new field that references a
RealmList. |
RealmObjectSchema |
addRealmObjectField(java.lang.String fieldName,
RealmObjectSchema objectSchema)
Adds a new field that references another
RealmObject. |
java.lang.String |
getClassName()
Returns the name of the RealmObject class being represented by this schema.
|
java.util.Set<java.lang.String> |
getFieldNames()
Returns all fields in this class.
|
RealmFieldType |
getFieldType(java.lang.String fieldName)
Returns the type used by the underlying storage engine to represent this field.
|
boolean |
hasField(java.lang.String fieldName)
Tests if the class has field defined with the given name.
|
boolean |
hasIndex(java.lang.String fieldName)
Checks if a given field has an index defined.
|
boolean |
hasPrimaryKey()
Checks if the class has a primary key defined.
|
boolean |
isNullable(java.lang.String fieldName)
Checks if a given field is nullable, i.e.
|
boolean |
isPrimaryKey(java.lang.String fieldName)
Checks if a given field is the primary key field.
|
boolean |
isRequired(java.lang.String fieldName)
Checks if a given field is required, i.e.
|
RealmObjectSchema |
removeField(java.lang.String fieldName)
Removes a field from the class.
|
RealmObjectSchema |
removeIndex(java.lang.String fieldName)
Removes an index from a given field.
|
RealmObjectSchema |
removePrimaryKey()
Removes the primary key from this class.
|
RealmObjectSchema |
renameField(java.lang.String currentFieldName,
java.lang.String newFieldName)
Renames a field from one name to another.
|
RealmObjectSchema |
setClassName(java.lang.String className)
Sets a new name for this RealmObject class.
|
RealmObjectSchema |
setNullable(java.lang.String fieldName,
boolean nullable)
Sets a field to be nullable, i.e.
|
RealmObjectSchema |
setRequired(java.lang.String fieldName,
boolean required)
Sets a field to be required, i.e.
|
RealmObjectSchema |
transform(RealmObjectSchema.Function function)
Runs a transformation function on each RealmObject instance of the current class.
|
public java.lang.String getClassName()
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.
public RealmObjectSchema setClassName(java.lang.String className)
className - the new name for this class.RealmSchema.rename(String, String)public RealmObjectSchema addField(java.lang.String fieldName, java.lang.Class<?> fieldType, FieldAttribute... attributes)
RealmObject
for the list of supported types. If the field should allow null values use the boxed type instead e.g.
Integer.class instead of int.class.
To add fields that reference other RealmObjects or RealmLists use addRealmObjectField(String, RealmObjectSchema)
or addRealmListField(String, RealmObjectSchema) instead.
fieldName - name of the field to add.fieldType - type of field to add. See RealmObject for the full list.attributes - set of attributes for this field.java.lang.IllegalArgumentException - if the type isn't supported, field name is illegal or a field with that name
already exists.public RealmObjectSchema addRealmObjectField(java.lang.String fieldName, RealmObjectSchema objectSchema)
RealmObject.fieldName - name of the field to add.objectSchema - schema for the Realm type being referenced.java.lang.IllegalArgumentException - if field name is illegal or a field with that name already exists.public RealmObjectSchema addRealmListField(java.lang.String fieldName, RealmObjectSchema objectSchema)
RealmList.fieldName - name of the field to add.objectSchema - schema for the Realm type being referenced.java.lang.IllegalArgumentException - if the field name is illegal or a field with that name already exists.public RealmObjectSchema removeField(java.lang.String fieldName)
fieldName - field name to remove.java.lang.IllegalArgumentException - if field name doesn't exist.public RealmObjectSchema renameField(java.lang.String currentFieldName, java.lang.String newFieldName)
currentFieldName - field name to rename.newFieldName - the new field name.java.lang.IllegalArgumentException - if field name doesn't exist or if the new field name already exists.public boolean hasField(java.lang.String fieldName)
fieldName - field name to test.true if the field exists, false otherwise.public RealmObjectSchema addIndex(java.lang.String fieldName)
Index annotation
on the field.fieldName - field to add index to.java.lang.IllegalArgumentException - if field name doesn't exist, the field cannot be indexed or it already has a
index defined.public boolean hasIndex(java.lang.String fieldName)
fieldName - existing field name to check.true if field is indexed, false otherwise.java.lang.IllegalArgumentException - if field name doesn't exist.Indexpublic RealmObjectSchema removeIndex(java.lang.String fieldName)
@Index annotation on the field.fieldName - field to remove index from.java.lang.IllegalArgumentException - if field name doesn't exist or the field doesn't have an index.public RealmObjectSchema addPrimaryKey(java.lang.String fieldName)
PrimaryKey
annotation on the field.fieldName - field to set as primary key.java.lang.IllegalArgumentException - if field name doesn't exist, the field cannot be a primary key or it already
has a primary key defined.public RealmObjectSchema removePrimaryKey()
PrimaryKey
annotation from the class.java.lang.IllegalArgumentException - if the class doesn't have a primary key defined.public RealmObjectSchema setRequired(java.lang.String fieldName, boolean required)
null values. This is equivalent to switching
between boxed types and their primitive variant e.g. Integer to int.fieldName - name of field in the class.required - true if field should be required, false otherwise.java.lang.IllegalArgumentException - if the field name doesn't exist, cannot have the Required annotation or
the field already have been set as required.Requiredpublic RealmObjectSchema setNullable(java.lang.String fieldName, boolean nullable)
null values. This is equivalent to switching
between primitive types and their boxed variant e.g. int to Integer.fieldName - name of field in the class.nullable - true if field should be nullable, false otherwise.java.lang.IllegalArgumentException - if the field name doesn't exist, or cannot be set as nullable.public boolean isRequired(java.lang.String fieldName)
null values.fieldName - field to check.true if it is required, false otherwise.java.lang.IllegalArgumentException - if field name doesn't exist.setRequired(String, boolean)public boolean isNullable(java.lang.String fieldName)
null values.fieldName - field to check.true if it is required, false otherwise.java.lang.IllegalArgumentException - if field name doesn't exist.setNullable(String, boolean)public boolean isPrimaryKey(java.lang.String fieldName)
fieldName - field to check.true if it is the primary key field, false otherwise.java.lang.IllegalArgumentException - if field name doesn't exist.addPrimaryKey(String)public boolean hasPrimaryKey()
true if a primary key is defined, false otherwise.PrimaryKeypublic java.util.Set<java.lang.String> getFieldNames()
public RealmObjectSchema transform(RealmObjectSchema.Function function)
DynamicRealmObject.public RealmFieldType getFieldType(java.lang.String fieldName)