]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jshopcore/model/customer/ShopCustomer.java
@JoinColumn and @Column doesn't work together
[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 java.util.Calendar;
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", referencedColumnName = "customer_contact_id", name = "id", nullable = false, updatable = false, unique = true)
60         @OneToOne (optional = false, targetEntity = BaseContact.class, orphanRemoval = true)
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 Calendar customerCreated;
76
77         /**
78          * "locked" timestamp
79          */
80         @Temporal (TemporalType.TIMESTAMP)
81         @Column (name = "customer_locked")
82         private Calendar 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 Calendar getCustomerCreated () {
138                 return this.customerCreated;
139         }
140
141         @Override
142         public void setCustomerCreated (final Calendar customerCreated) {
143                 this.customerCreated = customerCreated;
144         }
145
146         @Override
147         public Calendar getCustomerLocked () {
148                 return this.customerLocked;
149         }
150
151         @Override
152         public void setCustomerLocked (final Calendar 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 }