GuavaDataStore.Builder


class GuavaDataStore.Builder<T : Any>


Builder class for a GuavaDataStore that works on a single process.

Summary

Public constructors

<T : Any> Builder(serializer: Serializer<T>, produceFile: Callable<File>)
<T : Any> Builder(
    context: Context,
    fileName: String,
    serializer: Serializer<T>
)

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

Public functions

GuavaDataStore.Builder<T>
addDataMigration(dataMigration: DataMigration<T>)

Add a DataMigration to the Datastore.

GuavaDataStore<T>

Build the DataStore.

GuavaDataStore.Builder<T>
setCorruptionHandler(
    corruptionHandler: ReplaceFileCorruptionHandler<T>
)

Sets the corruption handler to install into the DataStore.

GuavaDataStore.Builder<T>
setExecutor(executor: Executor)

Sets the Executor used by the DataStore.

Public constructors

Builder

<T : Any> Builder(serializer: Serializer<T>, produceFile: Callable<File>)

Builder

<T : Any> Builder(
    context: Context,
    fileName: String,
    serializer: Serializer<T>
)

Create a GuavaDataStoreBuilder 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.

Either produceFile or context & name must be set, but not both. This is enforced by the two constructors.

Parameters
context: Context

the Context from which we retrieve files directory.

fileName: String

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

serializer: Serializer<T>

the Serializer for the type that this DataStore acts on.

Public functions

addDataMigration

Added in 1.2.0-alpha01
fun addDataMigration(dataMigration: DataMigration<T>): GuavaDataStore.Builder<T>

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

Parameters
dataMigration: DataMigration<T>

the migration to add

Returns
GuavaDataStore.Builder<T>

this

build

Added in 1.2.0-alpha01
fun build(): GuavaDataStore<T>

Build the DataStore.

Returns
GuavaDataStore<T>

the DataStore with the provided parameters

setCorruptionHandler

Added in 1.2.0-alpha01
fun setCorruptionHandler(
    corruptionHandler: ReplaceFileCorruptionHandler<T>
): GuavaDataStore.Builder<T>

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.

Parameters
corruptionHandler: ReplaceFileCorruptionHandler<T>

the handler to invoke when there is a file corruption

Returns
GuavaDataStore.Builder<T>

this

setExecutor

Added in 1.2.0-alpha01
fun setExecutor(executor: Executor): GuavaDataStore.Builder<T>

Sets the Executor used by the DataStore.

This parameter is optional and defaults to Dispatchers.IO.

Parameters
executor: Executor

the executor to be used by DataStore

Returns
GuavaDataStore.Builder<T>

this