2 * Copyright (C) 2016 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.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;
34 * A general basket item
36 * @author Roland Haeder<roland@mxchange.org>
38 @Entity (name = "basket_items")
39 @Table (name = "basket_items")
40 public class BasketItem extends BaseItem implements AddableBasketItem {
45 private static final long serialVersionUID = 52_749_158_492_581_578L;
48 * Entry itemId (from database backend)
51 @GeneratedValue (strategy = GenerationType.IDENTITY)
52 @Column (name = "item_id", nullable = false, updatable = false)
58 @JoinColumn (name = "product_id", updatable = false)
59 @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.MERGE)
60 private Product itemProduct;
65 @Basic (optional = false)
66 @Column (name = "item_type", nullable = false, length = 20)
67 private String itemType;
72 @Basic (optional = false)
73 @Column (name = "ordered_amount", nullable = false, length = 20)
74 private Long orderedAmount;
79 public BasketItem () {
83 * Constructor for an item from given Product instance
85 * @param product Product instance
87 public BasketItem (final Product product) {
88 // Call default constructor
91 // itemProduct must not be null
92 if (null == product) {
94 throw new NullPointerException("product is null"); //NOI18N
97 // Copy all neccessary values
98 this.itemType = "product"; //NOI18N
101 this.itemProduct = product;
105 * Constructor for an item from given Product instance and orderedAmount.
107 * @param product Product instance
108 * @param amount Ordered orderedAmount
110 public BasketItem (final Product product, final Long amount) {
114 // orderedAmount must not be null
115 if (null == amount) {
117 throw new NullPointerException("amount is null"); //NOI18N
121 this.orderedAmount = amount;
125 public Long getItemId () {
130 public void setItemId (final Long itemId) {
131 this.itemId = itemId;
135 public Product getItemProduct () {
136 return this.itemProduct;
140 public void setItemProduct (final Product itemProduct) {
141 this.itemProduct = itemProduct;
145 public String getItemType () {
146 return this.itemType;
150 public void setItemType (final String itemType) {
151 this.itemType = itemType;
155 public Long getOrderedAmount () {
156 return this.orderedAmount;
160 public void setOrderedAmount (final Long orderedAmount) {
161 this.orderedAmount = orderedAmount;