查询房间中的嵌套对象-Android

时间:2019-05-06 10:30:20

标签: android sqlite android-room android-architecture-components android-viewmodel

我在项目中的architect component中使用了entities,下面是一个API

@Entity(tableName = "tblCourseContentList")
public class CourseContentListModel {
    @PrimaryKey(autoGenerate = true)
    private long id_courseContentList;
    @SerializedName("status")
    @Expose
    private String status;
    @SerializedName("0")
    @Expose
    @Embedded
    private _0 _0 = null;

    // --- CONSTRUCTORS ---
    @Ignore
    public CourseContentListModel() {

    }

    public CourseContentListModel(long id_courseContentList,
                                  String status,
                                  _0 _0) {
        this.id_courseContentList = id_courseContentList;
        this.status = status;
        this._0 = _0;
    }

    //region --- GETTER ---
    public long getId_courseContentList() {
        return id_courseContentList;
    }

    public String getStatus() {
        return status;
    }

    public _0 get_0() {
        return _0;
    }
    //endregion

    //region --- SETTER ---
    public void setId_courseContentList(long id_courseContentList) {
        this.id_courseContentList = id_courseContentList;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void set_0(_0 _0) {
        this._0 = _0;
    }
    //endregion
}

并且:

public class _0 {
    @SerializedName("download_package_url")
    @Expose
    private String downloadPackageUrl;
    @SerializedName("download_package_size")
    @Expose
    private String downloadPackageSize;
    @SerializedName("sections")
    @Expose
    private List<Section> sections = null;

    // --- CONSTRUCTORS ---
    @Ignore
    public _0() {

    }

    public _0(String downloadPackageUrl,
              String downloadPackageSize,
              List<Section> sections) {
        this.downloadPackageUrl = downloadPackageUrl;
        this.downloadPackageSize = downloadPackageSize;
        this.sections = sections;
    }

    //region --- GETTER ---
    public String getDownloadPackageUrl() {
        return downloadPackageUrl;
    }

    public String getDownloadPackageSize() {
        return downloadPackageSize;
    }

    public List<Section> getSections() {
        return sections;
    }
    //endregion

    //region --- SETTER ---
    public void setDownloadPackageUrl(String downloadPackageUrl) {
        this.downloadPackageUrl = downloadPackageUrl;
    }

    public void setDownloadPackageSize(String downloadPackageSize) {
        this.downloadPackageSize = downloadPackageSize;
    }

    public void setSections(List<Section> sections) {
        this.sections = sections;
    }
    //endregion
}

并且:

public class Section {
    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("summary")
    @Expose
    private String summary;
    @SerializedName("content")
    @Expose
    private List<Content> content = null;

    // --- CONSTRUCTORS ---
    @Ignore
    public Section() {

    }

    public Section(String id,
                   String name,
                   String summary,
                   List<Content> content) {
        this.id = id;
        this.name = name;
        this.summary = summary;
        this.content = content;
    }

    //region --- GETTER ---
    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getSummary() {
        return summary;
    }

    public List<Content> getContent() {
        return content;
    }
    //endregion

    //region --- SETTER ---
    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public void setContent(List<Content> content) {
        this.content = content;
    }
    //endregion
}

并且:

public class Content {
    @SerializedName("module_id")
    @Expose
    private String module_id;
    @SerializedName("parent_id")
    @Expose
    private String parent_id;
    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("filename")
    @Expose
    private String filename;
    @SerializedName("filesize")
    @Expose
    private String filesize;
    @SerializedName("fileurl")
    @Expose
    private String fileurl;
    @SerializedName("extension")
    @Expose
    private String extension;
    @SerializedName("filetype")
    @Expose
    private String filetype;
    @SerializedName("url")
    @Expose
    private String url;
    @SerializedName("type")
    @Expose
    private String type;
    @SerializedName("description")
    @Expose
    private String description;
    @SerializedName("media")
    @Expose
    private List<Media> media = null;

    // --- CONSTRUCTORS ---
    @Ignore
    public Content() {

    }

    public Content(String module_id,
                   String parent_id,
                   String name,
                   String filename,
                   String filesize,
                   String fileurl,
                   String extension,
                   String filetype,
                   String url,
                   String type,
                   String description,
                   List<Media> media) {
        this.module_id = module_id;
        this.parent_id = parent_id;
        this.name = name;
        this.filename = filename;
        this.filesize = filesize;
        this.fileurl = fileurl;
        this.extension = extension;
        this.filetype = filetype;
        this.url = url;
        this.type = type;
        this.description = description;
        this.media = media;
    }

    //region --- GETTER ---
    public String getModule_id() {
        return module_id;
    }

    public String getParent_id() {
        return parent_id;
    }

    public String getName() {
        return name;
    }

    public String getFilename() {
        return filename;
    }

    public String getFilesize() {
        return filesize;
    }

    public String getFileurl() {
        return fileurl;
    }

    public String getExtension() {
        return extension;
    }

    public String getFiletype() {
        return filetype;
    }

    public String getUrl() {
        return url;
    }

    public String getType() {
        return type;
    }

    public String getDescription() {
        return description;
    }

    public List<Media> getMedia() {
        return media;
    }
    //endregion

    //region --- SETTER ---
    public void setModule_id(String module_id) {
        this.module_id = module_id;
    }

    public void setParent_id(String parent_id) {
        this.parent_id = parent_id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public void setFilesize(String filesize) {
        this.filesize = filesize;
    }

    public void setFileurl(String fileurl) {
        this.fileurl = fileurl;
    }

    public void setExtension(String extension) {
        this.extension = extension;
    }

    public void setFiletype(String filetype) {
        this.filetype = filetype;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setMedia(List<Media> media) {
        this.media = media;
    }
    //endregion
}

并且:

public class Media {
    @SerializedName("parent_id")
    @Expose
    private String parent_id;
    @SerializedName("title")
    @Expose
    private String title;
    @SerializedName("url")
    @Expose
    private String url;
    @SerializedName("filetype")
    @Expose
    private String filetype;
    @SerializedName("extension")
    @Expose
    private String extension;

    // --- CONSTRUCTORS ---
    public Media() {

    }

    public Media(String parent_id,
                 String title,
                 String url,
                 String filetype,
                 String extension) {
        this.parent_id = parent_id;
        this.title = title;
        this.url = url;
        this.filetype = filetype;
        this.extension = extension;
    }

    //region --- GETTER ---
    public String getParent_id() {
        return parent_id;
    }

    public String getTitle() {
        return title;
    }

    public String getUrl() {
        return url;
    }

    public String getFileType() {
        return filetype;
    }

    public String getExtension() {
        return extension;
    }
    //endregion

    //region --- SETTER ---
    public void setParent_id(String parent_id) {
        this.parent_id = parent_id;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setFileType(String filetype) {
        this.filetype = filetype;
    }

    public void setExtension(String extension) {
        this.extension = extension;
    }
    //endregion
}

我需要像下面这样在query中用DAO获取数据:

@Dao
public interface CourseContentSubListDao {
    @Query("SELECT * FROM tblCourseContentList WHERE parent_id=:id AND type=:type")
    LiveData<SubContentModel> getAllQResource(String id, String type);
}

但是这里parent_id和这里typeCannot resolve symbol 'parent_id'Cannot resolve symbol 'type'

我该怎么办?

我应该从foreignKeys开始使用吗?

如果我应该在foreignKeys中使用foreignKeys,请问我该如何在entities中使用public List<RecipeIndicatorsDto> listByUploadTime(LocalDateTime localDateTime) { if(localDateTime!=null) { QRecipeIndicator qRecipeIndicator = recipeIndicatorRepo.getQEntity(); QOrder qOrder=orderRepo.getQEntity(); List<Predicate> predicates = new ArrayList<>(); predicates.add(qRecipeIndicator.uploadTime.before(localDateTime)); List<RecipeIndicator> recipeIndicators = recipeIndicatorRepo.find(predicates, new PageRequest(0, 100)); List<Order> orders=orderRepo.find(null,new PageRequest(0,100)); return recipeIndicators.stream() .map(DtoFactory::recipeIndicatorsDto) .collect(Collectors.toList());

0 个答案:

没有答案