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.Builder
and 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 class
RealmConfiguration.Builder
RealmConfiguration.Builder used to construct instances of a RealmConfiguration in a fluent manner.
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_REALM_NAME
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
String
getAssetFilePath()
Returns the path to the Realm asset file.CompactOnLaunchCallback
getCompactOnLaunchCallback()
Returns a callback to determine if the Realm file should be compacted before being returned to the user.io.realm.internal.OsRealmConfig.Durability
getDurability()
byte[]
getEncryptionKey()
FlowFactory
getFlowFactory()
Returns theFlowFactory
that is used to create Kotlin Flows from Realm objects.long
getMaxNumberOfActiveVersions()
RealmMigration
getMigration()
String
getPath()
Returns the absolute path to where the Realm file will be saved.File
getRealmDirectory()
String
getRealmFileName()
Set<Class<? extends RealmModel>>
getRealmObjectClasses()
Returns the unmodifiableSet
of model classes that make up the schema for this Realm.RxObservableFactory
getRxFactory()
Returns theRxObservableFactory
that is used to create Rx Observables from Realm objects.long
getSchemaVersion()
boolean
hasAssetFile()
Indicates if an asset file has been configured for this configuration.int
hashCode()
boolean
isAllowQueriesOnUiThread()
Returns whether aRealmQuery
is allowed to be launched from the UI thread.boolean
isAllowWritesOnUiThread()
Returns whether calls toRealm.executeTransaction(io.realm.Realm.Transaction)
can be done on the UI thread.boolean
isReadOnly()
Returns whether this Realm is read-only or not.boolean
isRecoveryConfiguration()
boolean
shouldDeleteRealmIfMigrationNeeded()
String
toString()
-
-
-
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:
true
if there is asset file,false
otherwise.
-
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
null
if 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 unmodifiableSet
of model classes that make up the schema for this Realm.- Returns:
- unmodifiable
Set
of 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 theRxObservableFactory
that 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 theFlowFactory
that 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 anIllegalStateException
ifBaseRealm.beginTransaction()
is called on it.- Returns:
true
if this Realm is read only,false
if not.
-
isRecoveryConfiguration
public boolean isRecoveryConfiguration()
- Returns:
true
if 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 aRealmQuery
is 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.
-
-