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 immutableRealmSchemawhich 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 booleancontains(String className)Checks if a given class already exists in the schema.abstract RealmObjectSchemacreate(String className)Adds a new class to the Realm.voidcreateKeyPathMapping()Create the underlying keypath mapping.abstract RealmObjectSchemacreateWithPrimaryKeyField(String className, String primaryKeyFieldName, Class<?> fieldType, FieldAttribute... attributes)Adds a new class to the Realm with a primary key field defined.abstract RealmObjectSchemaget(String className)Returns theRealmObjectSchemafor a given class.abstract Set<RealmObjectSchema>getAll()Returns theRealmObjectSchemas for all RealmObject classes that can be saved in this Realm.abstract voidremove(String className)Removes a class from the Realm.abstract RealmObjectSchemarename(String oldClassName, String newClassName)Renames a class already in the Realm.
-
-
-
Method Detail
-
get
@Nullable public abstract RealmObjectSchema get(String className)
Returns theRealmObjectSchemafor a given class. If thisRealmSchemais immutable, an immutableRealmObjectSchemawill be returned. Otherwise, it returns a mutableRealmObjectSchema.- Parameters:
className- name of the class- Returns:
- schema object for that class or
nullif the class doesn't exists.
-
getAll
public abstract Set<RealmObjectSchema> getAll()
Returns theRealmObjectSchemas for all RealmObject classes that can be saved in this Realm. If thisRealmSchemais immutable, an immutableRealmObjectSchemaset will be returned. Otherwise, it returns an mutableRealmObjectSchemaset.- 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 thisRealmSchemais 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,longand their boxed types or theStringis supported.attributes- set of attributes for this field. This method implicitly addsFieldAttribute.PRIMARY_KEYandFieldAttribute.INDEXEDattributes to the field.- Returns:
- a Realm schema object for that class.
- Throws:
UnsupportedOperationException- if thisRealmSchemais 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 thisRealmSchemais 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 thisRealmSchemais 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:
trueif the class already exists.falseotherwise.
-
createKeyPathMapping
public void createKeyPathMapping()
Create the underlying keypath mapping. Should only be called by typed Realms.
-
-