Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /
io.realm

Class 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: Temporary visible DEBUG method.

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.

Sets this to determine if the Realm file should be compacted before returned to the user.

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 .

Copies the Realm file from the given asset file path.When opening the Realm for the first time, instead of creating an empty file, the Realm file will be copied from the provided asset file and used instead.

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

Specifies the directory where the Realm file will be saved. The default value is context.getFilesDir() . If the directory does not exist, it will be created.

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.

Sets the FlowFactory used to create coroutines Flows from Realm objects. The default factory is RealmFlowFactory .

Parámetros

  • factory - fábrica a utilizar.

Setting this will create an in-memory Realm instead of saving it to disk. In-memory Realms might still use disk space if memory is running low, but all files created by an in-memory Realm will be deleted when the Realm is closed.Note that because in-memory Realms are not persisted, you must be sure to hold on to at least one non-closed reference to the in-memory Realm object with the specific name as long as you want the data to last.

Sets the initial data in io.realm.Realm . This transaction will be executed only for the first time when database file is created or while migrating the data when Builder.deleteRealmIfMigrationNeeded() is set.

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
)

Replaces the existing module(s) with one or more RealmModule s. Using this method will replace the current schema for this Realm with the schema defined by the provided modules.

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