2 * Copyright (C) 2016 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.jshopcore.model.customer;
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;
41 * A shop customer class.
43 * @author Roland Haeder<roland@mxchange.org>
45 @Entity (name = "customer")
46 @Table (name = "customer")
47 @SuppressWarnings ("PersistenceUnitPresent")
48 public class ShopCustomer implements Customer {
53 private static final long serialVersionUID = 4_328_454_581_751L;
58 @Basic (optional = false)
59 @Column (name = "customer_account_status", nullable = false)
60 @Enumerated (EnumType.STRING)
61 private CustomerAccountStatus customerAccountStatus;
66 @Column (name = "customer_confirm_key", length = 50)
67 private String customerConfirmKey;
70 * Id number from "contacts" table
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;
79 @Basic (optional = false)
80 @Temporal (TemporalType.TIMESTAMP)
81 @Column (name = "customer_created", nullable = false)
82 private Calendar customerCreated;
88 @Column (name = "customer_id", nullable = false, length = 20, updatable = false)
89 @GeneratedValue (strategy = GenerationType.IDENTITY)
90 private Long customerId;
95 @Temporal (TemporalType.TIMESTAMP)
96 @Column (name = "customer_locked_timestamp")
97 private Calendar customerLocked;
100 * Customer number, this is different to the database entry customerId.
102 @Column (name = "customer_number", nullable = false, length = 20)
103 private String customerNumber;
108 @Column (name = "customer_password_hash")
109 private String customerPasswordHash;
112 * Default constructor
114 public ShopCustomer () {
118 public void copyAll (final Customer customer) {
119 // Copy also customerContact data
120 this.getCustomerContact().copyAll(customer.getCustomerContact());
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());
132 public boolean equals (final Object object) {
133 if (this == object) {
135 } else if (null == object) {
137 } else if (this.getClass() != object.getClass()) {
141 final Customer other = (Customer) object;
143 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
145 } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) {
149 return Objects.equals(this.getCustomerContact(), other.getCustomerContact());
153 public int hashCode () {
155 hash = 17 * hash + Objects.hashCode(this.getCustomerContact());
156 hash = 17 * hash + Objects.hashCode(this.getCustomerId());
157 hash = 17 * hash + Objects.hashCode(this.getCustomerNumber());
162 public CustomerAccountStatus getCustomerAccountStatus () {
163 return this.customerAccountStatus;
167 public void setCustomerAccountStatus (final CustomerAccountStatus customerAccountStatus) {
168 this.customerAccountStatus = customerAccountStatus;
172 public String getCustomerConfirmKey () {
173 return this.customerConfirmKey;
177 public void setCustomerConfirmKey (final String customerConfirmKey) {
178 this.customerConfirmKey = customerConfirmKey;
182 public Contact getCustomerContact () {
183 return this.customerContact;
187 public void setCustomerContact (final Contact customerContact) {
188 this.customerContact = customerContact;
192 public Calendar getCustomerCreated () {
193 return this.customerCreated;
197 public void setCustomerCreated (final Calendar customerCreated) {
198 this.customerCreated = customerCreated;
202 public Long getCustomerId () {
203 return this.customerId;
207 public void setCustomerId (final Long customerId) {
208 this.customerId = customerId;
212 public Calendar getCustomerLocked () {
213 return this.customerLocked;
217 public void setCustomerLocked (final Calendar customerLocked) {
218 this.customerLocked = customerLocked;
222 public String getCustomerNumber () {
223 return this.customerNumber;
227 public void setCustomerNumber (final String customerNumber) {
228 this.customerNumber = customerNumber;
232 public String getCustomerPasswordHash () {
233 return this.customerPasswordHash;
237 public void setCustomerPasswordHash (final String customerPasswordHash) {
238 this.customerPasswordHash = customerPasswordHash;