public class RealmObjectSchema extends 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(String fieldName,
Class<?> fieldType,
FieldAttribute... attributes)
Adds a new simple field to the RealmObject class.
|
RealmObjectSchema |
addIndex(String fieldName)
Adds an index to a given field.
|
RealmObjectSchema |
addPrimaryKey(String fieldName)
Adds a primary key to a given field.
|
RealmObjectSchema |
addRealmListField(String fieldName,
RealmObjectSchema objectSchema)
Adds a new field that references a
RealmList . |
RealmObjectSchema |
addRealmObjectField(String fieldName,
RealmObjectSchema objectSchema)
Adds a new field that references another
RealmObject . |
void |
close()
Closes/frees native resource.
|
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. |
RealmObjectSchema |
removeField(String fieldName)
Removes a field from the class.
|
RealmObjectSchema |
removeIndex(String fieldName)
Removes an index from a given field.
|
RealmObjectSchema |
removePrimaryKey()
Removes the primary key from this class.
|
RealmObjectSchema |
renameField(String currentFieldName,
String newFieldName)
Renames a field from one name to another.
|
RealmObjectSchema |
setClassName(String className)
Sets a new name for this RealmObject class.
|
RealmObjectSchema |
setNullable(String fieldName,
boolean nullable)
Sets a field to be nullable i.e., it should be able to hold
null values. |
RealmObjectSchema |
setRequired(String fieldName,
boolean required)
Sets a field to be required i.e., it is not allowed to hold
null values. |
RealmObjectSchema |
transform(RealmObjectSchema.Function function)
Runs a transformation function on each RealmObject instance of the current class.
|
public void close()
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 RealmObjectSchema setClassName(String className)
table
has a primary key, this will transfer the primary key for the new class name.className
- the new name for this class.IllegalArgumentException
- if className is null
or an empty string, or its length exceeds 56 characters.RealmSchema.rename(String, String)
public 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 name
already exists.public 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.public 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.public RealmObjectSchema removeField(String fieldName)
fieldName
- field name to remove.IllegalArgumentException
- if field name doesn't exist.public 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.public boolean hasField(String fieldName)
fieldName
- field name to test.true
if the field exists, false
otherwise.public 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.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 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.public 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.public 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.public 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.Required
public 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.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 RealmObjectSchema transform(RealmObjectSchema.Function function)
DynamicRealmObject
.public RealmFieldType getFieldType(String fieldName)