]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jshopcore/model/basket/items/BasketItem.java
renamed even more fields/attributes
[jproduct-core.git] / src / org / mxchange / jshopcore / model / basket / items / BasketItem.java
1 /*
2  * Copyright (C) 2015 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.Column;
21 import javax.persistence.Entity;
22 import javax.persistence.GeneratedValue;
23 import javax.persistence.GenerationType;
24 import javax.persistence.Id;
25 import javax.persistence.JoinColumn;
26 import javax.persistence.OneToOne;
27 import javax.persistence.Table;
28 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
29 import org.mxchange.jshopcore.model.product.GenericProduct;
30 import org.mxchange.jshopcore.model.product.Product;
31
32 /**
33  * A general basket item
34  *
35  * @author Roland Haeder<roland@mxchange.org>
36  */
37 @Entity (name = "basket_items")
38 @Table (name = "basket_items")
39 public class BasketItem extends BaseItem implements AddableBasketItem {
40
41         /**
42          * Serial number
43          */
44         private static final long serialVersionUID = 52_749_158_492_581_578L;
45
46         /**
47          * Item orderedAmount
48          */
49         @Basic (optional = false)
50         @Column (name = "ordered_amount", nullable = false, length = 20)
51         private Long orderedAmount;
52
53         /**
54          * Entry itemId (from database backend)
55          */
56         @Id
57         @GeneratedValue (strategy = GenerationType.IDENTITY)
58         @Column (name = "item_id", nullable = false, updatable = false)
59         private Long itemId;
60
61         /**
62          * Item type
63          */
64         @Basic (optional = false)
65         @Column (name = "item_type", nullable = false, length = 20)
66         private String itemType;
67
68         /**
69          * Product instance
70          */
71         @JoinColumn (name = "product_id", updatable = false)
72         @OneToOne (targetEntity = GenericProduct.class)
73         private Product itemProduct;
74
75         /**
76          * Default constructor
77          */
78         public BasketItem () {
79         }
80
81         /**
82          * Constructor for an item from given Product instance
83          *
84          * @param product Product instance
85          */
86         public BasketItem (final Product product) {
87                 // Call default constructor
88                 this();
89
90                 // itemProduct must not be null
91                 if (null == product) {
92                         // Abort here
93                         throw new NullPointerException("product is null"); //NOI18N
94                 }
95
96                 // Copy all neccessary values
97                 this.itemType = "product"; //NOI18N
98
99                 // Copy instance
100                 this.itemProduct = product;
101         }
102
103         /**
104          * Constructor for an item from given Product instance and orderedAmount.
105          *
106          * @param product Product instance
107          * @param amount Ordered orderedAmount
108          */
109         public BasketItem (final Product product, final Long amount) {
110                 // Other constructor
111                 this(product);
112
113                 // orderedAmount must not be null
114                 if (null == amount) {
115                         // Abort here
116                         throw new NullPointerException("amount is null"); //NOI18N
117                 }
118
119                 // Set orderedAmount
120                 this.orderedAmount = amount;
121         }
122
123         @Override
124         public Long getOrderedAmount () {
125                 return this.orderedAmount;
126         }
127
128         @Override
129         public void setOrderedAmount (final Long orderedAmount) {
130                 this.orderedAmount = orderedAmount;
131         }
132
133         @Override
134         public Long getItemId () {
135                 return this.itemId;
136         }
137
138         @Override
139         public void setItemId (final Long itemId) {
140                 this.itemId = itemId;
141         }
142
143         @Override
144         public String getItemType () {
145                 return this.itemType;
146         }
147
148         @Override
149         public void setItemType (final String itemType) {
150                 this.itemType = itemType;
151         }
152
153         @Override
154         public Product getItemProduct () {
155                 return this.itemProduct;
156         }
157
158         @Override
159         public void setItemProduct (final Product itemProduct) {
160                 this.itemProduct = itemProduct;
161         }
162 }