简体   繁体   English

如何用列表在数据库中删除房间表<collections> ?</collections>

[英]How to write delete room tables in database with list<collections>?

I need to delete a list of subroutines with one button push.我需要一键删除子程序列表。 But when I wrote in dao但是当我在dao中写的时候

@Delete(entity = Subroutines.class)
    void deleteSubroutineList(List<Subroutines> subroutine);

I keep getting errors trying to setup up the repository for AsychTask我在尝试为 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>[]提供: List<Subroutines>[]

But when I update required type on dao into但是当我将 dao 上的所需类型更新为

@Delete(entity = Subroutines.class)
void deleteSubroutineList(List<Subroutines>[] subroutine);

I get error at compile: pointing on dao我在编译时出错:指向 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:子程序实体 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 *不包括 getter 和 setter、构造函数、toString 导致太长

What should I do to make this work?我应该怎么做才能使这项工作?

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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM