Verified
Status Update
Comments
yb...@google.com <yb...@google.com> #2
Actually you can have a BaseDao<T> and extend from it but i think we have a bug that breaks this resolution. We'll support it but we won't support Object (because Room does not know what is returned unless you tell it and we don't want to inherit from table).
ze...@gmail.com <ze...@gmail.com> #3
Thats Great news, could you let me know when its fixed ? :)
yb...@google.com <yb...@google.com>
yb...@google.com <yb...@google.com>
bs...@gmail.com <bs...@gmail.com> #4
ROOM version: 1.0.0-alpha8
My DAO
@Dao
public interface GenericDao<T extends Entity> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insert(T entity);
@Update
int update(T entity);
@Delete
int delete(T entity);
}
ERROR:Type of the parameter must be a class annotated with @Entity or a collection/array of it.
My DAO
@Dao
public interface GenericDao<T extends Entity> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insert(T entity);
@Update
int update(T entity);
@Delete
int delete(T entity);
}
ERROR:Type of the parameter must be a class annotated with @Entity or a collection/array of it.
ze...@gmail.com <ze...@gmail.com> #5
Does this also support
@Query("SELECT * FROM user")
List<T> getAll();
@Query("SELECT * FROM user")
Flowable<List<User>> getAll();
??
@Query("SELECT * FROM user")
List<T> getAll();
@Query("SELECT * FROM user")
Flowable<List<User>> getAll();
??
ze...@gmail.com <ze...@gmail.com> #6
Or Better with dynamic queries
@Query(query)
List<T> getAll(String query);
or
@Query(query)
Flowable<List<User>> getAll(Query query);
@Query(query)
List<T> getAll(String query);
or
@Query(query)
Flowable<List<User>> getAll(Query query);
bs...@gmail.com <bs...@gmail.com> #7
The "Dao" below works. I can have other Dao heroing the GenericDao.
@Dao
public interface GenericDao<T> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(T... entity);
@Update
void update(T... entity);
@Delete
void delete(T... entity);
}
However, GenericDao can not be included in my Database class
@Dao
public interface GenericDao<T> {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(T... entity);
@Update
void update(T... entity);
@Delete
void delete(T... entity);
}
However, GenericDao can not be included in my Database class
Description
Version used: 1.0.0.aplha1
Devices/Android versions reproduced on: All
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).
I would be cool if return types could be generic or even an Object and the mapping could be done on the output. That way i do not need to create a new Dao for every model in my project.