]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jshopcore/model/order/ShopOrder.java
ShopCustomer is to generic, better project-specific. And this is now interface-based...
[jproduct-core.git] / src / org / mxchange / jshopcore / model / order / ShopOrder.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;
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 Haeder<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         private static final long serialVersionUID = 19_728_938_459_834L;
52
53         /**
54          * Access key
55          */
56         @Basic (optional = false)
57         @Column (name = "access_key", length = 100, nullable = false, unique = true)
58         private String accessKey;
59
60         /**
61          * Customer instance
62          */
63         @JoinColumn (name = "customer_id", nullable = false, updatable = false)
64         @OneToOne (targetEntity = Customer.class, cascade = CascadeType.REFRESH, optional = false)
65         private Customer customer;
66
67         /**
68          * Created timestamp
69          */
70         @Basic (optional = false)
71         @Temporal (TemporalType.TIMESTAMP)
72         @Column (name = "order_created", nullable = false)
73         private Calendar orderCreated;
74
75         /**
76          * Order orderId
77          */
78         @Id
79         @GeneratedValue (strategy = GenerationType.IDENTITY)
80         @Column (name = "order_id", length = 20)
81         private Long orderId;
82
83         /**
84          * Item list, don't save this
85          */
86         @Transient
87         private List<AddableBasketItem> orderedItems;
88
89         @Override
90         public boolean equals (final Object object) {
91                 if (this == object) {
92                         return true;
93                 } else if (null == object) {
94                         return false;
95                 } else if (this.getClass() != object.getClass()) {
96                         return false;
97                 }
98
99                 final Orderable other = (Orderable) object;
100
101                 if (!Objects.equals(this.getAccessKey(), other.getAccessKey())) {
102                         return false;
103                 } else if (!Objects.equals(this.getCustomer(), other.getCustomer())) {
104                         return false;
105                 } else if (!Objects.equals(this.getOrderId(), other.getOrderId())) {
106                         return false;
107                 } else if (!Objects.equals(this.getOrderedItems(), other.getOrderedItems())) {
108                         return false;
109                 }
110
111                 return true;
112         }
113
114         @Override
115         public int hashCode () {
116                 int hash = 7;
117                 hash = 61 * hash + Objects.hashCode(this.getAccessKey());
118                 hash = 61 * hash + Objects.hashCode(this.getCustomer());
119                 hash = 61 * hash + Objects.hashCode(this.getOrderId());
120                 hash = 61 * hash + Objects.hashCode(this.getOrderedItems());
121                 return hash;
122         }
123
124         @Override
125         public String getAccessKey () {
126                 return this.accessKey;
127         }
128
129         @Override
130         public void setAccessKey (final String accessKey) {
131                 this.accessKey = accessKey;
132         }
133
134         @Override
135         public Customer getCustomer () {
136                 return this.customer;
137         }
138
139         @Override
140         public void setCustomer (final Customer customer) {
141                 this.customer = customer;
142         }
143
144         @Override
145         public Calendar getOrderCreated () {
146                 return this.orderCreated;
147         }
148
149         @Override
150         public void setOrderCreated (final Calendar orderCreated) {
151                 this.orderCreated = orderCreated;
152         }
153
154         @Override
155         public Long getOrderId () {
156                 return this.orderId;
157         }
158
159         @Override
160         public void setOrderId (final Long orderId) {
161                 this.orderId = orderId;
162         }
163
164         @Override
165         public List<AddableBasketItem> getOrderedItems () {
166                 return this.orderedItems;
167         }
168
169         @Override
170         public void setOrderedItems (final List<AddableBasketItem> orderedItems) {
171                 this.orderedItems = orderedItems;
172         }
173
174 }