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:
    • 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.
        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.
        a Realm schema object for that class.
        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.
        className - name of the class to remove.
        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.
        oldClassName - old class name.
        newClassName - new class name.
        a schema object for renamed class.
        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.
        className - class name to check.
        true if the class already exists. false otherwise.
      • createKeyPathMapping

        public void createKeyPathMapping()
        Create the underlying keypath mapping. Should only be called by typed Realms.