]> git.mxchange.org Git - juser-login-core.git/blob - src/org/mxchange/jusercore/model/user/LoginUser.java
created unique index on login name
[juser-login-core.git] / src / org / mxchange / jusercore / model / user / LoginUser.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.jusercore.model.user;
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.Index;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.NamedQueries;
32 import javax.persistence.NamedQuery;
33 import javax.persistence.OneToOne;
34 import javax.persistence.Table;
35 import javax.persistence.Temporal;
36 import javax.persistence.TemporalType;
37 import org.mxchange.jcontacts.contact.Contact;
38 import org.mxchange.jcontacts.contact.UserContact;
39 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
40
41 /**
42  * A shop customer class.
43  * <p>
44  * @author Roland Haeder<roland@mxchange.org>
45  */
46 @Entity (name = "users")
47 @Table (
48                 name = "users",
49                 indexes = {
50                         @Index (
51                                         name = "confirmation_key",
52                                         unique = true,
53                                         columnList = "user_confirm_key"
54                         ),
55                         @Index (
56                                         name = "user_name",
57                                         unique = true,
58                                         columnList = "user_name"
59                         )
60                 }
61 )
62 @NamedQueries (
63                 {
64                         @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
65                         @NamedQuery (name = "AllEmailAddresses", query = "SELECT DISTINCT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
66                         @NamedQuery (name = "SearchUserName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
67                         @NamedQuery (name = "SearchEmailAddress", query = "SELECT u FROM users AS u INNER JOIN contacts AS c ON u.userContact = c WHERE LOWER(c.contactEmailAddress) LIKE LOWER(:param)")
68                 }
69 )
70 public class LoginUser implements User {
71
72         /**
73          * Serial number
74          */
75         private static final long serialVersionUID = 4_328_454_581_751L;
76
77         /**
78          * Account status
79          */
80         @Basic (optional = false)
81         @Column (name = "user_account_status", nullable = false)
82         @Enumerated (value = EnumType.STRING)
83         private UserAccountStatus userAccountStatus;
84
85         /**
86          * Confirmation key
87          */
88         @Column (name = "user_confirm_key", length = 50)
89         private String userConfirmKey;
90
91         /**
92          * Id number from "contacts" table
93          */
94         @JoinColumn (name = "user_contact_id", nullable = false, updatable = false)
95         @OneToOne (targetEntity = UserContact.class, optional = false, cascade = CascadeType.ALL)
96         private Contact userContact;
97
98         /**
99          * "created" timestamp
100          */
101         @Basic (optional = false)
102         @Temporal (TemporalType.TIMESTAMP)
103         @Column (name = "user_created", nullable = false)
104         private Calendar userCreated;
105
106         /**
107          * Encrypted password
108          */
109         @Column (name = "user_encrypted_password", nullable = false)
110         private String userEncryptedPassword;
111
112         /**
113          * User id
114          */
115         @Id
116         @Column (name = "user_id", nullable = false, length = 20, updatable = false)
117         @GeneratedValue (strategy = GenerationType.IDENTITY)
118         private Long userId;
119
120         /**
121          * "locked" timestamp
122          */
123         @Temporal (TemporalType.TIMESTAMP)
124         @Column (name = "user_locked")
125         private Calendar userLocked;
126
127         /**
128          * User name
129          */
130         @Column (name = "user_name", nullable = false, length = 20)
131         private String userName;
132
133         /**
134          * Default constructor
135          */
136         public LoginUser () {
137         }
138
139         @Override
140         public void copyAll (final User user) {
141                 // Copy also contact data
142                 this.getUserContact().copyAll(user.getUserContact());
143
144                 // Copy other data
145                 this.setUserConfirmKey(user.getUserConfirmKey());
146                 this.setUserName(user.getUserName());
147                 this.setUserEncryptedPassword(user.getUserEncryptedPassword());
148                 this.setUserAccountStatus(user.getUserAccountStatus());
149                 this.setUserCreated(user.getUserCreated());
150                 this.setUserLocked(user.getUserLocked());
151         }
152
153         @Override
154         public UserAccountStatus getUserAccountStatus () {
155                 return this.userAccountStatus;
156         }
157
158         @Override
159         public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
160                 this.userAccountStatus = userAccountStatus;
161         }
162
163         @Override
164         public String getUserConfirmKey () {
165                 return this.userConfirmKey;
166         }
167
168         @Override
169         public void setUserConfirmKey (final String customerConfirmKey) {
170                 this.userConfirmKey = customerConfirmKey;
171         }
172
173         @Override
174         public Contact getUserContact () {
175                 return this.userContact;
176         }
177
178         @Override
179         public void setUserContact (final Contact userContact) {
180                 this.userContact = userContact;
181         }
182
183         @Override
184         public Calendar getUserCreated () {
185                 return this.userCreated;
186         }
187
188         @Override
189         public void setUserCreated (final Calendar userCreated) {
190                 this.userCreated = userCreated;
191         }
192
193         @Override
194         public String getUserEncryptedPassword () {
195                 return this.userEncryptedPassword;
196         }
197
198         @Override
199         public void setUserEncryptedPassword (final String userEncryptedPassword) {
200                 this.userEncryptedPassword = userEncryptedPassword;
201         }
202
203         @Override
204         public Long getUserId () {
205                 return this.userId;
206         }
207
208         @Override
209         public void setUserId (final Long userId) {
210                 this.userId = userId;
211         }
212
213         @Override
214         public Calendar getUserLocked () {
215                 return this.userLocked;
216         }
217
218         @Override
219         public void setUserLocked (final Calendar userLocked) {
220                 this.userLocked = userLocked;
221         }
222
223         @Override
224         public String getUserName () {
225                 return this.userName;
226         }
227
228         @Override
229         public void setUserName (final String userName) {
230                 this.userName = userName;
231         }
232 }