package com.medenterprise.supplystore.entity; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.persistence.*; import com.medenterprise.supplystore.enums.OrderStatus; @Entity @Table(name = "`Order`") public class Order implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name = "id", nullable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column(name = "user_id", nullable = false) private int userId; @JoinColumn(name = "customer_id", nullable = false) @ManyToOne private Customer customer; @Column(name = "site_id") private Integer siteId; @Column(name = "provider_id") private Integer providerId; @Column(name = "status_id", nullable = false) private Integer statusId; @Column(name = "date", nullable = false) @Temporal(TemporalType.DATE) private Date date; @Column(name = "requiredDate") @Temporal(TemporalType.DATE) private Date requiredDate; @Column(name = "shippingDate") @Temporal(TemporalType.DATE) private Date shippingDate; @OneToMany(cascade = {CascadeType.REFRESH, CascadeType.REMOVE}, mappedBy = "order") private List itemList; public Order() { } public String getStatus() { for (OrderStatus item : OrderStatus.values()) { if (statusId == item.ordinal()) { return item.name(); } } return null; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public int getUserId() { return userId; } public void setUserId(int userId) { this.userId = userId; } public Customer getCustomer() { if (customer == null) { customer = new Customer(); } return customer; } public void setCustomer(Customer customer) { this.customer = customer; } public Integer getSiteId() { return siteId; } public void setSiteId(Integer siteId) { this.siteId = siteId; } public Integer getProviderId() { return providerId; } public void setProviderId(Integer providerId) { this.providerId = providerId; } public Integer getStatusId() { return statusId; } public void setStatusId(Integer statusId) { this.statusId = statusId; } public Date getDate() { if (date == null) { date = new Date(); } return date; } public void setDate(Date date) { this.date = date; } public Date getRequiredDate() { if (requiredDate == null) { requiredDate = new Date(); } return requiredDate; } public void setRequiredDate(Date requiredDate) { this.requiredDate = requiredDate; } public Date getShippingDate() { return shippingDate; } public void setShippingDate(Date shippingDate) { this.shippingDate = shippingDate; } public List getItemList() { if (itemList == null) { itemList = new ArrayList(); } return itemList; } public void setItemList(List itemList) { this.itemList = itemList; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Order)) { return false; } Order other = (Order) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "com.medenterprise.app.supplystore.entity.Order[id=" + id + "]"; } }