public static 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 |
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 |
migration(RealmMigration migration)
Sets the
RealmMigration to be run if a migration is needed. |
RealmConfiguration.Builder |
name(java.lang.String filename)
Sets the filename for the Realm.
|
RealmConfiguration.Builder |
schemaVersion(int schemaVersion)
Sets the schema version of the Realm.
|
RealmConfiguration.Builder |
setModules(java.lang.Object baseModule,
java.lang.Object... additionalModules)
Replaces the existing module(s) with one or more
RealmModule s. |
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(int 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 setModules(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.setModules(Realm.getDefaultMode(), new MyLibraryModule());
baseModule
- First Realm module (required).additionalModules
- Additional Realm modulesjava.lang.IllegalArgumentException
- if any of the modules are null
or doesn't have the
RealmModule
annotation.Realm.getDefaultModule()
public RealmConfiguration build()