]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jshopcore/model/customer/ShopCustomer.java
added equals()/hashCode() for easier checking
[jproduct-core.git] / src / org / mxchange / jshopcore / model / customer / ShopCustomer.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.customer;
18
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.UserContact;
37 import org.mxchange.jshopcore.model.customer.status.CustomerAccountStatus;
38
39 /**
40  * A shop customer class.
41  * <p>
42  * @author Roland Haeder<roland@mxchange.org>
43  */
44 @Entity (name = "customer")
45 @Table (name = "customer")
46 public class ShopCustomer implements Customer, Comparable<Customer> {
47
48         /**
49          * Serial number
50          */
51         private static final long serialVersionUID = 4_328_454_581_751L;
52
53         /**
54          * Id number from "contacts" table
55          */
56         @JoinColumn (name = "contact_id", nullable = false, updatable = false, unique = true)
57         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
58         private Contact contact;
59
60         /**
61          * Account status
62          */
63         @Basic (optional = false)
64         @Column (name = "customer_account_status", nullable = false)
65         @Enumerated (EnumType.STRING)
66         private CustomerAccountStatus customerAccountStatus;
67
68         /**
69          * Confirmation key
70          */
71         @Column (name = "customer_confirm_key", length = 50)
72         private String customerConfirmKey;
73
74         /**
75          * "created" timestamp
76          */
77         @Basic (optional = false)
78         @Temporal (TemporalType.TIMESTAMP)
79         @Column (name = "customer_created", nullable = false)
80         private Calendar customerCreated;
81
82         /**
83          * Customer id
84          */
85         @Id
86         @Column (name = "customer_id", nullable = false, length = 20, updatable = false)
87         @GeneratedValue (strategy = GenerationType.IDENTITY)
88         private Long customerId;
89
90         /**
91          * "locked" timestamp
92          */
93         @Temporal (TemporalType.TIMESTAMP)
94         @Column (name = "customer_locked_timestamp")
95         private Calendar customerLocked;
96
97         /**
98          * Customer number, this is different to the database entry customerId.
99          */
100         @Column (name = "customer_number", nullable = false, length = 20)
101         private String customerNumber;
102
103         /**
104          * Password hash
105          */
106         @Column (name = "customer_password_hash")
107         private String customerPasswordHash;
108
109         /**
110          * Default constructor
111          */
112         public ShopCustomer () {
113         }
114
115         @Override
116         public int compareTo (final Customer customer) {
117                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
118         }
119
120         @Override
121         public void copyAll (final Customer customer) {
122                 // Copy also contact data
123                 this.getContact().copyAll(customer.getContact());
124
125                 // Copy other data
126                 this.setCustomerConfirmKey(customer.getCustomerConfirmKey());
127                 this.setCustomerNumber(customer.getCustomerNumber());
128                 this.setCustomerPasswordHash(customer.getCustomerPasswordHash());
129                 this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
130                 this.setCustomerCreated(customer.getCustomerCreated());
131                 this.setCustomerLocked(customer.getCustomerLocked());
132         }
133
134         @Override
135         public boolean equals (final Object obj) {
136                 if (this == obj) {
137                         return true;
138                 } else if (obj == null) {
139                         return false;
140                 } else if (this.getClass() != obj.getClass()) {
141                         return false;
142                 }
143
144                 final Customer other = (Customer) obj;
145
146                 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
147                         return false;
148                 } else if (!Objects.equals(this.getContact(), other.getContact())) {
149                         return false;
150                 }
151
152                 return Objects.equals(this.getContact(), other.getContact());
153         }
154
155         @Override
156         public int hashCode () {
157                 int hash = 3;
158                 hash = 17 * hash + Objects.hashCode(this.getContact());
159                 hash = 17 * hash + Objects.hashCode(this.getCustomerId());
160                 hash = 17 * hash + Objects.hashCode(this.getCustomerNumber());
161                 return hash;
162         }
163
164         @Override
165         public Contact getContact () {
166                 return this.contact;
167         }
168
169         @Override
170         public void setContact (final Contact contact) {
171                 this.contact = contact;
172         }
173
174         @Override
175         public CustomerAccountStatus getCustomerAccountStatus () {
176                 return this.customerAccountStatus;
177         }
178
179         @Override
180         public void setCustomerAccountStatus (final CustomerAccountStatus customerAccountStatus) {
181                 this.customerAccountStatus = customerAccountStatus;
182         }
183
184         @Override
185         public String getCustomerConfirmKey () {
186                 return this.customerConfirmKey;
187         }
188
189         @Override
190         public void setCustomerConfirmKey (final String customerConfirmKey) {
191                 this.customerConfirmKey = customerConfirmKey;
192         }
193
194         @Override
195         public Calendar getCustomerCreated () {
196                 return this.customerCreated;
197         }
198
199         @Override
200         public void setCustomerCreated (final Calendar customerCreated) {
201                 this.customerCreated = customerCreated;
202         }
203
204         @Override
205         public Long getCustomerId () {
206                 return this.customerId;
207         }
208
209         @Override
210         public void setCustomerId (final Long customerId) {
211                 this.customerId = customerId;
212         }
213
214         @Override
215         public Calendar getCustomerLocked () {
216                 return this.customerLocked;
217         }
218
219         @Override
220         public void setCustomerLocked (final Calendar customerLocked) {
221                 this.customerLocked = customerLocked;
222         }
223
224         @Override
225         public String getCustomerNumber () {
226                 return this.customerNumber;
227         }
228
229         @Override
230         public void setCustomerNumber (final String customerNumber) {
231                 this.customerNumber = customerNumber;
232         }
233
234         @Override
235         public String getCustomerPasswordHash () {
236                 return this.customerPasswordHash;
237         }
238
239         @Override
240         public void setCustomerPasswordHash (final String customerPasswordHash) {
241                 this.customerPasswordHash = customerPasswordHash;
242         }
243
244 }