public static final class SyncConfiguration.Builder extends Object
Constructor and Description |
---|
Builder(SyncUser user,
String uri)
Deprecated.
Use
SyncUser.createConfiguration(String) instead. |
Modifier and Type | Method and Description |
---|---|
SyncConfiguration.Builder |
addModule(Object module)
Adds a module to the already defined modules.
|
SyncConfiguration |
build()
Creates the RealmConfiguration based on the builder parameters.
|
SyncConfiguration.Builder |
clientResyncMode(ClientResyncMode mode)
Configure the behavior in case of a Client Resync.
|
SyncConfiguration.Builder |
compactOnLaunch()
Setting this will cause Realm to compact the Realm file if the Realm file has grown too large and a
significant amount of space can be recovered.
|
SyncConfiguration.Builder |
compactOnLaunch(CompactOnLaunchCallback compactOnLaunch)
Sets this to determine if the Realm file should be compacted before returned to the user.
|
SyncConfiguration.Builder |
directory(File directory)
Sets the local root directory where synchronized Realm files can be saved.
|
SyncConfiguration.Builder |
disableSSLVerification()
This will disable TLS certificate verification for the remote Realm Object Server.
|
SyncConfiguration.Builder |
encryptionKey(byte[] key)
Sets the 64 bytes key used to encrypt and decrypt the Realm file.
|
SyncConfiguration.Builder |
errorHandler(SyncSession.ErrorHandler errorHandler)
Sets the error handler used by this configuration.
|
SyncConfiguration.Builder |
fullSynchronization()
Define this Realm as a fully synchronized Realm.
|
SyncConfiguration.Builder |
initialData(Realm.Transaction transaction)
Sets the initial data in
Realm . |
SyncConfiguration.Builder |
inMemory()
Setting this will create an in-memory Realm instead of saving it to disk.
|
SyncConfiguration.Builder |
modules(Iterable<Object> modules)
Replaces the existing module(s) with one or more
RealmModule s. |
SyncConfiguration.Builder |
modules(Object baseModule,
Object... additionalModules)
Replaces the existing module(s) with one or more
RealmModule s. |
SyncConfiguration.Builder |
name(String filename)
Sets the local file name for the Realm.
|
SyncConfiguration.Builder |
partialRealm()
Deprecated.
Use
SyncUser.createConfiguration(String) instead. |
SyncConfiguration.Builder |
readOnly()
Setting this will cause the Realm to become read only and all write transactions made against this Realm will
fail with an
IllegalStateException . |
SyncConfiguration.Builder |
rxFactory(RxObservableFactory factory)
Sets the
RxObservableFactory used to create Rx Observables from Realm objects. |
SyncConfiguration.Builder |
schemaVersion(long schemaVersion)
Sets the schema version of the Realm.
|
SyncConfiguration.Builder |
trustedRootCA(String filename)
Provides the trusted root certificate(s) authority (CA) in
PEM format, that should be used to
validate the TLS connections to the Realm Object Server. |
SyncConfiguration.Builder |
urlPrefix(String urlPrefix)
The prefix that is prepended to the path in the HTTP request that initiates a sync
connection to the Realm Object Server.
|
SyncConfiguration.Builder |
waitForInitialRemoteData()
Setting this will cause the Realm to download all known changes from the server the first time a Realm is
opened.
|
SyncConfiguration.Builder |
waitForInitialRemoteData(long timeout,
TimeUnit unit)
Setting this will cause the Realm to download all known changes from the server the first time a Realm is
opened.
|
@Deprecated public Builder(SyncUser user, String uri)
SyncUser.createConfiguration(String)
instead.
Opening a synchronized Realm requires a valid user and an unique URI that identifies that Realm. In URIs,
/~/
can be used as a placeholder for a user ID in case the Realm should only be available to one
user e.g., "realm://objectserver.realm.io/~/default"
.
The URL cannot end with .realm
, .realm.lock
or .realm.management
.
The /~/
will automatically be replaced with the user ID when creating the SyncConfiguration
.
Moreover, the URI defines the local location on disk. The default location of a synchronized Realm file is
/data/data/<packageName>/files/realm-object-server/<user-id>/<last-path-segment>
, but this behavior
can be overwritten using name(String)
and directory(File)
.
Many Android devices are using FAT32 file systems. FAT32 file systems have a limitation that file names cannot be longer than 255 characters. Moreover, the entire URI should not exceed 256 characters. If file name and underlying path are too long to handle for FAT32, a shorter unique name will be generated. See also @{link https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx}.
user
- the user for this Realm. An authenticated SyncUser
is required to open any Realm managed
by a Realm Object Server.uri
- URI identifying the Realm. If only a path like /~/default
is given, the configuration will
assume the file is located on the same server returned by SyncUser.getAuthenticationUrl()
.SyncUser.isValid()
public SyncConfiguration.Builder name(String filename)
filename
- name of the local file on disk.IllegalArgumentException
- if file name is null
or empty.public SyncConfiguration.Builder directory(File directory)
Synchronized Realms will not be saved directly in the provided directory, but instead in a subfolder that matches the path defined by Realm URI. As Realm server URIs are unique this means that multiple users can save their Realms on disk without the risk of them overwriting each other files.
The default location is context.getFilesDir()
.
directory
- directory on disk where the Realm file can be saved.IllegalArgumentException
- if the directory is not valid.public SyncConfiguration.Builder encryptionKey(byte[] key)
key
- the encryption key.IllegalArgumentException
- if key is invalid.public SyncConfiguration.Builder schemaVersion(long schemaVersion)
Synced Realms only support additive schema changes which can be applied without requiring a manual
migration. The schema version will only be used as an indication to the underlying storage layer to remove
or add indexes. These will be recalculated if the provided schema version differ from the version in the
Realm file.
WARNING: There is no guarantee that the value inserted here is the same returned by BaseRealm.getVersion()
.
Due to the nature of synced Realms, the value can both be higher and lower.
schemaVersion
connected to the server for
the first time after this schemaVersion was used.
schemaVersion
connected to the server after
this Realm was created.
schemaVersion
- the schema version.IllegalArgumentException
- if schema version is invalid.public SyncConfiguration.Builder modules(Object baseModule, 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 modulesIllegalArgumentException
- if any of the modules don't have the RealmModule
annotation.Realm.getDefaultModule()
public SyncConfiguration.Builder modules(Iterable<Object> modules)
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());
modules
- list of modules tthe first Realm module (required).IllegalArgumentException
- if any of the modules don't have the RealmModule
annotation.Realm.getDefaultModule()
public SyncConfiguration.Builder addModule(Object module)
public SyncConfiguration.Builder rxFactory(RxObservableFactory factory)
RxObservableFactory
used to create Rx Observables from Realm objects.
The default factory is RealmObservableFactory
.factory
- factory to use.public SyncConfiguration.Builder initialData(Realm.Transaction transaction)
Realm
. This transaction will be executed only the first time
the Realm file is opened (created) or while migrating the data if
RealmConfiguration.Builder.deleteRealmIfMigrationNeeded()
is set.transaction
- transaction to execute.public SyncConfiguration.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 SyncConfiguration.Builder errorHandler(SyncSession.ErrorHandler errorHandler)
SyncManager.setDefaultSessionErrorHandler(SyncSession.ErrorHandler)
.
Only errors not handled by the defined SyncPolicy
will be reported to this error handler.
errorHandler
- error handler used to report back errors when communicating with the Realm Object Server.IllegalArgumentException
- if null
is given as an error handler.public SyncConfiguration.Builder trustedRootCA(String filename)
PEM
format, that should be used to
validate the TLS connections to the Realm Object Server.
The file should be stored under assets
, it will be copied at runtime into the internal storage.
Note: This is similar to passing the parameter CAfile
to SSL_CTX_load_verify_locations
,
Therefore it is recommended to include only the root CA you trust, and not the entire list of root CA
as this file will be loaded at runtime.
It is your responsibility to download and verify the correct PEM
for the root CA you trust.
An existing list by Mozilla exist that could be used https://mozillacaprogram.secure.force.com/CA/IncludedCACertificateReportPEMCSV
filename
- the path under assets
to the root CA.public SyncConfiguration.Builder disableSSLVerification()
This might be useful in non-production environments where you use a self-signed certificate for testing.
public SyncConfiguration.Builder waitForInitialRemoteData()
Since downloading all changes can be an lengthy operation that might block the UI thread, Realms with this
setting enabled should only be opened on background threads or with
Realm.getInstanceAsync(RealmConfiguration, Realm.Callback)
on the UI thread.
This check is only enforced the first time a Realm is created. If you otherwise want to make sure a Realm
has the latest changes, use SyncSession.downloadAllServerChanges()
.
public SyncConfiguration.Builder waitForInitialRemoteData(long timeout, TimeUnit unit)
Since downloading all changes can be an lengthy operation that might block the UI thread, Realms with this
setting enabled should only be opened on background threads or with
Realm.getInstanceAsync(RealmConfiguration, Realm.Callback)
on the UI thread.
This check is only enforced the first time a Realm is created. If you otherwise want to make sure a Realm
has the latest changes, use SyncSession.downloadAllServerChanges()
.
timeout
- how long to wait for the download to complete before an DownloadingRealmInterruptedException
is thrown.unit
- the unit of time used to define the timeout.public SyncConfiguration.Builder readOnly()
IllegalStateException
.
This in particular mean that initialData(Realm.Transaction)
will not work in combination with a
read only Realm and setting this will result in a IllegalStateException
being thrown.
@Deprecated public SyncConfiguration.Builder partialRealm()
SyncUser.createConfiguration(String)
instead.SyncConfiguration.isPartialRealm()
public SyncConfiguration.Builder fullSynchronization()
Full synchronization, unlike the default query-based synchronization, will transparently synchronize the entire Realm without needing to query for the data. This option is useful if the serverside Realm is small and all the data in the Realm should be available to the user.
public SyncConfiguration.Builder compactOnLaunch()
DefaultCompactOnLaunchCallback
for details.public SyncConfiguration.Builder compactOnLaunch(CompactOnLaunchCallback compactOnLaunch)
compactOnLaunch
- 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 bytes used by data in the file.public SyncConfiguration.Builder urlPrefix(String urlPrefix)
/realm-sync
path is used.urlPrefix
- The prefix to append to the sync connection url.public SyncConfiguration.Builder clientResyncMode(ClientResyncMode mode)
The default mode is ClientResyncMode.RECOVER_LOCAL_REALM
.
mode
- what should happen when a Client Resync happensfor more information about what a Client Resync is.
public SyncConfiguration build()
SyncConfiguration
.IllegalStateException
- if the configuration parameters are invalid or inconsistent.