Package io.realm

Class 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 immutable RealmSchema which can only be used for inspecting. Use DynamicRealm.getSchema() to get a mutable schema.

    All changes must happen inside a write transaction for the particular Realm.

    See Also:
    RealmMigration
    • Method Detail

      • 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. Only byte, short, int, long and their boxed types or the String is supported.
        attributes - set of attributes for this field. This method implicitly adds FieldAttribute.PRIMARY_KEY and FieldAttribute.INDEXED attributes to the field.
        Returns:
        a Realm schema object for that class.
        Throws:
        UnsupportedOperationException - if this RealmSchema 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 an IllegalStateException. Removes those classes or fields first.
        Parameters:
        className - name of the class to remove.
        Throws:
        UnsupportedOperationException - if this RealmSchema 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 this RealmSchema 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.