在DAO类Room Persistence中的方法中传递的自定义对象

时间:2017-06-18 15:10:28

标签: android android-sqlite android-room

我正在尝试用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);
}

该场景的查询是什么?

0 个答案:

没有答案