如何重载android房间dao方法?

2skhul33  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(271)

在android房间里,我正在为articletable实体类编写@dao。
在这个articledao类中,有几个具有不同名称的更新方法。
我可以超载android房间方法吗?
如果我重载android room方法,它们会工作吗?
articledao类如下

@Dao
public interface ArticleDao {
    // insert query
    @Insert(onConflict = REPLACE)
    void insert(ArticleData articleData);

    @Delete
    void delete(ArticleData articleData);

    // delete all query
    @Delete
    void reset(List<ArticleData> articleDataList);

    // update query
    @Query("UPDATE " + Constants.TABLE_NAME_ARTICLE +
            " SET title = :uTitle, content = :uContent  WHERE ID = :uID")
    void updateTitle_Content(int uID, String uTitle, String uContent);

    // update query
    @Query("UPDATE " + Constants.TABLE_NAME_ARTICLE +
            " SET articleID = :uArticleID, title = :uTitle WHERE ID = :uID")
    void updateArticleID_Title_Content(int uID, int uArticleID, String uTitle);

    // update query
    @Query("UPDATE " + Constants.TABLE_NAME_ARTICLE +
            " SET articleID = :uArticleID, title = :uTitle, content = :uContent WHERE ID = :uID")
    void updateAll(int uID, int uArticleID, String uTitle, String uContent);

    // get all data query
    @Query("SELECT * FROM " + Constants.TABLE_NAME_ARTICLE)
    List<ArticleData> getAll();
}
ubbxdtey

ubbxdtey1#

是的,我们可以重载android房间方法。
android room方法重载过程与java方法重载过程相同
articledao类位于以下重载方法中。

@Dao
public interface ArticleDao {
    // insert query
    @Insert(onConflict = REPLACE)
    void insert(ArticleData articleData);

    @Delete
    void delete(ArticleData articleData);

    // delete all query
    @Delete
    void reset(List<ArticleData> articleDataList);

    // update query
    @Query("UPDATE " + Constants.TABLE_NAME_ARTICLE +
            " SET title = :uTitle, content = :uContent  WHERE ID = :uID")
    void update(int uID, String uTitle, String uContent);

    // update query
    @Query("UPDATE " + Constants.TABLE_NAME_ARTICLE +
            " SET articleID = :uArticleID, title = :uTitle WHERE ID = :uID")
    void update(int uID, int uArticleID, String uTitle);

    // update query
    @Query("UPDATE " + Constants.TABLE_NAME_ARTICLE +
            " SET articleID = :uArticleID, title = :uTitle, content = :uContent WHERE ID = :uID")
    void update(int uID, int uArticleID, String uTitle, String uContent);

    // get all data query
    @Query("SELECT * FROM " + Constants.TABLE_NAME_ARTICLE)
    List<ArticleData> getAll();
}

相关问题