public static final class SyncConfiguration.Builder extends Object
Constructor and Description |
---|
Builder(SyncUser user,
String uri)
Creates an instance of the Builder for the SyncConfiguration.
|
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 |
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 |
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()
Setting this will open a partially synchronized Realm.
|
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 |
waitForInitialRemoteData() |
public Builder(SyncUser user, String uri)
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()
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.
public SyncConfiguration.Builder partialRealm()
SyncConfiguration.isPartialRealm()
public SyncConfiguration build()
SyncConfiguration
.IllegalStateException
- if the configuration parameters are invalid or inconsistent.