Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
io.realm

Clase RealmConfiguration.Builder

java.lang.Object
io.realm.RealmConfiguration.Builder

Enclosing class:

RealmConfiguration

RealmConfiguration.Builder used to construct instances of a RealmConfiguration in a fluent manner.

Constructor and Description

Crea una instancia del constructor para RealmConfiguration.

Modificador y Tipo
Método y descripción
Object module
)

FIXME: Método DEBUG visible temporalmente.

boolean allowQueriesOnUiThread
)

Configura si un RealmQuery puede iniciarse desde el hilo Interfaz de Usuario o no.

boolean allowWritesOnUiThread
)

Sets whether or not calls to Realm.executeTransaction are allowed from the UI thread.

String assetFile
)

Copies the Realm file from the given asset file path.

Crea la RealmConfiguration basada en los parámetros del generador.

Establece esto para determinar si el archivo Realm debe compactarse antes de devolverlo al usuario.

Si estableces esta opción, Realm compactará el archivo Realm si este ha crecido demasiado y se puede recuperar una cantidad significativa de espacio.

Establecer esto cambiará el comportamiento de manejo de las excepciones de migración.

File directory
)

Specifies the directory where the Realm file will be saved.

byte[] key
)

Sets the 64 byte key used to encrypt and decrypt the Realm file.

Establece la FlowFactory utilizada para crear flujos de corrutinas a partir de objetos Realm.

Establecer esto creará un Realm en memoria en lugar de guardarlo en el disco.

Sets the initial data in io.realm.Realm .

Establece el número máximo de versiones activas en el archivo Realm antes de que se lance una IllegalStateException al intentar guardar más datos.

Define io.realm.RealmMigration que se debe ejecutar si se requiere una migración.

Object baseModule,
java.lang.Object[] additionalModules
)

Replaces the existing module(s) with one or more RealmModule s.

String filename
)

Establece el nombre del archivo para el archivo Realm.

Configurar esto hará que el Realm se vuelva de solo lectura y todas las transacciones de escritura realizadas contra este Realm fallarán con una IllegalStateException .

Sets the RxObservableFactory used to create Rx Observables from Realm objects.

long schemaVersion
)

Establece la versión de esquema del Realm.

  • Métodos heredados de la clase java.lang.Object: getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

public Builder ()

Crea una instancia del Builder para el RealmConfiguration. Esto utilizará el propio directorio interno de la aplicación para almacenar el archivo Realm. Esto no requiere permisos adicionales. La ubicación por defecto es /data/data/<packagename>/files , pero puede cambiar según las implementaciones del proveedor de Android.

FIXME: Temporary visible DEBUG method. Will add a module unconditionally. Adds a module to already defined modules.

boolean allowQueriesOnUiThread
)

Configura si un RealmQuery puede iniciarse desde el hilo Interfaz de Usuario o no.

By default Realm allows queries on the main thread. However, by doing so your application may experience a drop of frames or even ANRs. We recommend diverting queries to non-UI threads or, alternatively, using RealmQuery.findAllAsync() or RealmQuery.findFirstAsync() .

boolean allowWritesOnUiThread
)

Sets whether or not calls to Realm.executeTransaction are allowed from the UI thread.

WARNING: Realm does not allow synchronous transactions to be run on the main thread unless users explicitly opt in with this method. We recommend diverting calls to executeTransaction to non-UI threads or, alternatively, using Realm.executeTransactionAsync .

Copia el archivo Realm desde la ruta del archivo de activo indicada. Al abrir el Realm por primera vez, en lugar de crear un archivo vacío, el archivo Realm se copiará desde el archivo de activo proporcionado y se utilizará en su lugar.

Esto no se puede combinar con deleteRealmIfMigrationNeeded() ya que hacerlo solo provocaría que se borre el archivo copiado.

ADVERTENCIA: Esto podría ser una operación prolongada y, lo ideal, es realizarla en un hilo en segundo plano.

Parámetros

  • assetFile - path to the asset database file.

Throws

Crea la RealmConfiguration basada en los parámetros del generador.

Devuelve

the created RealmConfiguration .

Sets this to determine if the Realm file should be compacted before returned to the user. It is passed the total file size (data + free space) and the bytes used by data in the file.

Parámetros

  • compactOnLaunch - a callback called when opening a Realm for the first time during the life of a process to determine if it should be compacted before being returned to the user. It is passed the total file size (data + free space) and the bytes used by data in the file.

Setting this will cause Realm to compact the Realm file if the Realm file has grown too large and a significant amount of space can be recovered. See DefaultCompactOnLaunchCallback for details.

Al configurar estos parámetros, se modifica el comportamiento de cómo se gestionan las excepciones de migración. En lugar de lanzar una io.realm.exceptions.RealmMigrationNeededException, el Realm en disco se borrará y recreará con el nuevo esquema de Realm.

This cannot be configured to have an asset file at the same time by calling assetFile(String) as the provided asset file will be deleted in migrations.

WARNING! This will result in loss of data.

Throws

Especifica el directorio donde se guardará el archivo de Realm. El valor predeterminado es context.getFilesDir() . Si el directorio no existe, se creará.

Parámetros

  • directory - the directory to save the Realm file in. Directory must be writable.

Throws

Establece la clave de 64 bytes utilizada para cifrar y descifrar el archivo Realm. Establece la clave de bytes io.realm.Realm#ENCRYPTION_KEY_LENGTH usada para cifrar y descifrar el archivo Realm.

Establece la fábrica de flujos utilizada para crear flujos de corrutinas a partir de objetos de Realm. La fábrica predeterminada es RealmFlowFactory.

Parámetros

  • factory - fábrica a utilizar.

Al configurar esto, se creará un dominio en memoria en lugar de guardarlo en el disco. Los dominios en memoria podrían seguir usando espacio en disco si la memoria es insuficiente, pero todos los archivos creados por un dominio en memoria se eliminarán al cerrarlo. Tenga en cuenta que, dado que los dominios en memoria no se almacenan en memoria, debe asegurarse de conservar al menos una referencia no cerrada al objeto del dominio en memoria con el nombre específico mientras desee que los datos perduren.

Establece los datos iniciales en io.realm.Realm. Esta transacción solo se ejecutará la primera vez al crear el archivo de base de datos o al migrar los datos si Builder.deleteRealmIfMigrationNeeded() está configurado.

Parámetros

  • transaction - transaction to execute.

Establece el número máximo de versiones activas en el archivo Realm antes de que se lance una IllegalStateException al intentar guardar más datos.

Realm is capable of concurrently handling many different versions of Realm objects. This can e.g. happen if you have a Realm open on many different threads or are freezing objects while data is being written to the file.

Under normal circumstances this is not a problem, but if the number of active versions grow too large, it will have a negative effect on the filesize on disk. Setting this parameters can therefore be used to prevent uses of Realm that can result in very large Realms.

Parámetros

  • number - the maximum number of active versions before an exception is thrown.

Tip

Sets the io.realm.RealmMigration to be run if a migration is needed. If this migration fails to upgrade the on-disc schema to the runtime schema, a io.realm.exceptions.RealmMigrationNeededException will be thrown.

Object baseModule,
java.lang.Object[] additionalModules
)

Reemplaza los módulos existentes con uno o más RealmModule. Este método reemplaza el esquema actual de este dominio con el esquema definido por los módulos proporcionados.

A reference to the default Realm module containing all Realm classes in the project (but not dependencies), can be found using Realm.getDefaultModule() . Combining the schema from the app project and a library dependency is thus done using the following code:

builder.modules(Realm.getDefaultMode(), new MyLibraryModule());

Parámetros

  • baseModule - el primer módulo de Realm (obligatorio).

  • additionalModules - los módulos adicionales de Realm

Throws

Establece el nombre del archivo para el archivo Realm.

Configurar esto hará que el Realm se vuelva de solo lectura y todas las transacciones de escritura realizadas contra este Realm fallarán con una IllegalStateException .

This in particular mean that initialData(Realm.Transaction) will not work in combination with a read only Realm and setting this will result in a IllegalStateException being thrown.

Marking a Realm as read only only applies to the Realm in this process. Other processes can still write to the Realm.

Establece la RxObservableFactory que se usa para crear Rx Observables a partir de objetos Realm. La fábrica por defecto es RealmObservableFactory .

Parámetros

  • factory - fábrica a utilizar.

long schemaVersion
)

Establece la versión del esquema del Realm. Esto debe ser igual o superior a la versión del esquema del archivo Realm existente, en caso de que haya alguno. Si la versión del esquema es más alta que la ya existente en Realm, se necesita una migración. Realm lanzará una io.realm.exceptions.RealmMigrationNeededException si no se proporciona ningún código de migración.

Volver

RealmConfiguration

En esta página