1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.domain.jpetstore;
17
18 import java.io.Serializable;
19 import java.math.BigDecimal;
20
21 public class LineItem implements Serializable {
22
23 private static final long serialVersionUID = 1L;
24
25 private int orderId;
26 private int lineNumber;
27 private int quantity;
28 private String itemId;
29 private BigDecimal unitPrice;
30 private Item item;
31 private BigDecimal total;
32
33 public LineItem() {
34 }
35
36 public LineItem(int lineNumber, CartItem cartItem) {
37 this.lineNumber = lineNumber;
38 this.quantity = cartItem.getQuantity();
39 this.itemId = cartItem.getItem().getItemId();
40 this.unitPrice = cartItem.getItem().getListPrice();
41 this.item = cartItem.getItem();
42 }
43
44 public int getOrderId() {
45 return orderId;
46 }
47
48 public void setOrderId(int orderId) {
49 this.orderId = orderId;
50 }
51
52 public int getLineNumber() {
53 return lineNumber;
54 }
55
56 public void setLineNumber(int lineNumber) {
57 this.lineNumber = lineNumber;
58 }
59
60 public String getItemId() {
61 return itemId;
62 }
63
64 public void setItemId(String itemId) {
65 this.itemId = itemId;
66 }
67
68 public BigDecimal getUnitPrice() {
69 return unitPrice;
70 }
71
72 public void setUnitPrice(BigDecimal unitprice) {
73 this.unitPrice = unitprice;
74 }
75
76 public BigDecimal getTotal() {
77 return total;
78 }
79
80 public Item getItem() {
81 return item;
82 }
83
84 public void setItem(Item item) {
85 this.item = item;
86 calculateTotal();
87 }
88
89 public int getQuantity() {
90 return quantity;
91 }
92
93 public void setQuantity(int quantity) {
94 this.quantity = quantity;
95 calculateTotal();
96 }
97
98 private void calculateTotal() {
99 if (item != null && item.getListPrice() != null) {
100 total = item.getListPrice().multiply(new BigDecimal(quantity));
101 } else {
102 total = null;
103 }
104 }
105
106 }