public static final class RealmConfiguration.Builder
extends java.lang.Object
Constructor and Description |
---|
Builder(android.content.Context context)
Creates an instance of the Builder for the RealmConfiguration.
|
Builder(java.io.File folder)
Creates an instance of the Builder for the RealmConfiguration.
|
Modifier and Type | Method and Description |
---|---|
RealmConfiguration.Builder |
assetFile(android.content.Context context,
java.lang.String assetFile)
Copies the Realm file from the given asset file path.
|
RealmConfiguration |
build()
Creates the RealmConfiguration based on the builder parameters.
|
RealmConfiguration.Builder |
deleteRealmIfMigrationNeeded()
Setting this will change the behavior of how migration exceptions are handled.
|
RealmConfiguration.Builder |
encryptionKey(byte[] key)
Sets the 64 bit key used to encrypt and decrypt the Realm file.
|
RealmConfiguration.Builder |
initialData(Realm.Transaction transaction)
Sets the initial data in
Realm . |
RealmConfiguration.Builder |
inMemory()
Setting this will create an in-memory Realm instead of saving it to disk.
|
RealmConfiguration.Builder |
migration(RealmMigration migration)
Sets the
RealmMigration to be run if a migration is needed. |
RealmConfiguration.Builder |
modules(java.lang.Object baseModule,
java.lang.Object... additionalModules)
Replaces the existing module(s) with one or more
RealmModule s. |
RealmConfiguration.Builder |
name(java.lang.String filename)
Sets the filename for the Realm.
|
RealmConfiguration.Builder |
rxFactory(RxObservableFactory factory)
Sets the
RxObservableFactory used to create Rx Observables from Realm objects. |
RealmConfiguration.Builder |
schemaVersion(long schemaVersion)
Sets the schema version of the Realm.
|
public Builder(java.io.File folder)
folder
- Folder to save Realm file in. Folder must be writable.java.lang.IllegalArgumentException
- if folder doesn't exists or isn't writable.public Builder(android.content.Context context)
/data/data/<packagename>/files
, but can
change depending on vendor implementations of Android.context
- Android context.public RealmConfiguration.Builder name(java.lang.String filename)
public RealmConfiguration.Builder encryptionKey(byte[] key)
public RealmConfiguration.Builder schemaVersion(long schemaVersion)
RealmMigrationNeededException
.migration(RealmMigration)
public RealmConfiguration.Builder migration(RealmMigration migration)
RealmMigration
to be run if a migration is needed. If this migration fails to
upgrade the on-disc schema to the runtime schema, a RealmMigrationNeededException
will be thrown.public RealmConfiguration.Builder deleteRealmIfMigrationNeeded()
RealmMigrationNeededException
the on-disc Realm will be cleared and recreated
with the new Realm schema.
WARNING! This will result in loss of data.public RealmConfiguration.Builder inMemory()
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.
public RealmConfiguration.Builder modules(java.lang.Object baseModule, java.lang.Object... additionalModules)
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());
baseModule
- the first Realm module (required).additionalModules
- the additional Realm modulesjava.lang.IllegalArgumentException
- if any of the modules doesn't have the RealmModule
annotation.Realm.getDefaultModule()
public RealmConfiguration.Builder rxFactory(RxObservableFactory factory)
RxObservableFactory
used to create Rx Observables from Realm objects.
The default factory is RealmObservableFactory
.factory
- factory to use.public RealmConfiguration.Builder initialData(Realm.Transaction transaction)
Realm
. This transaction will be executed only for the first time
when database file is created or while migrating the data when deleteRealmIfMigrationNeeded()
is set.transaction
- transaction to execute.public RealmConfiguration.Builder assetFile(android.content.Context context, java.lang.String assetFile)
context
- Android application context.assetFile
- path to the asset database file.public RealmConfiguration build()
RealmConfiguration
.