KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > entity > bean > Order


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.entity.bean;
8
9 import javax.persistence.CascadeType;
10 import javax.persistence.Entity;
11 import javax.persistence.FetchType;
12 import javax.persistence.GeneratorType;
13 import javax.persistence.Id;
14 import javax.persistence.OneToMany;
15 import javax.persistence.Table;
16 import javax.persistence.Id;
17 import javax.persistence.CascadeType;
18 import javax.persistence.FetchType;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21
22 @Entity
23 @Table(name = "PURCHASE_ORDER")
24 public class Order implements java.io.Serializable JavaDoc
25 {
26    private int id;
27    private double total;
28    private Collection JavaDoc<LineItem> lineItems;
29
30    @Id(generate = GeneratorType.AUTO)
31    public int getId()
32    {
33       return id;
34    }
35
36    public void setId(int id)
37    {
38       this.id = id;
39    }
40
41    public double getTotal()
42    {
43       return total;
44    }
45
46    public void setTotal(double total)
47    {
48       this.total = total;
49    }
50
51    public void addPurchase(String JavaDoc product, int quantity, double price)
52    {
53       if (lineItems == null) lineItems = new ArrayList JavaDoc<LineItem>();
54       LineItem item = new LineItem();
55       item.setOrder(this);
56       item.setProduct(product);
57       item.setQuantity(quantity);
58       item.setSubtotal(quantity * price);
59       lineItems.add(item);
60       total += quantity * price;
61    }
62
63    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="order")
64    public Collection JavaDoc<LineItem> getLineItems()
65    {
66       return lineItems;
67    }
68
69    public void setLineItems(Collection JavaDoc<LineItem> lineItems)
70    {
71       this.lineItems = lineItems;
72    }
73 }
74
Popular Tags