66.6 Adding the Repository
Add a new class named ProductRepository to the project, with the Kind menu set to Class and None enabled in the Modifiers section of the Create New Class dialog.
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;
...