]> git.mxchange.org Git - jshop-core.git/blob - src/org/mxchange/jshopcore/model/order/items/OrderItem.java
c687fd07ffe7344dc6977d2ad069c4b4c84ecfb4
[jshop-core.git] / src / org / mxchange / jshopcore / model / order / items / OrderItem.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.order.items;
18
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;
36
37 /**
38  * A general basket item
39  * <p>
40  * @author Roland Haeder<roland@mxchange.org>
41  */
42 @Entity (name = "ordered_item")
43 @Table (
44                 name = "ordered_items",
45                 indexes = {
46                         @Index (name = "product", columnList = "order_product_id")
47                 }
48 )
49 @SuppressWarnings ("PersistenceUnitPresent")
50 public class OrderItem extends BaseItem implements AddableBasketItem {
51
52         /**
53          * Serial number
54          */
55         @Transient
56         private static final long serialVersionUID = 44_189_562_738_723_581L;
57
58         /**
59          * Entry id (from database backend)
60          */
61         @Id
62         @GeneratedValue (strategy = GenerationType.IDENTITY)
63         @Column (name = "order_id", nullable = false, length = 20)
64         private Long itemId;
65
66         /**
67          * Item type
68          */
69         @Basic (optional = false)
70         @Column (name = "order_item_type", length = 20)
71         private String itemType;
72
73         /**
74          * Item amount
75          */
76         @Basic (optional = false)
77         @Column (name = "order_amount", nullable = false)
78         private Long orderedAmount;
79
80         /**
81          * Product instance
82          */
83         @JoinColumn (name = "order_product_id", updatable = false)
84         @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH)
85         private Product product;
86
87         /**
88          * Default constructor
89          */
90         public OrderItem () {
91         }
92
93         @Override
94         public boolean equals (final Object object) {
95                 if (this == object) {
96                         return true;
97                 } else if (null == object) {
98                         return false;
99                 } else if (this.getClass() != object.getClass()) {
100                         return false;
101                 }
102
103                 final AddableBasketItem item = (AddableBasketItem) object;
104
105                 if (!Objects.equals(this.itemType, item.getItemType())) {
106                         return false;
107                 } else if (!Objects.equals(this.orderedAmount, item.getOrderedAmount())) {
108                         return false;
109                 }
110
111                 return Objects.equals(this.product, item.getItemProduct());
112         }
113
114         @Override
115         public int hashCode () {
116                 int hash = 3;
117                 hash = 53 * hash + Objects.hashCode(this.getItemType());
118                 hash = 53 * hash + Objects.hashCode(this.getOrderedAmount());
119                 hash = 53 * hash + Objects.hashCode(this.getItemProduct());
120                 return hash;
121         }
122
123         @Override
124         public Long getItemId () {
125                 return this.itemId;
126         }
127
128         @Override
129         public void setItemId (final Long itemId) {
130                 this.itemId = itemId;
131         }
132
133         @Override
134         public Product getItemProduct () {
135                 return this.product;
136         }
137
138         @Override
139         public void setItemProduct (final Product product) {
140                 this.product = product;
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 Long getOrderedAmount () {
155                 return this.orderedAmount;
156         }
157
158         @Override
159         public void setOrderedAmount (final Long orderedAmount) {
160                 this.orderedAmount = orderedAmount;
161         }
162
163 }