How to get list of cursor object from room dao access?

Viewed 9380

I am trying to chnage my code to make use of room database APIs. For documents table I have defined Entity class Document, when I query getAll() it returns me all the document.

Now I have old implementation of Adapter which makes user of Cursor ( Its a CursorAdapter ). In my DocumentDao class I defined one method to get list of cursor objects. My Dao class as follows :

@Dao
public interface DocumentDao {

    @Query("SELECT * FROM documents")
    List<com.myapp.room.entity.Document> getAll();

    @Query("SELECT * FROM documents")
    List<Cursor> getCursorAll();
}

During compile time I am getting following error :

Error:(20, 18) error: Not sure how to convert a Cursor to this method's return type

The official guide for Room which states that :

If your app's logic requires direct access to the return rows, you can return a Cursor object from your queries, as shown in the following code snippet:

@Dao
public interface MyDao {
    @Query("SELECT * FROM user WHERE age > :minAge LIMIT 5")
    public Cursor loadRawUsersOlderThan(int minAge);
}

My question is do I need to write converter for this purpose ?

1 Answers
Related