Class DynamicRealm

DynamicRealm is a dynamic variant of Realm. This means that all access to data and/or queries are
done using string based class names instead of class type references.

This is useful during migrations or when working with string-based data like CSV or XML files.

The same RealmConfiguration can be used to open a Realm file in both dynamic and typed mode, but
modifying the schema while having both a typed and dynamic version open is highly discouraged and will most likely
crash the typed Realm. During migrations only a DynamicRealm will be open.

This means that the schema is not created or validated until a Realm has been opened in typed mode. If a Realm
file is opened in dynamic mode first it will not contain any information about classes and fields, and any queries
for classes defined by the schema will fail.

Field Detail

objectContext

Method Detail

getInstance

Realm static constructor that returns a dynamic variant of the Realm instance defined by provided
RealmConfiguration. Dynamic Realms do not care about schemaVersion and schemas, so opening a
DynamicRealm will never trigger a migration.

asObservable

public <any> asObservable()

Returns an RxJava Observable that monitors changes to this Realm. It will emit the current state
when subscribed to. Items will continually be emitted as the Realm is updated -
onComplete will never be called.

If you would like the asObservable() to stop emitting items, you can instruct RxJava to
only emit only the first item by using the first() operator:

realm.asObservable().first().subscribe( ... ) // You only get the results once

Returns:

RxJava Observable that only calls onNext. It will never call onComplete or OnError.

setAutoRefresh

public void setAutoRefresh(boolean autoRefresh)

Sets the auto-refresh status of the Realm instance.

Auto-refresh is a feature that enables automatic update of the current Realm instance and all its derived objects
(RealmResults and RealmObject instances) when a commit is performed on a Realm acting on the same file in
another thread. This feature is only available if the Realm instance lives on a Looper enabled
thread.

RealmFileException - if an error happened when accessing the underlying Realm file or writing to the
destination file.

waitForChange

public boolean waitForChange()

Blocks the current thread until new changes to the Realm are available or stopWaitForChange()
is called from another thread. Once stopWaitForChange is called, all future calls to this method will
return false immediately.

Returns:

true if the Realm was updated to the latest version, false if it was
cancelled by calling stopWaitForChange.

beginTransaction

public void beginTransaction()

Starts a transaction which must be closed by BaseRealm.commitTransaction() or aborted by
BaseRealm.cancelTransaction(). Transactions are used to atomically create, update and delete objects
within a Realm.

Before beginning a transaction, the Realm instance is updated to the latest version in order to include all
changes from other threads. This update does not trigger any registered RealmChangeListener.

It is therefore recommended to query for the items that should be modified from inside the transaction. Otherwise
there is a risk that some of the results have been deleted or modified when the transaction begins.

commitTransaction

public void commitTransaction()

All changes since BaseRealm.beginTransaction() are persisted to disk and the Realm reverts back to
being read-only. An event is sent to notify all other Realm instances that a change has occurred. When the event
is received, the other Realms will update their objects and RealmResults to reflect the
changes from this commit.

cancelTransaction

public void cancelTransaction()

Reverts all writes (created, updated, or deleted objects) made in the current write transaction and end the
transaction.