Class RealmConfiguration
- java.lang.Object
-
- io.realm.RealmConfiguration
-
- Direct Known Subclasses:
SyncConfiguration
public class RealmConfiguration extends Object
A RealmConfiguration is used to setup a specific Realm instance.Instances of a RealmConfiguration can only created by using the
RealmConfiguration.Builderand calling itsRealmConfiguration.Builder.build()method.A commonly used RealmConfiguration can easily be accessed by first saving it as
Realm.setDefaultConfiguration(RealmConfiguration)and then usingRealm.getDefaultInstance().A minimal configuration can be created using:
RealmConfiguration config = new RealmConfiguration.Builder().build()This will create a RealmConfiguration with the following properties.
- Realm file is called "default.realm"
- It is saved in Context.getFilesDir()
- It has its schema version set to 0.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRealmConfiguration.BuilderRealmConfiguration.Builder used to construct instances of a RealmConfiguration in a fluent manner.
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_REALM_NAME
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)StringgetAssetFilePath()Returns the path to the Realm asset file.CompactOnLaunchCallbackgetCompactOnLaunchCallback()Returns a callback to determine if the Realm file should be compacted before being returned to the user.io.realm.internal.OsRealmConfig.DurabilitygetDurability()byte[]getEncryptionKey()FlowFactorygetFlowFactory()Returns theFlowFactorythat is used to create Kotlin Flows from Realm objects.longgetMaxNumberOfActiveVersions()RealmMigrationgetMigration()StringgetPath()Returns the absolute path to where the Realm file will be saved.FilegetRealmDirectory()StringgetRealmFileName()Set<Class<? extends RealmModel>>getRealmObjectClasses()Returns the unmodifiableSetof model classes that make up the schema for this Realm.RxObservableFactorygetRxFactory()Returns theRxObservableFactorythat is used to create Rx Observables from Realm objects.longgetSchemaVersion()booleanhasAssetFile()Indicates if an asset file has been configured for this configuration.inthashCode()booleanisAllowQueriesOnUiThread()Returns whether aRealmQueryis allowed to be launched from the UI thread.booleanisAllowWritesOnUiThread()Returns whether calls toRealm.executeTransaction(io.realm.Realm.Transaction)can be done on the UI thread.booleanisReadOnly()Returns whether this Realm is read-only or not.booleanisRecoveryConfiguration()booleanshouldDeleteRealmIfMigrationNeeded()StringtoString()
-
-
-
Field Detail
-
DEFAULT_REALM_NAME
public static final String DEFAULT_REALM_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRealmDirectory
public File getRealmDirectory()
-
getRealmFileName
public String getRealmFileName()
-
getEncryptionKey
public byte[] getEncryptionKey()
-
getSchemaVersion
public long getSchemaVersion()
-
getMigration
public RealmMigration getMigration()
-
shouldDeleteRealmIfMigrationNeeded
public boolean shouldDeleteRealmIfMigrationNeeded()
-
getDurability
public io.realm.internal.OsRealmConfig.Durability getDurability()
-
hasAssetFile
public boolean hasAssetFile()
Indicates if an asset file has been configured for this configuration.- Returns:
trueif there is asset file,falseotherwise.
-
getAssetFilePath
@Nullable public String getAssetFilePath()
Returns the path to the Realm asset file.- Returns:
- path to the asset file relative to the asset directory or
nullif not asset file was specified.
-
getCompactOnLaunchCallback
public CompactOnLaunchCallback getCompactOnLaunchCallback()
Returns a callback to determine if the Realm file should be compacted before being returned to the user.- Returns:
- 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 total bytes used by data in the file.
-
getRealmObjectClasses
public Set<Class<? extends RealmModel>> getRealmObjectClasses()
Returns the unmodifiableSetof model classes that make up the schema for this Realm.- Returns:
- unmodifiable
Setof model classes.
-
getPath
public String getPath()
Returns the absolute path to where the Realm file will be saved.- Returns:
- the absolute path to the Realm file defined by this configuration.
-
getRxFactory
public RxObservableFactory getRxFactory()
Returns theRxObservableFactorythat is used to create Rx Observables from Realm objects.- Returns:
- the factory instance used to create Rx Observables.
- Throws:
UnsupportedOperationException- if the required RxJava framework is not on the classpath.
-
getFlowFactory
public FlowFactory getFlowFactory()
Returns theFlowFactorythat is used to create Kotlin Flows from Realm objects.- Returns:
- the factory instance used to create Flows.
- Throws:
UnsupportedOperationException- if the required coroutines framework is not on the classpath.
-
isReadOnly
public boolean isReadOnly()
Returns whether this Realm is read-only or not. Read-only Realms cannot be modified and will throw anIllegalStateExceptionifBaseRealm.beginTransaction()is called on it.- Returns:
trueif this Realm is read only,falseif not.
-
isRecoveryConfiguration
public boolean isRecoveryConfiguration()
- Returns:
trueif this configuration is intended to open a backup Realm (as a result of a client reset).
-
getMaxNumberOfActiveVersions
public long getMaxNumberOfActiveVersions()
- Returns:
- the maximum number of active versions allowed before an exception is thrown.
-
isAllowWritesOnUiThread
public boolean isAllowWritesOnUiThread()
Returns whether calls toRealm.executeTransaction(io.realm.Realm.Transaction)can be done on the UI thread.Note: Realm does not allow blocking transactions to be run on the main thread unless users explicitly opt in with
RealmConfiguration.Builder.allowWritesOnUiThread(boolean)or its Realm Sync builder counterpart.- Returns:
- whether or not write operations are allowed to be run from the UI thread.
-
isAllowQueriesOnUiThread
public boolean isAllowQueriesOnUiThread()
Returns whether aRealmQueryis allowed to be launched from the UI thread.By default Realm allows queries on the main thread. To disallow this users have to explicitly opt in with
RealmConfiguration.Builder.allowQueriesOnUiThread(boolean)or its Realm Sync builder counterpart.- Returns:
- whether or not queries are allowed to be run from the UI thread.
-
-