# DataSource.Factory

Summary:[Ctors](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#pubctors)\|[Methods](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#inhmethods)  

# DataSource.Factory

| The`android.arch`Architecture Components packages are no longer maintained. They have been superseded by the corresponding[androidx.\*](https://developer.android.com/jetpack/androidx/migrate)packages. See[androidx.paging.DataSource.Factory](https://developer.android.com/reference/androidx/paging/DataSource.Factory)instead.

`
public
static

abstract
class
DataSource.Factory
`  
`

extends Object


``


`

|---|------------------------------------------------------|
| java.lang.Object                                        ||
| ↳ | android.arch.paging.DataSource.Factory\<Key, Value\> |

<br />

*** ** * ** ***

Factory for DataSources.

Data-loading systems of an application or library can implement this interface to allow`LiveData<PagedList>`s to be created. For example, Room can provide a DataSource.Factory for a given SQL query:  

```
 @Dao
 interface UserDao {
    @Query("SELECT * FROM user ORDER BY lastName ASC")
    public abstract DataSource.Factory<Integer, User> usersByLastName();
 }
 
```
In the above sample,`Integer`is used because it is the`Key`type of PositionalDataSource. Currently, Room uses the`LIMIT`/`OFFSET`SQL keywords to page a large query with a PositionalDataSource.

<br />

## Summary

|                                                       ### Public constructors                                                        ||
|-----------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[DataSource.Factory](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#DataSource.Factory())`() ` |

|                                                                                                                                                                                                                                                             ### Public methods                                                                                                                                                                                                                                                             ||
|------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)`<Key, Value>`         | ` `[create](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#create())`() ` Create a DataSource.                                                                                                                                                                                                                                                                                     |
| ` <ToValue> `[Factory](https://developer.android.com/reference/android/arch/paging/DataSource.Factory)`<Key, ToValue>` | ` `[map](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#map(android.arch.core.util.Function<Value, ToValue>))`(`[Function](https://developer.android.com/reference/android/arch/core/util/Function)`<Value, ToValue> function) ` Applies the given function to each value emitted by DataSources produced by this Factory.                                                         |
| ` <ToValue> `[Factory](https://developer.android.com/reference/android/arch/paging/DataSource.Factory)`<Key, ToValue>` | ` `[mapByPage](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#mapByPage(android.arch.core.util.Function<java.util.List<Value>, java.util.List<ToValue>>))`(`[Function](https://developer.android.com/reference/android/arch/core/util/Function)`<List<Value>, List<ToValue>> function) ` Applies the given function to each value emitted by DataSources produced by this Factory. |

| ### Inherited methods |
|-----------------------|---|
| From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public constructors

### DataSource.Factory

```
DataSource.Factory ()
```

<br />

<br />

## Public methods

### create

```
DataSource<Key, Value> create ()
```

Create a DataSource.

The DataSource should invalidate itself if the snapshot is no longer valid. If a DataSource becomes invalid, the only way to query more data is to create a new DataSource from the Factory.

[LivePagedListBuilder](https://developer.android.com/reference/android/arch/paging/LivePagedListBuilder)for example will construct a new PagedList and DataSource when the current DataSource is invalidated, and pass the new PagedList through the`LiveData<PagedList>`to observers.

<br />

|                                                            Returns                                                             ||
|----------------------------------------------------------------------------------------------------|----------------------------|
| [DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)`<Key, Value>` | the new DataSource. <br /> |

### map

```
Factory<Key, ToValue> map (Function<Value, ToValue> function)
```

Applies the given function to each value emitted by DataSources produced by this Factory.

Same as[mapByPage(Function)](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#mapByPage(android.arch.core.util.Function<java.util.List<Value>, java.util.List<ToValue>>)), but operates on individual items.

<br />

|                                                    Parameters                                                     ||
|------------|-------------------------------------------------------------------------------------------------------|
| `function` | `Function`: Function that runs on each loaded item, returning items of a potentially new type. <br /> |

|                                                                                           Returns                                                                                            ||
|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| [Factory](https://developer.android.com/reference/android/arch/paging/DataSource.Factory)`<Key, ToValue>` | A new DataSource.Factory, which transforms items using the given function. <br /> |

**See also:**

- [mapByPage(Function)](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#mapByPage(android.arch.core.util.Function<java.util.List<Value>, java.util.List<ToValue>>))
- [map(Function)](https://developer.android.com/reference/android/arch/paging/DataSource#map(android.arch.core.util.Function<Value, ToValue>))
- [mapByPage(Function)](https://developer.android.com/reference/android/arch/paging/DataSource#mapByPage(android.arch.core.util.Function<java.util.List<Value>, java.util.List<ToValue>>))  

### mapByPage

```
Factory<Key, ToValue> mapByPage (Function<List<Value>, List<ToValue>> function)
```

Applies the given function to each value emitted by DataSources produced by this Factory.

Same as[map(Function)](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#map(android.arch.core.util.Function<Value, ToValue>)), but allows for batch conversions.

<br />

|                                                    Parameters                                                     ||
|------------|-------------------------------------------------------------------------------------------------------|
| `function` | `Function`: Function that runs on each loaded page, returning items of a potentially new type. <br /> |

|                                                                                           Returns                                                                                            ||
|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| [Factory](https://developer.android.com/reference/android/arch/paging/DataSource.Factory)`<Key, ToValue>` | A new DataSource.Factory, which transforms items using the given function. <br /> |

**See also:**

- [map(Function)](https://developer.android.com/reference/android/arch/paging/DataSource.Factory#map(android.arch.core.util.Function<Value, ToValue>))
- [map(Function)](https://developer.android.com/reference/android/arch/paging/DataSource#map(android.arch.core.util.Function<Value, ToValue>))
- [mapByPage(Function)](https://developer.android.com/reference/android/arch/paging/DataSource#mapByPage(android.arch.core.util.Function<java.util.List<Value>, java.util.List<ToValue>>))  
-

  ## Interfaces

  - [DataSource.InvalidatedCallback](https://developer.android.com/reference/android/arch/paging/DataSource.InvalidatedCallback)
-

  ## Classes

  - [AsyncPagedListDiffer](https://developer.android.com/reference/android/arch/paging/AsyncPagedListDiffer)
  - [DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)
  - [DataSource.Factory](https://developer.android.com/reference/android/arch/paging/DataSource.Factory)
  - [ItemKeyedDataSource](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource)
  - [ItemKeyedDataSource.LoadCallback](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback)
  - [ItemKeyedDataSource.LoadInitialCallback](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialCallback)
  - [ItemKeyedDataSource.LoadInitialParams](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialParams)
  - [ItemKeyedDataSource.LoadParams](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadParams)
  - [LivePagedListBuilder](https://developer.android.com/reference/android/arch/paging/LivePagedListBuilder)
  - [PagedList](https://developer.android.com/reference/android/arch/paging/PagedList)
  - [PagedList.BoundaryCallback](https://developer.android.com/reference/android/arch/paging/PagedList.BoundaryCallback)
  - [PagedList.Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)
  - [PagedList.Callback](https://developer.android.com/reference/android/arch/paging/PagedList.Callback)
  - [PagedList.Config](https://developer.android.com/reference/android/arch/paging/PagedList.Config)
  - [PagedList.Config.Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Config.Builder)
  - [PagedListAdapter](https://developer.android.com/reference/android/arch/paging/PagedListAdapter)
  - [PageKeyedDataSource](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource)
  - [PageKeyedDataSource.LoadCallback](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadCallback)
  - [PageKeyedDataSource.LoadInitialCallback](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadInitialCallback)
  - [PageKeyedDataSource.LoadInitialParams](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadInitialParams)
  - [PageKeyedDataSource.LoadParams](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadParams)
  - [PositionalDataSource](https://developer.android.com/reference/android/arch/paging/PositionalDataSource)
  - [PositionalDataSource.LoadInitialCallback](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadInitialCallback)
  - [PositionalDataSource.LoadInitialParams](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadInitialParams)
  - [PositionalDataSource.LoadRangeCallback](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadRangeCallback)
  - [PositionalDataSource.LoadRangeParams](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadRangeParams)
  - [RxPagedListBuilder](https://developer.android.com/reference/android/arch/paging/RxPagedListBuilder)