RxDataStoreBuilder


public final class RxDataStoreBuilder<T extends Object>


Builder class for an RxDataStore that works on a single process.

Summary

Public constructors

<T extends Object> RxDataStoreBuilder(
    @NonNull Callable<@NonNull File> produceFile,
    @NonNull Serializer<@NonNull T> serializer
)

Create a RxDataStoreBuilder with the callable which returns the File that DataStore acts on.

<T extends Object> RxDataStoreBuilder(
    @NonNull Context context,
    @NonNull String fileName,
    @NonNull Serializer<@NonNull T> serializer
)

Create a RxDataStoreBuilder with the Context and name from which to derive the DataStore file.

Public methods

final @NonNull RxDataStoreBuilder<@NonNull T>

Add a DataMigration to the Datastore.

final @NonNull RxDataStoreBuilder<@NonNull T>

Add an RxDataMigration to the DataStore.

final @NonNull RxDataStore<@NonNull T>

Build the DataStore.

final @NonNull RxDataStoreBuilder<@NonNull T>

Sets the corruption handler to install into the DataStore.

final @NonNull RxDataStoreBuilder<@NonNull T>

Set the Scheduler on which to perform IO and transform operations.

Public constructors

RxDataStoreBuilder

public <T extends Object> RxDataStoreBuilder(
    @NonNull Callable<@NonNull File> produceFile,
    @NonNull Serializer<@NonNull T> serializer
)

Create a RxDataStoreBuilder with the callable which returns the File that DataStore acts on. The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.

Parameters
@NonNull Callable<@NonNull File> produceFile

Function which returns the file that the new DataStore will act on. The function must return the same path every time. No two instances of DataStore should act on the same file at the same time.

@NonNull Serializer<@NonNull T> serializer

the serializer for the type that this DataStore acts on.

RxDataStoreBuilder

public <T extends Object> RxDataStoreBuilder(
    @NonNull Context context,
    @NonNull String fileName,
    @NonNull Serializer<@NonNull T> serializer
)

Create a RxDataStoreBuilder with the Context and name from which to derive the DataStore file. The file is generated by File(this.filesDir, "datastore/$fileName"). The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.

Parameters
@NonNull Context context

the context from which we retrieve files directory.

@NonNull String fileName

the filename relative to Context.applicationContext.filesDir that DataStore acts on. The File is obtained from dataStoreFile. It is created in the "/datastore" subdirectory.

@NonNull Serializer<@NonNull T> serializer

the serializer for the type that this DataStore acts on.

Public methods

addDataMigration

Added in 1.0.0
public final @NonNull RxDataStoreBuilder<@NonNull T> addDataMigration(@NonNull DataMigration<@NonNull T> dataMigration)

Add a DataMigration to the Datastore. Migrations are run in the order they are added.

Parameters
@NonNull DataMigration<@NonNull T> dataMigration

the migration to add

Returns
@NonNull RxDataStoreBuilder<@NonNull T>

this

addRxDataMigration

Added in 1.0.0
public final @NonNull RxDataStoreBuilder<@NonNull T> addRxDataMigration(@NonNull RxDataMigration<@NonNull T> rxDataMigration)

Add an RxDataMigration to the DataStore. Migrations are run in the order they are added.

Parameters
@NonNull RxDataMigration<@NonNull T> rxDataMigration

the migration to add.

Returns
@NonNull RxDataStoreBuilder<@NonNull T>

this

build

Added in 1.0.0
public final @NonNull RxDataStore<@NonNull T> build()

Build the DataStore.

Returns
@NonNull RxDataStore<@NonNull T>

the DataStore with the provided parameters

setCorruptionHandler

Added in 1.0.0
public final @NonNull RxDataStoreBuilder<@NonNull T> setCorruptionHandler(
    @NonNull ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler
)

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.

Parameters
@NonNull ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler
Returns
@NonNull RxDataStoreBuilder<@NonNull T>

this

setIoScheduler

Added in 1.0.0
public final @NonNull RxDataStoreBuilder<@NonNull T> setIoScheduler(@NonNull Scheduler ioScheduler)

Set the Scheduler on which to perform IO and transform operations. This is converted into a CoroutineDispatcher before being added to DataStore.

This parameter is optional and defaults to Schedulers.io().

Parameters
@NonNull Scheduler ioScheduler

the scheduler on which IO and transform operations are run

Returns
@NonNull RxDataStoreBuilder<@NonNull T>

this