// Path: src/main/java/com/yyqian/imagine/po/Post.java
// @Entity
// @Table(name = "post")
// public class Post extends BaseUGC {
// 
//   @Column(name = "title", nullable = false)
//   private String title;
// 
//   @Enumerated(EnumType.STRING)
//   @Column(name = "kind", nullable = false)
//   private Kind kind;
// 
//   @Enumerated(EnumType.STRING)
//   @Column(name = "category")
//   private Category category;
// 
//   // map to comment, bidirectional
//   // @OneToMany tells the persistence provider this is an association and not an attribute.
//   @OneToMany(mappedBy = "post", fetch = FetchType.EAGER, orphanRemoval = true, cascade =
//       {CascadeType.PERSIST, CascadeType.MERGE})
//   @JsonIgnore
//   private List<Comment> comments = new ArrayList<Comment>();
// 
//   @Column(name = "comment_count", nullable = false)
//   private int commentCount = 0;
// 
//   @Column(name = "site")
//   private String site;
// 
//   // The default constructor only exists for the sake of JPA. You won’t use it directly, so it is
//   // designated as protected.
//   public Post() {
//   }
// 
//   public Post(String title, String content, User user, Kind kind) {
//     super(content, user);
//     this.title = title;
//     this.kind = kind;
//   }
// 
//   @Override
//   public String toString() {
//     return id.toString();
//   }
// 
//   public static enum Kind {PLAIN, LINK}
// 
//   public static enum Category {SHOW, ASK}
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Kind getKind() {
//     return kind;
//   }
// 
//   public Category getCategory() {
//     return category;
//   }
// 
//   public List<Comment> getComments() {
//     return comments;
//   }
// 
//   public int getCommentCount() {
//     return commentCount;
//   }
// 
//   public void setTitle(String title) {
//     this.title = title;
//   }
// 
//   public void setKind(Kind kind) {
//     this.kind = kind;
//   }
// 
//   public void setCategory(Category category) {
//     this.category = category;
//   }
// 
//   public void setComments(List<Comment> comments) {
//     this.comments = comments;
//   }
// 
//   public void increaseCommentCount() {
//     commentCount = commentCount + 1;
//   }
// 
//   public void decreaseCommentCount() {
//     if (commentCount > 0) {
//       commentCount = commentCount - 1;
//     }
//   }
// 
//   public String getSite() {
//     return site;
//   }
// 
//   public void setSite(String site) {
//     this.site = site;
//   }
// }
// 
// Path: src/main/java/com/yyqian/imagine/po/User.java
// @Entity
// @Table(name = "user")
// public class User extends Base {
// 
//   @Column(name = "username", nullable = false, unique = true)
//   private String username;
// 
//   @Column(name = "password_hash", nullable = false)
//   private String passwordHash;
// 
//   @Column(name = "email", unique = true)
//   private String email;
// 
//   @Column(name = "role", nullable = false)
//   @Enumerated(EnumType.STRING)
//   private Role role = Role.USER;
// 
//   @Lob
//   @Column(name = "about")
//   private String about;
// 
//   @Column(name = "point", nullable = false)
//   private Integer point = 0;
// 
//   public enum Role {
//     USER, ADMIN
//   }
// 
//   public User() {
//   }
// 
//   public User(String username, String passwordHash) {
//     this.username = username;
//     this.passwordHash = passwordHash;
//   }
// 
//   @Override
//   public String toString() {
//     return id.toString();
//   }
// 
//   public String getUsername() {
//     return username;
//   }
// 
//   public String getEmail() {
//     return email;
//   }
// 
//   public Role getRole() {
//     return role;
//   }
// 
//   public String getPasswordHash() {
//     return passwordHash;
//   }
// 
//   public void setPasswordHash(String passwordHash) {
//     this.passwordHash = passwordHash;
//   }
// 
//   public void setRole(Role role) {
//     this.role = role;
//   }
// 
//   public void setUsername(String username) {
//     this.username = username;
//   }
// 
//   public void setEmail(String email) {
//     this.email = email;
//   }
// 
//   public String getAbout() {
//     return about;
//   }
// 
//   public void setAbout(String about) {
//     this.about = about;
//   }
// 
//   public Integer getPoint() {
//     return point;
//   }
// 
//   public void setPoint(Integer point) {
//     this.point = point;
//   }
// }


import com.yyqian.imagine.po.Post;
import com.yyqian.imagine.po.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Collection;
package com.yyqian.imagine.repository;



/**
 * Created by yyqian on 12/5/15.
 * In a typical Java application, you’d expect to write a class that implements PostRepository.
 * But that’s what makes Spring Data JPA so powerful: You don’t have to write an implementation of
 * the repository interface. Spring Data JPA creates an implementation on the fly when you run
 * the application.
 * In summary:
 * 1. Interface-based programming entity
 * 2. No implementation required
 * 3. Queries derived from method names
 * CrudRepository: exposed CRUD methods
 * PagingAndSortingRepository: exposed CRUD methods and paging ones
 * JpaRepository: findAll() will return List<T>, the transaction timeout for save() is customized
 * to 10 secs.
 *
 * Repository annotation is optional, just for the sake of Intellij IDEA. IDEA will complain without it.
 */
@Repository
public interface PostRepository extends JpaRepository<Post, Long> {
  Collection<Post> findBySite(String site);
// Path: src/main/java/com/yyqian/imagine/po/Post.java
// @Entity
// @Table(name = "post")
// public class Post extends BaseUGC {
// 
//   @Column(name = "title", nullable = false)
//   private String title;
// 
//   @Enumerated(EnumType.STRING)
//   @Column(name = "kind", nullable = false)
//   private Kind kind;
// 
//   @Enumerated(EnumType.STRING)
//   @Column(name = "category")
//   private Category category;
// 
//   // map to comment, bidirectional
//   // @OneToMany tells the persistence provider this is an association and not an attribute.
//   @OneToMany(mappedBy = "post", fetch = FetchType.EAGER, orphanRemoval = true, cascade =
//       {CascadeType.PERSIST, CascadeType.MERGE})
//   @JsonIgnore
//   private List<Comment> comments = new ArrayList<Comment>();
// 
//   @Column(name = "comment_count", nullable = false)
//   private int commentCount = 0;
// 
//   @Column(name = "site")
//   private String site;
// 
//   // The default constructor only exists for the sake of JPA. You won’t use it directly, so it is
//   // designated as protected.
//   public Post() {
//   }
// 
//   public Post(String title, String content, User user, Kind kind) {
//     super(content, user);
//     this.title = title;
//     this.kind = kind;
//   }
// 
//   @Override
//   public String toString() {
//     return id.toString();
//   }
// 
//   public static enum Kind {PLAIN, LINK}
// 
//   public static enum Category {SHOW, ASK}
// 
//   public String getTitle() {
//     return title;
//   }
// 
//   public Kind getKind() {
//     return kind;
//   }
// 
//   public Category getCategory() {
//     return category;
//   }
// 
//   public List<Comment> getComments() {
//     return comments;
//   }
// 
//   public int getCommentCount() {
//     return commentCount;
//   }
// 
//   public void setTitle(String title) {
//     this.title = title;
//   }
// 
//   public void setKind(Kind kind) {
//     this.kind = kind;
//   }
// 
//   public void setCategory(Category category) {
//     this.category = category;
//   }
// 
//   public void setComments(List<Comment> comments) {
//     this.comments = comments;
//   }
// 
//   public void increaseCommentCount() {
//     commentCount = commentCount + 1;
//   }
// 
//   public void decreaseCommentCount() {
//     if (commentCount > 0) {
//       commentCount = commentCount - 1;
//     }
//   }
// 
//   public String getSite() {
//     return site;
//   }
// 
//   public void setSite(String site) {
//     this.site = site;
//   }
// }
// 
// Path: src/main/java/com/yyqian/imagine/po/User.java
// @Entity
// @Table(name = "user")
// public class User extends Base {
// 
//   @Column(name = "username", nullable = false, unique = true)
//   private String username;
// 
//   @Column(name = "password_hash", nullable = false)
//   private String passwordHash;
// 
//   @Column(name = "email", unique = true)
//   private String email;
// 
//   @Column(name = "role", nullable = false)
//   @Enumerated(EnumType.STRING)
//   private Role role = Role.USER;
// 
//   @Lob
//   @Column(name = "about")
//   private String about;
// 
//   @Column(name = "point", nullable = false)
//   private Integer point = 0;
// 
//   public enum Role {
//     USER, ADMIN
//   }
// 
//   public User() {
//   }
// 
//   public User(String username, String passwordHash) {
//     this.username = username;
//     this.passwordHash = passwordHash;
//   }
// 
//   @Override
//   public String toString() {
//     return id.toString();
//   }
// 
//   public String getUsername() {
//     return username;
//   }
// 
//   public String getEmail() {
//     return email;
//   }
// 
//   public Role getRole() {
//     return role;
//   }
// 
//   public String getPasswordHash() {
//     return passwordHash;
//   }
// 
//   public void setPasswordHash(String passwordHash) {
//     this.passwordHash = passwordHash;
//   }
// 
//   public void setRole(Role role) {
//     this.role = role;
//   }
// 
//   public void setUsername(String username) {
//     this.username = username;
//   }
// 
//   public void setEmail(String email) {
//     this.email = email;
//   }
// 
//   public String getAbout() {
//     return about;
//   }
// 
//   public void setAbout(String about) {
//     this.about = about;
//   }
// 
//   public Integer getPoint() {
//     return point;
//   }
// 
//   public void setPoint(Integer point) {
//     this.point = point;
//   }
// }


// Path: src/main/java/com/yyqian/imagine/repository/PostRepository.java
import com.yyqian.imagine.po.Post;
import com.yyqian.imagine.po.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Collection;

package com.yyqian.imagine.repository;



/**
 * Created by yyqian on 12/5/15.
 * In a typical Java application, you’d expect to write a class that implements PostRepository.
 * But that’s what makes Spring Data JPA so powerful: You don’t have to write an implementation of
 * the repository interface. Spring Data JPA creates an implementation on the fly when you run
 * the application.
 * In summary:
 * 1. Interface-based programming entity
 * 2. No implementation required
 * 3. Queries derived from method names
 * CrudRepository: exposed CRUD methods
 * PagingAndSortingRepository: exposed CRUD methods and paging ones
 * JpaRepository: findAll() will return List<T>, the transaction timeout for save() is customized
 * to 10 secs.
 *
 * Repository annotation is optional, just for the sake of Intellij IDEA. IDEA will complain without it.
 */
@Repository
public interface PostRepository extends JpaRepository<Post, Long> {
  Collection<Post> findBySite(String site);
  Collection<Post> findByUser(User user);