]> git.mxchange.org Git - jshop-core.git/blob - src/org/mxchange/jshopcore/model/customer/ShopCustomer.java
2db4c227f8e6c7ab13b1a23424dccaba509ccec0
[jshop-core.git] / src / org / mxchange / jshopcore / model / customer / ShopCustomer.java
1 /*
2  * Copyright (C) 2015 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 javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.EnumType;
25 import javax.persistence.Enumerated;
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 org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.UserContact;
36 import org.mxchange.jshopcore.model.customer.status.CustomerAccountStatus;
37
38 /**
39  * A shop customer class.
40  * <p>
41  * @author Roland Haeder<roland@mxchange.org>
42  */
43 @Entity (name = "customer")
44 @Table (name = "customer")
45 public class ShopCustomer implements Customer {
46
47         /**
48          * Serial number
49          */
50         private static final long serialVersionUID = 4_328_454_581_751L;
51
52         /**
53          * Id number from "contacts" table
54          */
55         @JoinColumn (name = "contact_id", nullable = false, updatable = false, unique = true)
56         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
57         private Contact contact;
58
59         /**
60          * Confirmation key
61          */
62         @Column (name = "customer_confirm_key", length = 50)
63         private String customerConfirmKey;
64
65         /**
66          * "created" timestamp
67          */
68         @Basic (optional = false)
69         @Temporal (TemporalType.TIMESTAMP)
70         @Column (name = "customer_created", nullable = false)
71         private Calendar customerCreated;
72
73         /**
74          * Customer id
75          */
76         @Id
77         @Column (name = "customer_id", nullable = false, length = 20, updatable = false)
78         @GeneratedValue (strategy = GenerationType.IDENTITY)
79         private Long customerId;
80
81         /**
82          * "locked" timestamp
83          */
84         @Temporal (TemporalType.TIMESTAMP)
85         @Column (name = "customer_locked")
86         private Calendar customerLocked;
87
88         /**
89          * Customer number, this is different to the database entry customerId.
90          */
91         @Column (name = "customer_number", nullable = false, length = 20)
92         private String customerNumber;
93
94         /**
95          * Password hash
96          */
97         @Column (name = "customer_password_hash")
98         private String customerPasswordHash;
99
100         /**
101          * Account status
102          */
103         @Basic (optional = false)
104         @Column (name = "customer_account_status", nullable = false)
105         @Enumerated (EnumType.STRING)
106         private CustomerAccountStatus customerAccountStatus;
107
108         /**
109          * Default constructor
110          */
111         public ShopCustomer () {
112         }
113
114         @Override
115         public void copyAll (final Customer customer) {
116                 // Copy also contact data
117                 this.getContact().copyAll(customer.getContact());
118
119                 // Copy other data
120                 this.setCustomerConfirmKey(customer.getCustomerConfirmKey());
121                 this.setCustomerNumber(customer.getCustomerNumber());
122                 this.setCustomerPasswordHash(customer.getCustomerPasswordHash());
123                 this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
124                 this.setCustomerCreated(customer.getCustomerCreated());
125                 this.setCustomerLocked(customer.getCustomerLocked());
126         }
127
128         @Override
129         public Contact getContact () {
130                 return this.contact;
131         }
132
133         @Override
134         public void setContact (final Contact contact) {
135                 this.contact = contact;
136         }
137
138         @Override
139         public String getCustomerConfirmKey () {
140                 return this.customerConfirmKey;
141         }
142
143         @Override
144         public void setCustomerConfirmKey (final String customerConfirmKey) {
145                 this.customerConfirmKey = customerConfirmKey;
146         }
147
148         @Override
149         public Calendar getCustomerCreated () {
150                 return this.customerCreated;
151         }
152
153         @Override
154         public void setCustomerCreated (final Calendar customerCreated) {
155                 this.customerCreated = customerCreated;
156         }
157
158         @Override
159         public Long getCustomerId () {
160                 return this.customerId;
161         }
162
163         @Override
164         public void setCustomerId (final Long customerId) {
165                 this.customerId = customerId;
166         }
167
168         @Override
169         public Calendar getCustomerLocked () {
170                 return this.customerLocked;
171         }
172
173         @Override
174         public void setCustomerLocked (final Calendar customerLocked) {
175                 this.customerLocked = customerLocked;
176         }
177
178         @Override
179         public String getCustomerNumber () {
180                 return this.customerNumber;
181         }
182
183         @Override
184         public void setCustomerNumber (final String customerNumber) {
185                 this.customerNumber = customerNumber;
186         }
187
188         @Override
189         public String getCustomerPasswordHash () {
190                 return this.customerPasswordHash;
191         }
192
193         @Override
194         public void setCustomerPasswordHash (final String customerPasswordHash) {
195                 this.customerPasswordHash = customerPasswordHash;
196         }
197
198         @Override
199         public CustomerAccountStatus getCustomerAccountStatus () {
200                 return this.customerAccountStatus;
201         }
202
203         @Override
204         public void setCustomerAccountStatus (final CustomerAccountStatus customerAccountStatus) {
205                 this.customerAccountStatus = customerAccountStatus;
206         }
207 }