Java tutorial
package io.starter.model; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import io.starter.security.dao.MyBatisConnectionFactory; import org.apache.ibatis.session.SqlSession; public class Content implements Comparable { /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.id * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Integer id; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.description * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private String description; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.url * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private String url; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.mime_type * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private String mimeType; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.user_id * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Integer userId; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.author * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Integer author; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.longitude * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Double longitude; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.latitude * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Double latitude; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.repost_count * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Integer repostCount; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.license * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private String license; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.copyright * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private String copyright; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.author_device * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Integer authorDevice; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.width * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Long width; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.height * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Long height; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.post_date * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Date postDate; /** * This field was generated by MyBatis Generator. This field corresponds to the database column content.flag * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ private Integer flag; /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.id * @return the value of content.id * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Integer getId() { return id; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.id * @param id the value for content.id * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setId(Integer id) { this.id = id; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.description * @return the value of content.description * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public String getDescription() { return description; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.description * @param description the value for content.description * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setDescription(String description) { this.description = description; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.url * @return the value of content.url * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public String getUrl() { return url; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.url * @param url the value for content.url * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setUrl(String url) { this.url = url; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.mime_type * @return the value of content.mime_type * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public String getMimeType() { return mimeType; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.mime_type * @param mimeType the value for content.mime_type * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setMimeType(String mimeType) { this.mimeType = mimeType; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.user_id * @return the value of content.user_id * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Integer getUserId() { return userId; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.user_id * @param userId the value for content.user_id * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setUserId(Integer userId) { this.userId = userId; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.author * @return the value of content.author * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Integer getAuthor() { return author; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.author * @param author the value for content.author * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setAuthor(Integer author) { this.author = author; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.longitude * @return the value of content.longitude * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Double getLongitude() { return longitude; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.longitude * @param longitude the value for content.longitude * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setLongitude(Double longitude) { this.longitude = longitude; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.latitude * @return the value of content.latitude * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Double getLatitude() { return latitude; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.latitude * @param latitude the value for content.latitude * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setLatitude(Double latitude) { this.latitude = latitude; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.repost_count * @return the value of content.repost_count * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Integer getRepostCount() { return repostCount; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.repost_count * @param repostCount the value for content.repost_count * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setRepostCount(Integer repostCount) { this.repostCount = repostCount; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.license * @return the value of content.license * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public String getLicense() { return license; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.license * @param license the value for content.license * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setLicense(String license) { this.license = license; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.copyright * @return the value of content.copyright * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public String getCopyright() { return copyright; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.copyright * @param copyright the value for content.copyright * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setCopyright(String copyright) { this.copyright = copyright; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.author_device * @return the value of content.author_device * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Integer getAuthorDevice() { return authorDevice; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.author_device * @param authorDevice the value for content.author_device * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setAuthorDevice(Integer authorDevice) { this.authorDevice = authorDevice; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.width * @return the value of content.width * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Long getWidth() { return width; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.width * @param width the value for content.width * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setWidth(Long width) { this.width = width; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.height * @return the value of content.height * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Long getHeight() { return height; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.height * @param height the value for content.height * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setHeight(Long height) { this.height = height; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.post_date * @return the value of content.post_date * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Date getPostDate() { return postDate; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.post_date * @param postDate the value for content.post_date * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setPostDate(Date postDate) { this.postDate = postDate; } /** * This method was generated by MyBatis Generator. This method returns the value of the database column content.flag * @return the value of content.flag * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public Integer getFlag() { return flag; } /** * This method was generated by MyBatis Generator. This method sets the value of the database column content.flag * @param flag the value for content.flag * @mbggenerated Tue Apr 07 16:38:07 PDT 2015 */ public void setFlag(Integer flag) { this.flag = flag; } /** * This field was generated by MyBatis Generator. This field corresponds to * the database column content.id * */ protected User user; public User getUser() { return user; } public void setUser(User user) { this.user = user; } /* * (non-Javadoc) * * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(Object o) { Content cd = (Content) o; if (cd.getRating() > this.getRating()) return 1; else if (cd.getRating() < this.getRating()) return -1; else return 0; } protected float rating = 0.0f; /** * @param rating * the rating to set */ public void setRating(Float rating) { if (rating != null) this.rating = rating; } public float getRating() { return this.rating; } protected ArrayList ratings; public ArrayList getRatings() { if (ratings == null) ratings = new ArrayList(); return ratings; } /** * Passing a content rating in, insert into the database and commit * * @param contentRating * @throws Exception */ public void insertContentRating(ContentRating contentRating) throws Exception { SqlSession session = MyBatisConnectionFactory.getSqlSessionFactory().openSession(true); try { session.insert("io.starter.dao.ContentRatingMapper.insert", contentRating); } catch (Exception e) { session.close(); throw e; } session.commit(); session.close(); } private boolean isPublic = false; public boolean isPublic() { return isPublic; } public void setPublic(boolean isPublic) { this.isPublic = isPublic; } private List<Category> categories; /** * handle the ratings filter * * @return */ public int getContentRating() { if (categories != null) { Iterator lst = categories.iterator(); int rets = 0; // basically unrated while (lst.hasNext()) { // get the LOWEST category rating number Category cc = (Category) lst.next(); try { int sr = cc.getSuitabilityRating(); if (sr > rets) rets = sr; } catch (Exception x) { ; } } return rets; } return 10; } public List<Category> getCategories() { return categories; } public void setCategories(List<Category> categories) { this.categories = categories; } public Integer ratingCount = -1; public Integer getRatingCount() { return ratingCount; } public void setRatingCount(Integer ratingCount) { this.ratingCount = ratingCount; } public Integer commentCount = -1; public Integer getCommentCount() { return commentCount; } public void setCommentCount(Integer commentCount) { this.commentCount = commentCount; } }