您可以通过生成的代码 yourDao(s) 获取所有查询,该代码带有 _impl 和 your@DatabaseClass(s) 后缀与 _impl
例如对于
@Dao
public interface CustomerDao {
@Insert
long insert(Customer customer);
@Query("INSERT INTO Customer (firstname, lastName, dateAdded) VALUES(:firstName,:lastName,:dateAdded)")
long insert(String firstName, String lastName, String dateAdded);
@Query("SELECT * FROM customer WHERE firstName=:firstName AND lastName = :lastName")
Customer getCustomerByName(String firstName, String lastName);
@Query("SELECT * FROM customer")
LiveData<List<Customer>> getAllCustomers();
}
那么 CustomerDao_Impl 是:-
@SuppressWarnings({"unchecked", "deprecation"})
public final class CustomerDao_Impl implements CustomerDao {
private final RoomDatabase __db;
private final EntityInsertionAdapter<Customer> __insertionAdapterOfCustomer;
private final SharedSQLiteStatement __preparedStmtOfInsert;
public CustomerDao_Impl(RoomDatabase __db) {
this.__db = __db;
this.__insertionAdapterOfCustomer = new EntityInsertionAdapter<Customer>(__db) {
@Override
public String createQuery() {
return "INSERT OR ABORT INTO `Customer` (`id`,`firstName`,`lastName`,`dateAdded`) VALUES (?,?,?,?)";
}
..........
对于ShopDatabase
@Database(entities = {Customer.class}, version = 1)
//@TypeConverters({Converters.class})
public abstract class ShopDatabase extends RoomDatabase {
private static ShopDatabase instance;
..........
那么 ShopDatabase_Impl 是:-
@SuppressWarnings({"unchecked", "deprecation"})
public final class ShopDatabase_Impl extends ShopDatabase {
private volatile CustomerDao _customerDao;
@Override
protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration configuration) {
final SupportSQLiteOpenHelper.Callback _openCallback = new RoomOpenHelper(configuration, new RoomOpenHelper.Delegate(1) {
@Override
public void createAllTables(SupportSQLiteDatabase _db) {
_db.execSQL("CREATE TABLE IF NOT EXISTS `Customer` (`id` INTEGER, `firstName` TEXT, `lastName` TEXT, `dateAdded` TEXT, PRIMARY KEY(`id`))");
_db.execSQL("CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)");
_db.execSQL("INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '588832abfd9fd9c6aad8dcebe485e219')");
}
@Override
public void dropAllTables(SupportSQLiteDatabase _db) {
_db.execSQL("DROP TABLE IF EXISTS `Customer`");
if (mCallbacks != null) {
for (int _i = 0, _size = mCallbacks.size(); _i < _size; _i++) {
mCallbacks.get(_i).onDestructiveMigration(_db);
}
}
}
..........