2 * Copyright (C) 2015 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.jshopcore.model.basket.items;
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;
33 * A general basket item
35 * @author Roland Haeder<roland@mxchange.org>
37 @Entity (name = "basket_items")
38 @Table (name = "basket_items")
39 public class BasketItem extends BaseItem implements AddableBasketItem {
44 private static final long serialVersionUID = 52_749_158_492_581_578L;
49 @Basic (optional = false)
50 @Column (name = "amount", nullable = false, length = 20)
54 * Entry itemId (from database backend)
57 @GeneratedValue (strategy = GenerationType.IDENTITY)
58 @Column (name = "item_id", nullable = false, updatable = false)
64 @Basic (optional = false)
65 @Column (name = "item_type", nullable = false, length = 20)
66 private String itemType;
71 @JoinColumn (name = "product_id", updatable = false)
72 @OneToOne (targetEntity = GenericProduct.class)
73 private Product product;
78 public BasketItem () {
82 * Constructor for an item from given Product instance
84 * @param product Product instance
86 public BasketItem (final Product product) {
87 // Call default constructor
90 // product must not be null
91 if (null == product) {
93 throw new NullPointerException("product is null"); //NOI18N
96 // Copy all neccessary values
97 this.itemType = "product"; //NOI18N
100 this.product = product;
104 * Constructor for an item from given Product instance and amount.
106 * @param product Product instance
107 * @param amount Ordered amount
109 public BasketItem (final Product product, final Long amount) {
113 // amount must not be null
114 if (null == amount) {
116 throw new NullPointerException("amount is null"); //NOI18N
120 this.amount = amount;
124 public Long getAmount () {
129 public void setAmount (final Long amount) {
130 this.amount = amount;
134 public Long getItemId () {
139 public void setItemId (final Long itemId) {
140 this.itemId = itemId;
144 public String getItemType () {
145 return this.itemType;
149 public void setItemType (final String itemType) {
150 this.itemType = itemType;
154 public Product getProduct () {
159 public void setProduct (final Product product) {
160 this.product = product;