package model.daoModels; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.json.JSONObject; import de.greenrobot.dao.DaoException; import model.UWDatabaseModel; // THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS // KEEP INCLUDES - put your custom includes here // KEEP INCLUDES END /** * Entity mapped to table "BIBLE_CHAPTER". */ public class BibleChapter extends model.UWDatabaseModel implements java.io.Serializable, Comparable<BibleChapter> { private Long id; private String uniqueSlug; private String slug; private String number; private String text; private String singleChapterBookName; private long bookId; /** Used to resolve relations */ private transient DaoSession daoSession; /** Used for active entity operations. */ private transient BibleChapterDao myDao; private Book book; private Long book__resolvedKey; // KEEP FIELDS - put your custom fields here // KEEP FIELDS END public BibleChapter() { } public BibleChapter(Long id) { this.id = id; } public BibleChapter(Long id, String uniqueSlug, String slug, String number, String text, String singleChapterBookName, long bookId) { this.id = id; this.uniqueSlug = uniqueSlug; this.slug = slug; this.number = number; this.text = text; this.singleChapterBookName = singleChapterBookName; this.bookId = bookId; } /** called by internal mechanisms, do not call yourself. */ public void __setDaoSession(DaoSession daoSession) { this.daoSession = daoSession; myDao = daoSession != null ? daoSession.getBibleChapterDao() : null; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUniqueSlug() { return uniqueSlug; } public void setUniqueSlug(String uniqueSlug) { this.uniqueSlug = uniqueSlug; } public String getSlug() { return slug; } public void setSlug(String slug) { this.slug = slug; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getText() { return text; } public void setText(String text) { this.text = text; } public String getSingleChapterBookName() { return singleChapterBookName; } public void setSingleChapterBookName(String singleChapterBookName) { this.singleChapterBookName = singleChapterBookName; } public long getBookId() { return bookId; } public void setBookId(long bookId) { this.bookId = bookId; } /** To-one relationship, resolved on first access. */ public Book getBook() { long __key = this.bookId; if (book__resolvedKey == null || !book__resolvedKey.equals(__key)) { if (daoSession == null) { throw new DaoException("Entity is detached from DAO context"); } BookDao targetDao = daoSession.getBookDao(); Book bookNew = targetDao.load(__key); synchronized (this) { book = bookNew; book__resolvedKey = __key; } } return book; } public void setBook(Book book) { if (book == null) { throw new DaoException("To-one property 'bookId' has not-null constraint; cannot set to-one to null"); } synchronized (this) { this.book = book; bookId = book.getId(); book__resolvedKey = bookId; } } /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */ public void delete() { if (myDao == null) { throw new DaoException("Entity is detached from DAO context"); } myDao.delete(this); } /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */ public void update() { if (myDao == null) { throw new DaoException("Entity is detached from DAO context"); } myDao.update(this); } /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */ public void refresh() { if (myDao == null) { throw new DaoException("Entity is detached from DAO context"); } myDao.refresh(this); } // KEEP METHODS - put your custom methods here //region UWDatabaseModel @Override public UWDatabaseModel setupModelFromJson(JSONObject json) { return null; } @Override public void insertModel(DaoSession session) { session.getBibleChapterDao().insert(this); } @Override public boolean updateWithModel(UWDatabaseModel newModel) { return false; } @Override public UWDatabaseModel setupModelFromJson(JSONObject json, UWDatabaseModel parent) { return null; } //endregion //region convenience methods /** * @param uniqueSlug Slug that is unique to only one model * @param session Session to use * @return Unique BibleChapter with the passed slug */ static public BibleChapter getModelForUniqueSlug(String uniqueSlug, DaoSession session){ BibleChapterDao dao = session.getBibleChapterDao(); BibleChapter model = dao.queryBuilder() .where(BibleChapterDao.Properties.UniqueSlug.eq(uniqueSlug)) .unique(); return (model == null)? null : model; } /** * @return The title to use with this chapter */ public String getTitle(){ String book = getBook().getTitle(); if(singleChapterBookName != null && singleChapterBookName.length() > 0){ book = singleChapterBookName; } return book + " " + this.number; } /** * @param id unique ID of desired model * @param session session to us * @return unique BibleChapter with passed id */ @Nullable static public BibleChapter getModelForId(long id, DaoSession session) { if(id < 0) { return null; } else { return session.getBibleChapterDao().queryBuilder() .where(BibleChapterDao.Properties.Id.eq(id)) .unique(); } } //endregion //region Comparable<> @Override public int compareTo(@NonNull BibleChapter another) { return Integer.parseInt(this.getNumber().trim()) - Integer.parseInt(another.getNumber().trim()); } //endregion @Override public String toString() { return "BibleChapter{" + "bookId=" + bookId + ", id=" + id + ", number='" + number + '\'' + ", slug='" + slug + '\'' + ", text='" + text + '\'' + ", uniqueSlug='" + uniqueSlug + '\'' + '}'; } // KEEP METHODS END }