3

我正在尝试用Room persistence我有一个接受自定义对象并返回该行的 id 在数据库中的方法替换我的数据库

   /**
     * This method return -1 if there is not any classInfo other wise return
     * the id of the classInfo
     * 
     * @param ClassInfo
     * @return
     */
    public int getClassIdByInfo(ClassInfo classInfo) {
        Cursor c = db.query(DB_CLASS_INFO, new String[]{CL_ID}, CL_BRANCH
                + "=? AND " + CL_SEM + "=? AND " + CL_SECTION + "=?",
                new String[]{classInfo.branch, classInfo.sem, classInfo.section}, null, null, null);
        if (c.getCount() > 0) {
            c.moveToFirst();
            return c.getInt(0);
        } else {

            return -1;
        }  

我想用 Room persistence DAO 方法替换这个方法

@Dao
public interface StudentClassDao {

    @Query("SELECT id FROM class_info....")  //what will be the query?
    int getClassIdByInfo(ClassInfo classInfo);
}

该场景的查询是什么?

4

0 回答 0