Relation on entities - android

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 10:19:08

问题


I am using from architect component and I need to set a lot of query on bellow values. How to create relation between bellow entities for query? in normal mode I can't access to nested objects.

For example I need to @Query("SELECT * FROM Content Where parent_id = 100") and other queries or I need to values that the name is JIM... but in normal mode I can't access to nested objects.

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

And:

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
}

And:

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
}

And:

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
}

And:

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
}

来源:https://stackoverflow.com/questions/56020030/relation-on-entities-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!