| 1 package xpetstore.domain.order.ejb; 2 3 import java.util.Collection ; 4 import java.util.Date ; 5 import java.util.Iterator ; 6 7 import javax.ejb.CreateException ; 8 import javax.ejb.EJBException ; 9 import javax.ejb.FinderException ; 10 11 import javax.annotation.EJB; 12 13 import javax.naming.NamingException ; 14 import javax.persistence.CascadeType; 15 import javax.persistence.Column; 16 import javax.persistence.Entity; 17 import javax.persistence.EntityManager; 18 import javax.persistence.Id; 19 import javax.persistence.JoinColumn; 20 import javax.persistence.ManyToOne; 21 import javax.persistence.OneToMany; 22 import javax.persistence.PersistenceContext; 23 import javax.persistence.Table; 24 25 import xpetstore.domain.customer.ejb.Customer; 26 import xpetstore.domain.catalog.ejb.Item; 27 28 import xpetstore.util.uidgen.ejb.*; 29 30 62 @Entity(name = "Order") 63 @Table(name = "T_ORDER") 64 public class Order 65 { 66 public static final String COUNTER_NAME = "Order"; 67 68 private Integer orderUid; 69 private Date orderDate; 70 private String status; 71 private String street1; 72 private String street2; 73 private String city; 74 private String state; 75 private String zipcode; 76 private String country; 77 private String creditCardNumber; 78 private String creditCardType; 79 private String creditCardExpiryDate; 80 private Collection orderItems; 81 private Customer customer; 82 83 public Order() 84 { 85 } 86 87 90 public void addOrderItem( OrderItem orderItem ) 91 { 92 if (orderItems == null) 93 orderItems = new java.util.ArrayList (); 94 95 orderItems.add(orderItem); 96 } 97 98 101 public void changeStatus( String status ) 102 { 103 setStatus( status ); 104 } 105 106 109 public double calculateTotal( ) 110 { 111 double total = 0; 112 Iterator it = getOrderItems( ).iterator( ); 113 while ( it.hasNext( ) ) 114 { 115 total += ( ( OrderItem ) it.next( ) ).calculateSubTotal( ); 116 } 117 118 return total; 119 } 120 121 128 @Id 129 @GeneratedValue(strategy= GenerationType.SEQUENCE) 130 @Column(name="orderUId") 131 public Integer getOrderUId( ) 132 { 133 return orderUid; 134 } 135 136 public void setOrderUId( Integer orderUId ) 137 { 138 this.orderUid = orderUId; 139 } 140 141 144 @Column(name="orderDate") 145 public Date getOrderDate( ) 146 { 147 return orderDate; 148 } 149 150 public void setOrderDate( Date orderDate ) 151 { 152 this.orderDate = orderDate; 153 } 154 155 159 @Column(name="status", length=25) 160 public String getStatus( ) 161 { 162 return status; 163 } 164 165 public void setStatus( String status ) 166 { 167 this.status = status; 168 } 169 170 174 @Column(name="street1", length=50) 175 public String getStreet1( ) 176 { 177 return street1; 178 } 179 180 public void setStreet1( java.lang.String street1 ) 181 { 182 this.street1 = street1; 183 } 184 185 189 @Column(name="street2", length=50) 190 public String getStreet2( ) 191 { 192 return street2; 193 } 194 195 public void setStreet2( String street2 ) 196 { 197 this.street2 = street2; 198 } 199 200 204 @Column(name="city", length=25) 205 public java.lang.String getCity( ) 206 { 207 return city; 208 } 209 210 public void setCity( String city ) 211 { 212 this.city = city; 213 } 214 215 219 @Column(name="state", length=3) 220 public String getState( ) 221 { 222 return state; 223 } 224 225 public void setState( String state ) 226 { 227 this.state = state; 228 } 229 230 234 @Column(name="zipcode", length=10) 235 public String getZipcode( ) 236 { 237 return zipcode; 238 } 239 240 public void setZipcode( String zipcode ) 241 { 242 this.zipcode = zipcode; 243 } 244 245 249 @Column(name="country", length=10) 250 public java.lang.String getCountry( ) 251 { 252 return country; 253 } 254 255 public void setCountry( String country ) 256 { 257 this.country = country; 258 } 259 260 264 @Column(name="creditCardNumber", length=25) 265 public String getCreditCardNumber( ) 266 { 267 return creditCardNumber; 268 } 269 270 public void setCreditCardNumber( String creditCardNumber ) 271 { 272 this.creditCardNumber = creditCardNumber; 273 } 274 275 279 @Column(name="creditCardType", length=25) 280 public String getCreditCardType( ) 281 { 282 return creditCardType; 283 } 284 285 public void setCreditCardType( String creditCardType ) 286 { 287 this.creditCardType = creditCardType; 288 } 289 290 294 @Column(name="creditCardExpiryDate", length=10) 295 public String getCreditCardExpiryDate( ) 296 { 297 return creditCardExpiryDate; 298 } 299 300 public void setCreditCardExpiryDate( String creditCardExpiryDate ) 301 { 302 this.creditCardExpiryDate = creditCardExpiryDate; 303 } 304 305 315 @ManyToOne(cascade={CascadeType.ALL}) 316 @JoinColumn(name="CUSTOMER_ID") 317 public Customer getCustomer( ) 318 { 319 return customer; 320 } 321 322 325 public void setCustomer( Customer customer ) 326 { 327 this.customer = customer; 328 } 329 330 340 @OneToMany(targetEntity=OrderItem.class, cascade={CascadeType.ALL}) 341 @JoinColumn(name="ORDER_ID") 342 public Collection getOrderItems( ) 343 { 344 return orderItems; 345 } 346 347 public void setOrderItems( Collection orderItems ) 348 { 349 this.orderItems = orderItems; 350 } 351 352 } 353 | Popular Tags |