Facebook
From kgsh, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 118
  1. @Table(name = "pets") // note : using JPQL not native SQL named queries
  2. public class Pet implements Serializable{
  3.        
  4.         /**
  5.          *
  6.          */
  7.         private static final long serialVersionUID = -5176917370330952845L;
  8.         @Id
  9.         @GeneratedValue(strategy=GenerationType.AUTO)  
  10.         private Integer id;
  11.         @Column(name="name")
  12.         private String name;
  13.        
  14.         @Column(name="photo")
  15.         @OneToMany(targetEntity=Photo.class)
  16.         private List<String>photoUrls = new ArrayList<>();
  17.         private String petImage;
  18.        
  19.  
  20.         private List<Tag>tags = new ArrayList<>();
  21.         @Enumerated(EnumType.STRING)
  22.         private Status status;
  23.        
  24.        
  25.  
  26.         public Pet() {}
  27.        
  28.         public  Pet(String name,  List<String>urls, List<Tag>tags, Status status) {
  29.                 this.name = name;
  30.                 this.photoUrls = urls;
  31.                 this.tags = tags;
  32.                 this.status = status;
  33.         }
  34.        
  35.         @ManyToOne
  36.         @JoinColumn(name = "category_id")
  37.         private Category category;
  38.  
  39.         @ManyToOne
  40.         @JoinColumn(name = "userNaeme")
  41.         private User user;
  42.  
  43.         //LinkedHashSet - O(1)
  44.         private Set<Order> orders = new LinkedHashSet<>(); //// to check need to maintain insertionOrder?
  45.        
  46.         public Category getCategory() {
  47.                 return category;
  48.         }
  49.  
  50.         public void setCategory(Category category) {
  51.                 this.category = category;
  52.         }
  53.  
  54.         public Integer getId() {
  55.                 return id;
  56.         }
  57.  
  58.         public void setId(Integer id) {
  59.                 this.id = id;
  60.         }
  61.  
  62.         public List<String> getPhotoUrls() {
  63.                 return photoUrls;
  64.         }
  65.  
  66.         public void setPhotoUrls(List<String> photoUrls) {
  67.                 this.photoUrls = photoUrls;
  68.         }
  69.        
  70.         public String getPetImage() {
  71.                 return petImage;
  72.         }
  73.  
  74.  
  75.         public List<Tag> getTags() {
  76.                 return tags;
  77.         }
  78.  
  79.         public void setTags(List<Tag> tags) {
  80.                 this.tags = tags;
  81.         }
  82.  
  83.        
  84.  
  85.         public void setOrders(Set<Order> orders) {
  86.                 this.orders = orders;
  87.         }
  88.        
  89.        
  90.         public User getUser() {
  91.                 return this.user;
  92.         }
  93.        
  94.         public void setUser(User user) {
  95.                 this.user = user;
  96.         }
  97.         public String getName() {
  98.                 return name;
  99.         }
  100.  
  101.         public void setName(String name) {
  102.                 this.name = name;
  103.         }
  104.        
  105.        
  106.        
  107.         protected Set<Order> getOrdersInternal() {
  108.                 if (this.orders == null) {
  109.                         this.orders = new HashSet<>();
  110.                 }
  111.                 return this.orders;
  112.         }
  113.  
  114.         public void setOrdersInternal(Collection<Order> orders) {
  115.                 this.orders = new LinkedHashSet<>(orders);
  116.         }
  117.  
  118.         public List<Order> getOrders() {
  119.                 List<Order> sortedOrders = new ArrayList<>(getOrdersInternal());
  120.                 PropertyComparator.sort(sortedOrders, new MutableSortDefinition("date", false, false));
  121.                 return Collections.unmodifiableList(sortedOrders);
  122.         }
  123.        
  124.         public void addOrder(Order order) {
  125.                 getOrdersInternal().add(order);
  126.                 order.setId(this.getId());
  127.         }
  128.  
  129.         public Status getStatus() {
  130.                 return status;
  131.         }
  132.  
  133.         public void setStatus(Status status) {
  134.                 this.status = status;
  135.         }
  136.  
  137.         public byte[] setPetImage(byte[] bytes) {
  138.                 // TODO Auto-generated method stub
  139.                 return bytes;
  140.         }
  141.  
  142.         }