I need to delete a list of subroutines with one button push. But when I wrote in dao
@Delete(entity = Subroutines.class)
void deleteSubroutineList(List<Subroutines> subroutine);
I keep getting errors trying to setup up the repository for AsychTask
public void deleteSubroutineList(List<Subroutines> subroutines) {
new DeleteSubroutineListAsyncTask(habitWithSubroutinesDao).execute(subroutines);
}
public static class DeleteSubroutineListAsyncTask extends AsyncTask<List<Subroutines>, Void, Void> {
private final HabitWithSubroutinesDao habitWithSubroutinesDao;
public DeleteSubroutineListAsyncTask(HabitWithSubroutinesDao habitWithSubroutinesDao) {
this.habitWithSubroutinesDao = habitWithSubroutinesDao;
}
@Override
protected Void doInBackground(List<Subroutines>... lists) {
habitWithSubroutinesDao.deleteSubroutineList(lists);
return null;
}
}
Required type: List,
Provided: List<Subroutines>[]
But when I update required type on dao into
@Delete(entity = Subroutines.class)
void deleteSubroutineList(List<Subroutines>[] subroutine);
I get error at compile: pointing on dao
error: The partial entity java.util.List<E> does not have any columns that can be used to perform the query.
void deleteSubroutineList(List<Subroutines>[] subroutine);
The Subroutine Entity Class:
@Entity(foreignKeys = @ForeignKey(
entity = Habits.class,
parentColumns = "pk_habit_uid",
childColumns = "fk_habit_uid",
onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.CASCADE
))
public class Subroutines implements Serializable {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "pk_subroutine_uid")
private long pk_subroutine_uid;
@ColumnInfo(name = "fk_habit_uid", index = true)
private long fk_habit_uid;
@ColumnInfo(name = "routine")
private String subroutine;
@ColumnInfo(name = "description")
private String description;
@ColumnInfo(name = "color")
private String color;
@ColumnInfo(name = "isModifiable")
private Boolean isModifiable;
@ColumnInfo(name = "isMarkedDone")
private boolean is_marked_done;
@ColumnInfo(name = "streak")
private int streak;
@ColumnInfo(name = "total_streak")
private int total_streak;
@ColumnInfo(name = "skips")
private int skips;
*not include getter and setters, constructor, toString cause to long
What should I do to make this work?
CodePudding user response:
I believe that you could utilise:-
@Delete(entity = Subroutines.class)
void deleteSubroutineList(List<Subroutines> subroutine);
In conjunction with :-
@Override
protected Void doInBackground(List<Subroutines>... lists) {
for(List<Subroutines> ls: lists)
habitWithSubroutinesDao.deleteSubroutineList(ls);
return null;
}