]> git.mxchange.org Git - jshop-core.git/blob - src/org/mxchange/jshopcore/model/basket/items/BasketItem.java
resorted members
[jshop-core.git] / src / org / mxchange / jshopcore / model / basket / items / BasketItem.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jshopcore.model.basket.items;
18
19 import javax.persistence.Basic;
20 import javax.persistence.CascadeType;
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.GeneratedValue;
24 import javax.persistence.GenerationType;
25 import javax.persistence.Id;
26 import javax.persistence.JoinColumn;
27 import javax.persistence.OneToOne;
28 import javax.persistence.Table;
29 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
30 import org.mxchange.jshopcore.model.product.GenericProduct;
31 import org.mxchange.jshopcore.model.product.Product;
32
33 /**
34  * A general basket item
35  * <p>
36  * @author Roland Haeder<roland@mxchange.org>
37  */
38 @Entity (name = "basket_items")
39 @Table (name = "basket_items")
40 public class BasketItem extends BaseItem implements AddableBasketItem {
41
42         /**
43          * Serial number
44          */
45         private static final long serialVersionUID = 52_749_158_492_581_578L;
46
47         /**
48          * Entry itemId (from database backend)
49          */
50         @Id
51         @GeneratedValue (strategy = GenerationType.IDENTITY)
52         @Column (name = "item_id", nullable = false, updatable = false)
53         private Long itemId;
54
55         /**
56          * Product instance
57          */
58         @JoinColumn (name = "product_id", updatable = false)
59         @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.MERGE)
60         private Product itemProduct;
61
62         /**
63          * Item type
64          */
65         @Basic (optional = false)
66         @Column (name = "item_type", nullable = false, length = 20)
67         private String itemType;
68
69         /**
70          * Item orderedAmount
71          */
72         @Basic (optional = false)
73         @Column (name = "ordered_amount", nullable = false, length = 20)
74         private Long orderedAmount;
75
76         /**
77          * Default constructor
78          */
79         public BasketItem () {
80         }
81
82         /**
83          * Constructor for an item from given Product instance
84          * <p>
85          * @param product Product instance
86          */
87         public BasketItem (final Product product) {
88                 // Call default constructor
89                 this();
90
91                 // itemProduct must not be null
92                 if (null == product) {
93                         // Abort here
94                         throw new NullPointerException("product is null"); //NOI18N
95                 }
96
97                 // Copy all neccessary values
98                 this.itemType = "product"; //NOI18N
99
100                 // Copy instance
101                 this.itemProduct = product;
102         }
103
104         /**
105          * Constructor for an item from given Product instance and orderedAmount.
106          * <p>
107          * @param product Product instance
108          * @param amount Ordered orderedAmount
109          */
110         public BasketItem (final Product product, final Long amount) {
111                 // Other constructor
112                 this(product);
113
114                 // orderedAmount must not be null
115                 if (null == amount) {
116                         // Abort here
117                         throw new NullPointerException("amount is null"); //NOI18N
118                 }
119
120                 // Set orderedAmount
121                 this.orderedAmount = amount;
122         }
123
124         @Override
125         public Long getItemId () {
126                 return this.itemId;
127         }
128
129         @Override
130         public void setItemId (final Long itemId) {
131                 this.itemId = itemId;
132         }
133
134         @Override
135         public Product getItemProduct () {
136                 return this.itemProduct;
137         }
138
139         @Override
140         public void setItemProduct (final Product itemProduct) {
141                 this.itemProduct = itemProduct;
142         }
143
144         @Override
145         public String getItemType () {
146                 return this.itemType;
147         }
148
149         @Override
150         public void setItemType (final String itemType) {
151                 this.itemType = itemType;
152         }
153
154         @Override
155         public Long getOrderedAmount () {
156                 return this.orderedAmount;
157         }
158
159         @Override
160         public void setOrderedAmount (final Long orderedAmount) {
161                 this.orderedAmount = orderedAmount;
162         }
163 }