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