public abstract class RealmObjectSchema extends Object
If this RealmObjectSchema
is retrieved from an immutable RealmSchema
, this RealmObjectSchema
will be immutable as well.
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 |
---|---|
abstract RealmObjectSchema |
addField(String fieldName,
Class<?> fieldType,
FieldAttribute... attributes)
Adds a new simple field to the RealmObject class.
|
abstract RealmObjectSchema |
addIndex(String fieldName)
Adds an index to a given field.
|
abstract RealmObjectSchema |
addPrimaryKey(String fieldName)
Adds a primary key to a given field.
|
abstract RealmObjectSchema |
addRealmListField(String fieldName,
RealmObjectSchema objectSchema)
Adds a new field that references a
RealmList . |
abstract RealmObjectSchema |
addRealmObjectField(String fieldName,
RealmObjectSchema objectSchema)
Adds a new field that references another
RealmObject . |
void |
close()
Deprecated.
RealmObjectSchema doesn't have to be released manually. |
String |
getClassName()
Returns the name of the RealmObject class being represented by this schema.
|
Set<String> |
getFieldNames()
Returns all fields in this class.
|
RealmFieldType |
getFieldType(String fieldName)
Returns the type used by the underlying storage engine to represent this field.
|
String |
getPrimaryKey()
Returns the name of the primary key field.
|
boolean |
hasField(String fieldName)
Tests if the class has field defined with the given name.
|
boolean |
hasIndex(String fieldName)
Checks if a given field has an index defined.
|
boolean |
hasPrimaryKey()
Checks if the class has a primary key defined.
|
boolean |
isNullable(String fieldName)
Checks if a given field is nullable i.e., it is allowed to contain
null values. |
boolean |
isPrimaryKey(String fieldName)
Checks if a given field is the primary key field.
|
boolean |
isRequired(String fieldName)
Checks if a given field is required i.e., it is not allowed to contain
null values. |
abstract RealmObjectSchema |
removeField(String fieldName)
Removes a field from the class.
|
abstract RealmObjectSchema |
removeIndex(String fieldName)
Removes an index from a given field.
|
abstract RealmObjectSchema |
removePrimaryKey()
Removes the primary key from this class.
|
abstract RealmObjectSchema |
renameField(String currentFieldName,
String newFieldName)
Renames a field from one name to another.
|
abstract RealmObjectSchema |
setClassName(String className)
Sets a new name for this RealmObject class.
|
abstract RealmObjectSchema |
setNullable(String fieldName,
boolean nullable)
Sets a field to be nullable i.e., it should be able to hold
null values. |
abstract RealmObjectSchema |
setRequired(String fieldName,
boolean required)
Sets a field to be required i.e., it is not allowed to hold
null values. |
abstract RealmObjectSchema |
transform(RealmObjectSchema.Function function)
Runs a transformation function on each RealmObject instance of the current class.
|
@Deprecated public void close()
RealmObjectSchema
doesn't have to be released manually.public String getClassName()
Realm
this name is the same as the RealmObject
class.DynamicRealm
this is the name used in all API methods requiring a class name.public abstract RealmObjectSchema setClassName(String className)
className
- the new name for this class.IllegalArgumentException
- if className is null
or an empty string, or its length exceeds 56
characters.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.RealmSchema.rename(String, String)
public abstract RealmObjectSchema addField(String fieldName, 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.IllegalArgumentException
- if the type isn't supported, field name is illegal or a field with that nameUnsupportedOperationException
- if this RealmObjectSchema
is immutable.
already exists.public abstract RealmObjectSchema addRealmObjectField(String fieldName, RealmObjectSchema objectSchema)
RealmObject
.fieldName
- name of the field to add.objectSchema
- schema for the Realm type being referenced.IllegalArgumentException
- if field name is illegal or a field with that name already exists.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public abstract RealmObjectSchema addRealmListField(String fieldName, RealmObjectSchema objectSchema)
RealmList
.fieldName
- name of the field to add.objectSchema
- schema for the Realm type being referenced.IllegalArgumentException
- if the field name is illegal or a field with that name already exists.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public abstract RealmObjectSchema removeField(String fieldName)
fieldName
- field name to remove.IllegalArgumentException
- if field name doesn't exist.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public abstract RealmObjectSchema renameField(String currentFieldName, String newFieldName)
currentFieldName
- field name to rename.newFieldName
- the new field name.IllegalArgumentException
- if field name doesn't exist or if the new field name already exists.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public boolean hasField(String fieldName)
fieldName
- field name to test.true
if the field exists, false
otherwise.public abstract RealmObjectSchema addIndex(String fieldName)
Index
annotation on the field.fieldName
- field to add index to.IllegalArgumentException
- if field name doesn't exist, the field cannot be indexed or it already has a
index defined.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public boolean hasIndex(String fieldName)
fieldName
- existing field name to check.true
if field is indexed, false
otherwise.IllegalArgumentException
- if field name doesn't exist.Index
public abstract RealmObjectSchema removeIndex(String fieldName)
@Index
annotation on the field.fieldName
- field to remove index from.IllegalArgumentException
- if field name doesn't exist or the field doesn't have an index.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public abstract RealmObjectSchema addPrimaryKey(String fieldName)
PrimaryKey
annotation on the field. Further, this implicitly adds Index
annotation to the field
as well.fieldName
- field to set as primary key.IllegalArgumentException
- if field name doesn't exist, the field cannot be a primary key or it already
has a primary key defined.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public abstract RealmObjectSchema removePrimaryKey()
PrimaryKey
annotation from the class. Further, this implicitly removes Index
annotation from
the field as well.IllegalArgumentException
- if the class doesn't have a primary key defined.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public abstract RealmObjectSchema setRequired(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.IllegalArgumentException
- if the field name doesn't exist, cannot have the Required
annotation or
the field already have been set as required.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.Required
public abstract RealmObjectSchema setNullable(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.IllegalArgumentException
- if the field name doesn't exist, or cannot be set as nullable.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public boolean isRequired(String fieldName)
null
values.fieldName
- field to check.true
if it is required, false
otherwise.IllegalArgumentException
- if field name doesn't exist.setRequired(String, boolean)
public boolean isNullable(String fieldName)
null
values.fieldName
- field to check.true
if it is required, false
otherwise.IllegalArgumentException
- if field name doesn't exist.setNullable(String, boolean)
public boolean isPrimaryKey(String fieldName)
fieldName
- field to check.true
if it is the primary key field, false
otherwise.IllegalArgumentException
- if field name doesn't exist.addPrimaryKey(String)
public boolean hasPrimaryKey()
true
if a primary key is defined, false
otherwise.PrimaryKey
public String getPrimaryKey()
IllegalStateException
- if the class doesn't have a primary key defined.public Set<String> getFieldNames()
public abstract RealmObjectSchema transform(RealmObjectSchema.Function function)
DynamicRealmObject
.function
- transformation function.UnsupportedOperationException
- if this RealmObjectSchema
is immutable.public RealmFieldType getFieldType(String fieldName)
fieldName
- name of the target field.