summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java
blob: 447cc75ace185f462dbb59aacc61e2d8b16467d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package examples.shop.impl.entity;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;


/**
 * A line item entity is a quantity of a single product. 
 * 
 * Instances of this class are used for both in-memory represenation 
 * of carts and the persistent representation of orders in 
 * the database 
 */
@Entity
public class LineItem implements java.io.Serializable {

    private String id;
    
    /** the product */
    private Product product;

    /** Number of items */
    private int quantity;

    /** Amount of the discount for each item */
    private double discount;

    /**
     * Constructor
     * @param productitem
     * @param number of items
     * @Param discount for each item 
     */
    public LineItem(Product productItem, int quantity, double discount) {
        System.out.println("LineItem(...) called");
        this.product = productItem;
        this.quantity = quantity;
        this.discount = discount;
    }

    public LineItem() {
        System.out.println("New LineItem created.");
    }
    
    /**
     * The id number of this line item. This is our primary key as well.
     * 
     * @return the id
     */
    @Id
    public String getId() {
        return id;
    }

    /**
     * Sets the id
     */
    public void setId(String id) {
        this.id = id;
    }


    /**
     * @return the productitem.
     * productitem has product id, name of the product and description
     */
    @OneToOne
    public Product getProduct() {
        System.out.println("LineItem.getProduct() called.");
        return product;
    }

    /**
     * @param productItem.
     */
    public void setProduct(Product product) {
        System.out.println("LineItem.setProduct() called.");
        this.product = product;
    }

    /**
     * @return the number of items.
     */
    public int getQuantity() {
        System.out.println("LineItem.getQuantity() called.");
        return quantity;
    }

    /**
     * @param the number of items.
     */
    public void setQuantity(int quantity) {
        System.out.println("LineItem.setQuantity() called.");
        this.quantity = quantity;
    }

    /**
     * @return the base price.  The base price is the
     * product's price times the quantity ordered.  This
     * figure does not take discounts into consideration.
     */
    public double basePrice() {
        System.out.println("LineItem.getBasePrice() called.");
        return quantity * product.getBasePrice();
    }

    /**
     * @return the discount that the customer gets on
     * this order.
     *
     * Note: The discount is a whole number, not
     *       a percentage discount.
     */
    public double getDiscount() {
        System.out.println("LineItem.getDiscount() called.");
        return discount;
    }

    /**
     * @param the discount that the customer gets on
     * this order.
     *
     * Note: The discount is a whole number, not
     *       a percentage discount.
     */
    public void setDiscount(double discount) {
        System.out.println("LineItem.setDiscount(" + discount + ") called.");
        this.discount = discount;
    }

}