Package io.realm
Class RealmSchema
- java.lang.Object
-
- io.realm.RealmSchema
-
public abstract class RealmSchema extends Object
Class for interacting with the Realm schema. This makes it possible to inspect, add, delete and change the classes in the Realm.Realm.getSchema()
returns an immutableRealmSchema
which can only be used for inspecting. UseDynamicRealm.getSchema()
to get a mutable schema.All changes must happen inside a write transaction for the particular Realm.
- See Also:
RealmMigration
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
contains(String className)
Checks if a given class already exists in the schema.abstract RealmObjectSchema
create(String className)
Adds a new class to the Realm.void
createKeyPathMapping()
Create the underlying keypath mapping.abstract RealmObjectSchema
createWithPrimaryKeyField(String className, String primaryKeyFieldName, Class<?> fieldType, FieldAttribute... attributes)
Adds a new class to the Realm with a primary key field defined.abstract RealmObjectSchema
get(String className)
Returns theRealmObjectSchema
for a given class.abstract Set<RealmObjectSchema>
getAll()
Returns theRealmObjectSchema
s for all RealmObject classes that can be saved in this Realm.abstract void
remove(String className)
Removes a class from the Realm.abstract RealmObjectSchema
rename(String oldClassName, String newClassName)
Renames a class already in the Realm.
-
-
-
Method Detail
-
get
@Nullable public abstract RealmObjectSchema get(String className)
Returns theRealmObjectSchema
for a given class. If thisRealmSchema
is immutable, an immutableRealmObjectSchema
will be returned. Otherwise, it returns an mutableRealmObjectSchema
.- Parameters:
className
- name of the class- Returns:
- schema object for that class or
null
if the class doesn't exists.
-
getAll
public abstract Set<RealmObjectSchema> getAll()
Returns theRealmObjectSchema
s for all RealmObject classes that can be saved in this Realm. If thisRealmSchema
is immutable, an immutableRealmObjectSchema
set will be returned. Otherwise, it returns an mutableRealmObjectSchema
set.- Returns:
- the set of all classes in this Realm or no RealmObject classes can be saved in the Realm.
-
create
public abstract RealmObjectSchema create(String className)
Adds a new class to the Realm.- Parameters:
className
- name of the class.- Returns:
- a Realm schema object for that class.
- Throws:
UnsupportedOperationException
- if thisRealmSchema
is immutable.
-
createWithPrimaryKeyField
public abstract RealmObjectSchema createWithPrimaryKeyField(String className, String primaryKeyFieldName, Class<?> fieldType, FieldAttribute... attributes)
Adds a new class to the Realm with a primary key field defined.- Parameters:
className
- name of the class.primaryKeyFieldName
- name of the primary key field.fieldType
- type of field to add. Onlybyte
,short
,int
,long
and their boxed types or theString
is supported.attributes
- set of attributes for this field. This method implicitly addsFieldAttribute.PRIMARY_KEY
andFieldAttribute.INDEXED
attributes to the field.- Returns:
- a Realm schema object for that class.
- Throws:
UnsupportedOperationException
- if thisRealmSchema
is immutable.
-
remove
public abstract void remove(String className)
Removes a class from the Realm. All data will be removed. Removing a class while other classes point to it will throw anIllegalStateException
. Removes those classes or fields first.- Parameters:
className
- name of the class to remove.- Throws:
UnsupportedOperationException
- if thisRealmSchema
is immutable or of a synced Realm.
-
rename
public abstract RealmObjectSchema rename(String oldClassName, String newClassName)
Renames a class already in the Realm.- Parameters:
oldClassName
- old class name.newClassName
- new class name.- Returns:
- a schema object for renamed class.
- Throws:
UnsupportedOperationException
- if thisRealmSchema
is immutable or of a synced Realm.
-
contains
public boolean contains(String className)
Checks if a given class already exists in the schema.- Parameters:
className
- class name to check.- Returns:
true
if the class already exists.false
otherwise.
-
createKeyPathMapping
public void createKeyPathMapping()
Create the underlying keypath mapping. Should only be called by typed Realms.
-
-