io.realm.annotations
Implemented interfaces:
By default a Realm can store all classes extending RealmObject in a project. However, if you want to restrict a Realm to only contain a subset of classes or want to share them between a library project and an app project, you must use a RealmModule.A RealmModule is a collection of classes extending RealmObject that can be combined with other RealmModules to create the schema for a Realm. This makes it easier to control versioning and migration of those Realms.
Un RealmModule puede ser un módulo de biblioteca o un módulo de aplicación. La distinción se realiza mediante la configuración library = true La configuración library = true normalmente solo es relevante para los autores de bibliotecas. Consulte más detalles a continuación.
Actualmente, no es posible tener varias declaraciones de RealmModule en un solo archivo. Si tiene más de un RealmModule, deberá usar archivos Java separados para cada módulo.
Módulos y bibliotecas de Realm
El comportamiento predeterminado de Realm es crear automáticamente un RealmModule llamado DefaultRealmModule que contiene todas las clases que extienden RealmObject en un proyecto. Realm reconoce automáticamente este módulo.
This behavior is problematic when combining a library project and an app project that both uses Realm. This is because the DefaultRealmModule will be created for both the library project and the app project, which will cause the project to fail with duplicate class definition errors.
Library authors are responsible for avoiding this conflict by using explicit modules where library = true is set. This disables the generation of the DefaultRealmModule for the library project and allows the library to be included in the app project that also uses Realm. This means that library projects that uses Realm internally are required to specify a specific module using RealmConfiguration.modules() .
App developers are not required to specify any modules, as they implicitly use the DefaultRealmModule , but they now has the option of adding the library project classes to their schema using RealmConfiguration.addModule() .
Resumen de elementos opcionales
Modificador y Tipo | Optional Element and Description |
|---|---|
public booleano | Instead of adding all Realm classes manually to a module, set this boolean to true to automatically include all Realm classes in this project. |
public RealmNamingPolicy | The naming policy applied to all classes part of this module. |
public Class | Especifica las clases que amplían RealmObject y que deben formar parte de este módulo. |
public RealmNamingPolicy | La política de nomenclatura aplicada a todos los nombres de campos en todas las clases que forman parte de este módulo. |
public booleano | Configurar esto como verdadero marcará este módulo como un módulo de librería. |
Element Detail
todas las clases |
|---|
Instead of adding all Realm classes manually to a module, set this boolean to true to automatically include all Realm classes in this project. This does not include classes from other libraries which must be exposed using their own module. Setting both Por defecto:
|
Política de nombres de clase |
|---|
The naming policy applied to all classes part of this module. The default policy is RealmNamingPolicy.NO_POLICY . To define a naming policy for all fields in the classes, use fieldNamingPolicy() . It is possible to override the naming policy specified in the module in each class using the RealmClass annotation. Si una clase es parte de varios módulos, se debe aplicar la misma política de nombres a ambos módulos; de lo contrario, se generará un error. Por defecto:
|
clases |
|---|
Specifies the classes extending RealmObject that should be part of this module. Only classes in this project can be included. Classes from other libraries must be exposed using their own module. Setting both Por defecto:
|
fieldNamingPolicy |
|---|
La política de nombres se aplica a todos los nombres de campo en todas las clases de este módulo. La política predeterminada es RealmNamingPolicy.NO_POLICY. Para definir una política de nombres para los nombres de clase, utilice classNamingPolicy(). It is possible to override this naming policy using either RealmClass.fieldNamingPolicy() or RealmField.name() . Por defecto:
|
Biblioteca |
|---|
Setting this to true will mark this module as a library module. This will prevent Realm from generating the Por defecto:
|