实体关系-Android

时间:2019-05-07 09:58:02

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

我正在使用Architect组件,并且需要在波纹管值上设置很多query。如何在entities和下面的query之间创建关系?在普通模式下,我无法访问嵌套对象。

例如,我需要@Query("SELECT * FROM Content Where parent_id = 100")和其他查询,或者需要将名称命名为JIM ...,但是在正常模式下,我无法访问嵌套对象。

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

0 个答案:

没有答案