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.jshopcore.model.customer.status.CustomerAccountStatus;
40 * A shop customer class.
42 * @author Roland Haeder<roland@mxchange.org>
44 @Entity (name = "customer")
45 @Table (name = "customer")
46 public class ShopCustomer implements Customer, Comparable<Customer> {
51 private static final long serialVersionUID = 4_328_454_581_751L;
54 * Id number from "contacts" table
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;
63 @Basic (optional = false)
64 @Column (name = "customer_account_status", nullable = false)
65 @Enumerated (EnumType.STRING)
66 private CustomerAccountStatus customerAccountStatus;
71 @Column (name = "customer_confirm_key", length = 50)
72 private String customerConfirmKey;
77 @Basic (optional = false)
78 @Temporal (TemporalType.TIMESTAMP)
79 @Column (name = "customer_created", nullable = false)
80 private Calendar customerCreated;
86 @Column (name = "customer_id", nullable = false, length = 20, updatable = false)
87 @GeneratedValue (strategy = GenerationType.IDENTITY)
88 private Long customerId;
93 @Temporal (TemporalType.TIMESTAMP)
94 @Column (name = "customer_locked_timestamp")
95 private Calendar customerLocked;
98 * Customer number, this is different to the database entry customerId.
100 @Column (name = "customer_number", nullable = false, length = 20)
101 private String customerNumber;
106 @Column (name = "customer_password_hash")
107 private String customerPasswordHash;
110 * Default constructor
112 public ShopCustomer () {
116 public int compareTo (final Customer customer) {
117 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
121 public void copyAll (final Customer customer) {
122 // Copy also contact data
123 this.getContact().copyAll(customer.getContact());
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());
135 public boolean equals (final Object obj) {
138 } else if (obj == null) {
140 } else if (this.getClass() != obj.getClass()) {
144 final Customer other = (Customer) obj;
146 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
148 } else if (!Objects.equals(this.getContact(), other.getContact())) {
152 return Objects.equals(this.getContact(), other.getContact());
156 public int hashCode () {
158 hash = 17 * hash + Objects.hashCode(this.getContact());
159 hash = 17 * hash + Objects.hashCode(this.getCustomerId());
160 hash = 17 * hash + Objects.hashCode(this.getCustomerNumber());
165 public Contact getContact () {
170 public void setContact (final Contact contact) {
171 this.contact = contact;
175 public CustomerAccountStatus getCustomerAccountStatus () {
176 return this.customerAccountStatus;
180 public void setCustomerAccountStatus (final CustomerAccountStatus customerAccountStatus) {
181 this.customerAccountStatus = customerAccountStatus;
185 public String getCustomerConfirmKey () {
186 return this.customerConfirmKey;
190 public void setCustomerConfirmKey (final String customerConfirmKey) {
191 this.customerConfirmKey = customerConfirmKey;
195 public Calendar getCustomerCreated () {
196 return this.customerCreated;
200 public void setCustomerCreated (final Calendar customerCreated) {
201 this.customerCreated = customerCreated;
205 public Long getCustomerId () {
206 return this.customerId;
210 public void setCustomerId (final Long customerId) {
211 this.customerId = customerId;
215 public Calendar getCustomerLocked () {
216 return this.customerLocked;
220 public void setCustomerLocked (final Calendar customerLocked) {
221 this.customerLocked = customerLocked;
225 public String getCustomerNumber () {
226 return this.customerNumber;
230 public void setCustomerNumber (final String customerNumber) {
231 this.customerNumber = customerNumber;
235 public String getCustomerPasswordHash () {
236 return this.customerPasswordHash;
240 public void setCustomerPasswordHash (final String customerPasswordHash) {
241 this.customerPasswordHash = customerPasswordHash;