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.order.items;
19 import java.util.Objects;
20 import javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.Index;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.OneToOne;
30 import javax.persistence.Table;
31 import javax.persistence.Transient;
32 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
33 import org.mxchange.jshopcore.model.basket.items.BaseItem;
34 import org.mxchange.jshopcore.model.product.GenericProduct;
35 import org.mxchange.jshopcore.model.product.Product;
38 * A general basket item
40 * @author Roland Haeder<roland@mxchange.org>
42 @Entity (name = "ordered_item")
44 name = "ordered_items",
46 @Index (name = "product", columnList = "order_product_id")
49 @SuppressWarnings ("PersistenceUnitPresent")
50 public class OrderItem extends BaseItem implements AddableBasketItem {
56 private static final long serialVersionUID = 44_189_562_738_723_581L;
59 * Entry id (from database backend)
62 @GeneratedValue (strategy = GenerationType.IDENTITY)
63 @Column (name = "order_id", nullable = false, length = 20)
69 @Basic (optional = false)
70 @Column (name = "order_item_type", length = 20)
71 private String itemType;
76 @Basic (optional = false)
77 @Column (name = "order_amount", nullable = false)
78 private Long orderedAmount;
83 @JoinColumn (name = "order_product_id", updatable = false)
84 @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH)
85 private Product product;
94 public boolean equals (final Object object) {
97 } else if (null == object) {
99 } else if (this.getClass() != object.getClass()) {
103 final AddableBasketItem item = (AddableBasketItem) object;
105 if (!Objects.equals(this.itemType, item.getItemType())) {
107 } else if (!Objects.equals(this.orderedAmount, item.getOrderedAmount())) {
111 return Objects.equals(this.product, item.getItemProduct());
115 public int hashCode () {
117 hash = 53 * hash + Objects.hashCode(this.getItemType());
118 hash = 53 * hash + Objects.hashCode(this.getOrderedAmount());
119 hash = 53 * hash + Objects.hashCode(this.getItemProduct());
124 public Long getItemId () {
129 public void setItemId (final Long itemId) {
130 this.itemId = itemId;
134 public Product getItemProduct () {
139 public void setItemProduct (final Product product) {
140 this.product = product;
144 public String getItemType () {
145 return this.itemType;
149 public void setItemType (final String itemType) {
150 this.itemType = itemType;
154 public Long getOrderedAmount () {
155 return this.orderedAmount;
159 public void setOrderedAmount (final Long orderedAmount) {
160 this.orderedAmount = orderedAmount;