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