68.6 Adding the Repository
Add a new class named ProductRepository to the project, with the Class option selected.
The repository class will be responsible for interacting with the Room database on behalf of the ViewModel and will need to provide methods that use the DAO to insert, delete and query product records. With the exception of the getAllProducts() DAO method (which returns a LiveData object) these database operations will need to be performed on separate threads from the main thread using the AsyncTask class.
Remaining within the ProductRepository.java file, add the code for the search AsyncTask. Also add a method named asyncFinished() which will be called by the query AsyncTask to return the search results to the repository thread:
package com.ebookfrenzy.roomdemo;
import android.os.AsyncTask;
import androidx.lifecycle.MutableLiveData;
import java.util.List;
public class ProductRepository {
private...