1 package org.hibernate.test.cid; 3 4 import java.io.Serializable ; 5 import java.math.BigDecimal ; 6 import java.util.ArrayList ; 7 import java.util.Calendar ; 8 import java.util.Collection ; 9 10 13 public class Order { 14 public static class Id implements Serializable { 15 private String customerId; 16 private int orderNumber; 17 18 public Id(String customerId, int orderNumber) { 19 this.customerId = customerId; 20 this.orderNumber = orderNumber; 21 } 22 public Id() {} 23 24 27 public String getCustomerId() { 28 return customerId; 29 } 30 33 public void setCustomerId(String customerId) { 34 this.customerId = customerId; 35 } 36 39 public int getOrderNumber() { 40 return orderNumber; 41 } 42 45 public void setOrderNumber(int orderNumber) { 46 this.orderNumber = orderNumber; 47 } 48 public int hashCode() { 49 return customerId.hashCode() + orderNumber; 50 } 51 public boolean equals(Object other) { 52 if (other instanceof Id) { 53 Id that = (Id) other; 54 return that.customerId.equals(this.customerId) && 55 that.orderNumber == this.orderNumber; 56 } 57 else { 58 return false; 59 } 60 } 61 } 62 63 private Id id = new Id(); 64 private Calendar orderDate; 65 private Customer customer; 66 private Collection lineItems = new ArrayList (); 67 private BigDecimal total; 68 69 public Order(Customer customer) { 70 this.customer = customer; 71 this.id.customerId = customer.getCustomerId(); 72 this.id.orderNumber = customer.getOrders().size(); 73 customer.getOrders().add(this); 74 } 75 76 public Order() {} 77 78 81 public Customer getCustomer() { 82 return customer; 83 } 84 87 public void setCustomer(Customer customer) { 88 this.customer = customer; 89 } 90 93 public Collection getLineItems() { 94 return lineItems; 95 } 96 99 public void setLineItems(Collection lineItems) { 100 this.lineItems = lineItems; 101 } 102 105 public Calendar getOrderDate() { 106 return orderDate; 107 } 108 111 public void setOrderDate(Calendar orderDate) { 112 this.orderDate = orderDate; 113 } 114 117 public BigDecimal getTotal() { 118 return total; 119 } 120 123 public void setTotal(BigDecimal total) { 124 this.total = total; 125 } 126 129 public Id getId() { 130 return id; 131 } 132 135 public void setId(Id id) { 136 this.id = id; 137 } 138 139 public LineItem generateLineItem( Product product, int quantity ) { 140 LineItem li = new LineItem( this, product ); 141 li.setQuantity( quantity ); 142 lineItems.add( li ); 143 return li; 144 } 145 } 146 | Popular Tags |