1 package xpetstore.domain.order.ejb; 2 3 import javax.annotation.EJB; 4 import javax.ejb.EJBException ; 5 import javax.persistence.CascadeType; 6 import javax.persistence.Column; 7 import javax.persistence.Entity; 8 import javax.persistence.Id; 9 import javax.persistence.JoinColumn; 10 import javax.persistence.ManyToOne; 11 import javax.persistence.Table; 12 13 import xpetstore.domain.catalog.ejb.Item; 14 15 import xpetstore.util.uidgen.ejb.UIDGenerator; 16 17 18 43 @Entity(name = "OrderItem") 44 @Table(name = "T_ORDER_ITEM") 45 public class OrderItem 46 { 47 48 public static final String COUNTER_NAME = "OrderItem"; 49 50 private Integer orderItemUId; 51 private int quantity; 52 private double unitPrice; 53 private Item item; 54 55 public OrderItem() 56 { 57 58 } 59 60 public OrderItem( int quantity, double unitPrice ) 61 { 62 setQuantity( quantity ); 63 setUnitPrice( unitPrice ); 64 } 65 66 71 public double calculateSubTotal( ) 72 { 73 return Math.max( getQuantity( ) * getUnitPrice( ), 0 ); 74 } 75 76 84 @Id 85 @GeneratedValue(strategy= GenerationType.AUTO) 86 @Column(name="orderItemUId") 87 public Integer getOrderItemUId( ) 88 { 89 return orderItemUId; 90 } 91 92 public void setOrderItemUId( Integer orderItemUId ) 93 { 94 this.orderItemUId = orderItemUId; 95 } 96 97 101 @Column(name="quantity") 102 public int getQuantity( ) 103 { 104 return quantity; 105 } 106 107 public void setQuantity( int quantity ) 108 { 109 this.quantity = quantity; 110 } 111 112 116 @Column(name="unitPrice") 117 public double getUnitPrice( ) 118 { 119 return unitPrice; 120 } 121 122 public void setUnitPrice( double unitPrice ) 123 { 124 this.unitPrice = unitPrice; 125 } 126 127 150 @ManyToOne(targetEntity=Item.class, cascade={CascadeType.ALL}) 151 @JoinColumn(name="itemId_fk") 152 public Item getItem( ) 153 { 154 return item; 155 } 156 157 160 public void setItem( Item item ) 161 { 162 this.item = item; 163 } 164 } 165 | Popular Tags |