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