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