]> git.mxchange.org Git - jshop-core.git/blob - src/org/mxchange/jshopcore/model/order/ShopOrder.java
Continued a bit:
[jshop-core.git] / src / org / mxchange / jshopcore / model / order / ShopOrder.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
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;
18
19 import java.util.Calendar;
20 import java.util.List;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.mxchange.jcustomercore.model.customer.Customer;
36 import org.mxchange.jshopcore.model.basket.AddableBasketItem;
37
38 /**
39  * An entity class for shop orders
40  * <p>
41  * @author Roland Häder<roland@mxchange.org>
42  */
43 @Entity (name = "orders")
44 @Table (name = "orders")
45 @SuppressWarnings ("PersistenceUnitPresent")
46 public class ShopOrder implements Orderable {
47
48         /**
49          * Serial number
50          */
51         @Transient
52         private static final long serialVersionUID = 19_728_938_459_834L;
53
54         /**
55          * Access key
56          */
57         @Basic (optional = false)
58         @Column (name = "access_key", length = 100, nullable = false, unique = true)
59         private String accessKey;
60
61         /**
62          * Customer instance
63          */
64         @JoinColumn (name = "customer_id", nullable = false, updatable = false)
65         @OneToOne (targetEntity = Customer.class, cascade = CascadeType.REFRESH, optional = false)
66         private Customer customer;
67
68         /**
69          * Created timestamp
70          */
71         @Basic (optional = false)
72         @Temporal (TemporalType.TIMESTAMP)
73         @Column (name = "order_created", nullable = false)
74         private Calendar orderCreated;
75
76         /**
77          * Order orderId
78          */
79         @Id
80         @GeneratedValue (strategy = GenerationType.IDENTITY)
81         @Column (name = "order_id", length = 20)
82         private Long orderId;
83
84         /**
85          * Item list, don't save this
86          */
87         @Transient
88         private List<AddableBasketItem> orderedItems;
89
90         @Override
91         public boolean equals (final Object object) {
92                 if (this == object) {
93                         return true;
94                 } else if (null == object) {
95                         return false;
96                 } else if (this.getClass() != object.getClass()) {
97                         return false;
98                 }
99
100                 final Orderable other = (Orderable) object;
101
102                 if (!Objects.equals(this.getAccessKey(), other.getAccessKey())) {
103                         return false;
104                 } else if (!Objects.equals(this.getCustomer(), other.getCustomer())) {
105                         return false;
106                 } else if (!Objects.equals(this.getOrderId(), other.getOrderId())) {
107                         return false;
108                 } else if (!Objects.equals(this.getOrderedItems(), other.getOrderedItems())) {
109                         return false;
110                 }
111
112                 return true;
113         }
114
115         @Override
116         public int hashCode () {
117                 int hash = 7;
118                 hash = 61 * hash + Objects.hashCode(this.getAccessKey());
119                 hash = 61 * hash + Objects.hashCode(this.getCustomer());
120                 hash = 61 * hash + Objects.hashCode(this.getOrderId());
121                 hash = 61 * hash + Objects.hashCode(this.getOrderedItems());
122                 return hash;
123         }
124
125         @Override
126         public String getAccessKey () {
127                 return this.accessKey;
128         }
129
130         @Override
131         public void setAccessKey (final String accessKey) {
132                 this.accessKey = accessKey;
133         }
134
135         @Override
136         public Customer getCustomer () {
137                 return this.customer;
138         }
139
140         @Override
141         public void setCustomer (final Customer customer) {
142                 this.customer = customer;
143         }
144
145         @Override
146         public Calendar getOrderCreated () {
147                 return this.orderCreated;
148         }
149
150         @Override
151         public void setOrderCreated (final Calendar orderCreated) {
152                 this.orderCreated = orderCreated;
153         }
154
155         @Override
156         public Long getOrderId () {
157                 return this.orderId;
158         }
159
160         @Override
161         public void setOrderId (final Long orderId) {
162                 this.orderId = orderId;
163         }
164
165         @Override
166         public List<AddableBasketItem> getOrderedItems () {
167                 return this.orderedItems;
168         }
169
170         @Override
171         public void setOrderedItems (final List<AddableBasketItem> orderedItems) {
172                 this.orderedItems = orderedItems;
173         }
174
175 }