SingleDataSourceRepository

The SingleDataSourceRepository<T> redirects all calls to the single data source of type T that encapsulates.

This repository is commonly used when there is only one data source to manipulate, or during the initial phase of development when further data sources are not yet implemented (for example, using a network data source only while not having yet the local storage data source ready).

Usage

val datasource = MyDataSource()
val repository = SingleDataSourceRepository(datasource /*get datasource*/, datasource /*put datasource*/, datasource /*delete datasource*/)
repository.get(IdQuery("myKey"), DefaultOperation)

Operation Types

Any operation can be passed to this repository, at is directly forwarding everything to its encapsulated DataSource. It is recomended to use a DefaultOperation as convention.

Other Implementations

Together with SingleDataSourceRepository<T> there are implementations deciated for a GetDataSource, PutDataSource and DeleteDataSource:

  • SingleGetDataSourceRepository<T>: Implements GetDataSource.
  • SinglePutDataSourceRepository<T>: Implements PutDataSource.
  • SingleDeleteDataSourceRepository<T>: Implements DeleteDataSource.

Notes

There are extensions of GetDataSource, PutDataSource and DeleteDataSource to get a SingleXXXDataSourceRepository<T>:

fun <V>GetDataSource<V>.toGetRepository() = SingleGetDataSourceRepository(this)
fun <V>PutDataSource<V>.toPutRepository() = SinglePutDataSourceRepository(this)
fun DeleteDataSource.toDeleteRepository() = SingleDeleteDataSourceRepository(this)

This allows the following code:

val getDataSource = MyGetDataSource()
val gteRepository = getDataSource.toGetRepository()
// ...