io.realm.annotations
Esta enumeración define las posibles formas en que los nombres de clases y campos se pueden asignar desde lo que se usa en Java al nombre usado internamente en el archivo Realm. Ejemplos donde esto es útil:
To support two model classes with the same simple name but in different packages.
Para facilitar el trabajo con esquemas multiplataforma, ya que las convenciones de nomenclatura son distintas.
To use a Java class name that is longer than the 57 character limit enforced by Realm.
To change a field name in Java without forcing app users through a migration process.
Depending on where the policy is applied, it will have slightly different semantics:
Si se aplica a RealmModule.classNamingPolicy todas las clases que formen parte de ese módulo se verán afectadas. Si una clase forma parte de varios módulos, se debe aplicar la misma política de nomenclatura a ambos módulos; de lo contrario, se generará un error.
Si se aplica a RealmModule.fieldNamingPolicy todos los campos persistibles en todas las clases que forman parte de este módulo se verán afectados.
Si se aplica a RealmClass.fieldNamingPolicy, todos los campos de esa clase se verán afectados. Esto anulará cualquier política de nombres de campos especificada en un módulo.
An example of this:
public class Person implements RealmModel { // is converted to "__person" internally public string firstName; // Is converted to "first_name" internally }
Choosing an internal name that differs from the name used in the Java model classes has the following implications:
Consultas sobre
DynamicRealmDebe usar el nombre interno. Las consultas en instancias normales deRealmdeben seguir usando el nombre tal como está definido en la clase Java.Migrations must use the internal name when creating classes and fields.
Los errores de esquema notificados utilizarán los nombres internos.
When automatically converting Java variable names, each variable name is normalized by splitting it into a list of words that are then joined using the rules of the target format. The following heuristics are used for determining what constitutes a "word".
Anytime a
_or$is encountered. Examples are "_FirstName", "_First_Name" and "$First$Name" which all becomes "First" and "Name".Cada vez que cambie de un carácter en minúscula a uno en mayúscula según lo identificado por Character.isUpperCase(int) y Character.isLowerCase(int) . El ejemplo es "FirstName", que se convierte en "First" y "Name".
Anytime you switch from more than one uppercase character to a lower case one. The last upper case letter is assumed to be part of the next word. This is identified by using Character.isUpperCase(int) and Character.isLowerCase(int) . Example is "FIRSTName" which becomes "FIRST" and "Name.
Some characters like emojiis are neither uppercase nor lowercase characters, so they will be part of the current word. Examples are "my😁" and "MY😁" which are both treated as one word.
Hungarian notation, i.e. variable names starting with lowercase "m" followed by uppercase letter is stripped and not considered part of any word. Example is "mFirstName" and "mFIRSTName" which becomes "First" and "Name.
Note that changing the internal name does NOT affect importing data from JSON. The JSON data must still follow the names as defined in the Realm Java class.
Cuando se trata de analizar JSON con librerías estándar como Moshi, GSON o Jackson, es importante recordar que estas librerías definen la transformación de JSON a Java, mientras que establecer nombres internos de Realm define la transformación de Java al archivo Realm.
This means that if you want to import data into Realm from JSON using these libraries you still need to provide the annotations from both the JSON parser library and Realm.
Using Moshi, it would look something like this:
public class Person extends RealmObject { // Name used in JSON input. // Name used internally in the Realm file. public string firstName; // name used in Java }
Enum Constant Summary
Enum Constant and Description |
|---|
The name in the Java model class is converted to camelCase, i.e. |
El nombre en la clase del modelo Java se usa tal cual internamente. |
El nombre en la clase del modelo Java se convierte a minúsculas y cada palabra está separada por |
No policy is applied. |
El nombre en la clase de modelo de Java se convierte a PascalCase, es decir. |
Resumen del método
Modificador y Tipo | Método y descripción |
|---|---|
public static RealmNamingPolicy | |
public static RealmNamingPolicy | values () |
Inherited Methods
Methods inherited from class java.lang.Object :
getClass,hashCode,equals,clone,toString,notify,notifyAll,wait,wait,wait,finalizeMétodos heredados de la clase java.lang.Enum :
name,ordinal,toString,equals,hashCode,clone,compareTo,getDeclaringClass,valueOf,finalize
Detalle de constante de enumeración
CAMEL_CASE
public static final RealmNamingPolicy
The name in the Java model class is converted to camelCase, i.e. all words are joined together with the first letter in the first word lower cased, and the first letter of all subsequent words upper cased. This is the standard naming schema in Java, Kotlin, Swift and JavaScript.Examples: "firstName", "FirstName", "mFirstName", "FIRST_NAME", "First$Name" all becomes "firstName".
IDENTITY
public static final RealmNamingPolicy
El nombre en la clase del modelo Java se usa tal cual internamente.
LOWER_CASE_WITH_UNDERSCORES
public static final RealmNamingPolicy
El nombre de la clase del modelo Java se convierte a minúsculas, con cada palabra separada por _ . Este es el esquema de nombres predeterminado en C++.
Examples: "firstName", "FirstName", "mFirstName", "FIRST_NAME", "First$Name" all becomes "first_name".
NO_POLICY
public static final RealmNamingPolicy
No se aplica ninguna política. Esta política no sustituirá ninguna política establecida en un elemento padre, por ejemplo, si se establece en RealmClass.fieldNamingPolicy , la política del módulo seguirá aplicándose a los nombres de campo.
If two modules disagree on the policy and one of them is NO_POLICY , the other will be chosen without an error being thrown.
This policy is the default.
PASCAL_CASE
public static final RealmNamingPolicy
The name in the Java model class is converted to PascalCase, i.e. all words are joined together with the first letter of all words upper cased. This is the default naming scheme in .NET.Examples: "firstName", "FirstName", "mFirstName", "FIRST_NAME", "First$Name" all becomes "FirstName".
Detalle del método
valueOf
values
public static RealmNamingPolicy values () |
|---|