VoidDataSource

VoidDataSource<T> is an empty implementation of GetDataSource, PutDataSource and DeleteDataSource. Any call to these functions will result in an error being thrown.

Usage

val dataSource = VoidDataSource<String>()
getDataSource.get("sampleKey").onComplete(onSuccess = {}, onFailure = {
// Error is a UnsupportedOperationException
print(it)
})

Note that the example above is using the extension methods of DataSoruce that encapsulate queries of type IdQuery<T>.

Query Types

Any Query can be passed to a VoidDataSource<T> (and all will result with an error).

Other Implementations

Together with VoidDataSource<T> there are also similar implementations for:

  • VoidGetDataSource<T>: Implements GetDataSource.
  • VoidPutDataSource<T>: Implements PutDataSource.
  • VoidDeleteDataSource: Implements DeleteDataSource.

Implementation Notes

Find below an example of implementation of a VoidDataSource<T>:

class VoidDataSource<V> : GetDataSource<V>, PutDataSource<V>, DeleteDataSource {
override fun get(query: Query): Future<V> = Future { throw UnsupportedOperationException() }
override fun getAll(query: Query): Future<List<V>> = Future { throw UnsupportedOperationException() }
override fun put(query: Query, value: V?): Future<V> = Future { throw UnsupportedOperationException() }
override fun putAll(query: Query, value: List<V>?): Future<List<V>> = Future { throw UnsupportedOperationException() }
override fun delete(query: Query): Future<Unit> = Future { throw UnsupportedOperationException() }
override fun deleteAll(query: Query): Future<Unit> = Future { throw UnsupportedOperationException() }
}