diff --git a/src/test/java/com/avaje/tests/model/basic/Order.java b/src/test/java/com/avaje/tests/model/basic/Order.java index f331b783e..270137dee 100644 --- a/src/test/java/com/avaje/tests/model/basic/Order.java +++ b/src/test/java/com/avaje/tests/model/basic/Order.java @@ -30,241 +30,241 @@ import com.avaje.ebean.annotation.Where; * Order entity bean. */ @Entity -@Table(name="o_order") +@Table(name = "o_order") public class Order implements Serializable { - - private static final long serialVersionUID = 1L; - - @XmlType(name="status") - public enum Status { - NEW, - APPROVED, - SHIPPED, - COMPLETE - } - - public Order(){ - - } - - @Id - Integer id; + private static final long serialVersionUID = 1L; - /** - * Derived total amount from the order details. Needs to be explicitly included in query as Transient. - * Removing the Transient would mean by default it would be included in a order query. - *

- * NOTE: The join clause for totalAmount and totalItems is the same. If your query includes both - * totalAmount and totalItems only the one join is added to the query. - *

- */ - @Transient - @Formula( - select="z_b${ta}.total_amount", - join="join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id") - Double totalAmount; + @XmlType(name = "status") + public enum Status { + NEW, + APPROVED, + SHIPPED, + COMPLETE + } - /** - * Derived total item count from the order details. Needs to be explicitly included in query as Transient. - */ - @Transient - @Formula( - select="z_b${ta}.total_items", - join="join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id") - Integer totalItems; - - @Enumerated(value=EnumType.ORDINAL) - Status status = Status.NEW; - - Date orderDate = new Date(System.currentTimeMillis()); + public Order() { - Date shipDate; + } - @NotNull - @ManyToOne - @JoinColumn(name="kcustomer_id") - Customer customer; - - //@Basic(fetch=FetchType.LAZY) - @Column(name="name",table="o_customer") - String customerName; - - @CreatedTimestamp - Timestamp cretime; - @Version - Timestamp updtime; + @Id + Integer id; - @Where(clause="${ta}.id > 0") - @OneToMany(cascade=CascadeType.ALL, mappedBy="order") - @OrderBy("id asc, orderQty asc, cretime desc") - List details; - - @OneToMany(cascade=CascadeType.ALL, mappedBy="order") - List shipments; - - public String toString() { - return id+" totalAmount:"+totalAmount+" totalItems:"+totalItems; + /** + * Derived total amount from the order details. Needs to be explicitly included in query as Transient. + * Removing the Transient would mean by default it would be included in a order query. + *

+ * NOTE: The join clause for totalAmount and totalItems is the same. If your query includes both + * totalAmount and totalItems only the one join is added to the query. + *

+ */ + @Transient + @Formula( + select = "z_b${ta}.total_amount", + join = "join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id") + Double totalAmount; + + /** + * Derived total item count from the order details. Needs to be explicitly included in query as Transient. + */ + @Transient + @Formula( + select = "z_b${ta}.total_items", + join = "join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id") + Integer totalItems; + + @Enumerated(value = EnumType.ORDINAL) + Status status = Status.NEW; + + Date orderDate = new Date(System.currentTimeMillis()); + + Date shipDate; + + @NotNull + @ManyToOne + @JoinColumn(name = "kcustomer_id") + Customer customer; + + //@Basic(fetch=FetchType.LAZY) + @Column(name = "name", table = "o_customer") + String customerName; + + @CreatedTimestamp + Timestamp cretime; + + @Version + Timestamp updtime; + + @Where(clause = "${ta}.id > 0") + @OneToMany(cascade = CascadeType.ALL, mappedBy = "order") + @OrderBy("id asc, orderQty asc, cretime desc") + List details; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "order") + List shipments; + + public String toString() { + return id + " totalAmount:" + totalAmount + " totalItems:" + totalItems; + } + + /** + * Return id. + */ + public Integer getId() { + return id; + } + + /** + * Set id. + */ + public void setId(Integer id) { + this.id = id; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public Double getTotalAmount() { + return totalAmount; + } + + public void setTotalAmount(Double totalAmount) { + this.totalAmount = totalAmount; + } + + public Integer getTotalItems() { + return totalItems; + } + + public void setTotalItems(Integer totalItems) { + this.totalItems = totalItems; + } + + /** + * Return order date. + */ + public Date getOrderDate() { + return orderDate; + } + + /** + * Set order date. + */ + public void setOrderDate(Date orderDate) { + this.orderDate = orderDate; + } + + /** + * Return ship date. + */ + public Date getShipDate() { + return shipDate; + } + + /** + * Set ship date. + */ + public void setShipDate(Date shipDate) { + this.shipDate = shipDate; + } + + /** + * Return cretime. + */ + public Timestamp getCretime() { + return cretime; + } + + /** + * Set cretime. + */ + public void setCretime(Timestamp cretime) { + this.cretime = cretime; + } + + /** + * Return updtime. + */ + public Timestamp getUpdtime() { + return updtime; + } + + /** + * Set updtime. + */ + public void setUpdtime(Timestamp updtime) { + this.updtime = updtime; + } + + /** + * Return status. + */ + public Status getStatus() { + return status; + } + + /** + * Set status. + */ + public void setStatus(Status status) { + this.status = status; + } + + /** + * Return customer. + */ + public Customer getCustomer() { + return customer; + } + + /** + * Set customer. + */ + public void setCustomer(Customer customer) { + this.customer = customer; + } + + /** + * Return details. + */ + public List getDetails() { + return details; + } + + /** + * Set details. + */ + public void setDetails(List details) { + this.details = details; + } + + public void addDetail(OrderDetail detail) { + + if (details == null) { + details = new ArrayList(); } - - /** - * Return id. - */ - public Integer getId() { - return id; + details.add(detail); + } + + public List getShipments() { + return shipments; + } + + public void setShipments(List shipments) { + this.shipments = shipments; + } + + public void addShipment(OrderShipment shipment) { + + if (shipments == null) { + shipments = new ArrayList(); } - - /** - * Set id. - */ - public void setId(Integer id) { - this.id = id; - } - - public String getCustomerName() { - return customerName; - } - - public void setCustomerName(String customerName) { - this.customerName = customerName; - } - - public Double getTotalAmount() { - return totalAmount; - } - - public void setTotalAmount(Double totalAmount) { - this.totalAmount = totalAmount; - } - - public Integer getTotalItems() { - return totalItems; - } - - public void setTotalItems(Integer totalItems) { - this.totalItems = totalItems; - } - - /** - * Return order date. - */ - public Date getOrderDate() { - return orderDate; - } - - /** - * Set order date. - */ - public void setOrderDate(Date orderDate) { - this.orderDate = orderDate; - } - - /** - * Return ship date. - */ - public Date getShipDate() { - return shipDate; - } - - /** - * Set ship date. - */ - public void setShipDate(Date shipDate) { - this.shipDate = shipDate; - } - - /** - * Return cretime. - */ - public Timestamp getCretime() { - return cretime; - } - - /** - * Set cretime. - */ - public void setCretime(Timestamp cretime) { - this.cretime = cretime; - } - - /** - * Return updtime. - */ - public Timestamp getUpdtime() { - return updtime; - } - - /** - * Set updtime. - */ - public void setUpdtime(Timestamp updtime) { - this.updtime = updtime; - } - - /** - * Return status. - */ - public Status getStatus() { - return status; - } - - /** - * Set status. - */ - public void setStatus(Status status) { - this.status = status; - } - - /** - * Return customer. - */ - public Customer getCustomer() { - return customer; - } - - /** - * Set customer. - */ - public void setCustomer(Customer customer) { - this.customer = customer; - } - - /** - * Return details. - */ - public List getDetails() { - return details; - } - - /** - * Set details. - */ - public void setDetails(List details) { - this.details = details; - } - - public void addDetail(OrderDetail detail){ - - if (details == null){ - details = new ArrayList(); - } - details.add(detail); - } - - public List getShipments() { - return shipments; - } - - public void setShipments(List shipments) { - this.shipments = shipments; - } - - public void addShipment(OrderShipment shipment){ - - if (shipments == null){ - shipments = new ArrayList(); - } - shipments.add(shipment); - } + shipments.add(shipment); + } }