2 * Copyright (C) 2015 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.jusercore.model.user;
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;
42 * A shop customer class.
44 * @author Roland Haeder<roland@mxchange.org>
46 @Entity (name = "users")
51 name = "confirmation_key",
53 columnList = "user_confirm_key"
58 @NamedQuery (name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
59 @NamedQuery (name = "AllEmailAddresses", query = "SELECT DISTINCT c.contactEmailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
60 @NamedQuery (name = "SearchUserName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
61 @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)")
64 public class LoginUser implements User {
69 private static final long serialVersionUID = 4_328_454_581_751L;
74 @Basic (optional = false)
75 @Column (name = "user_account_status", nullable = false)
76 @Enumerated (value = EnumType.STRING)
77 private UserAccountStatus userAccountStatus;
82 @Column (name = "user_confirm_key", length = 50)
83 private String userConfirmKey;
86 * Id number from "contacts" table
88 @JoinColumn (name = "user_contact_id", nullable = false, updatable = false)
89 @OneToOne (targetEntity = UserContact.class, optional = false, cascade = CascadeType.ALL)
90 private Contact userContact;
95 @Basic (optional = false)
96 @Temporal (TemporalType.TIMESTAMP)
97 @Column (name = "user_created", nullable = false)
98 private Calendar userCreated;
103 @Column (name = "user_encrypted_password", nullable = false)
104 private String userEncryptedPassword;
110 @Column (name = "user_id", nullable = false, length = 20, updatable = false)
111 @GeneratedValue (strategy = GenerationType.IDENTITY)
117 @Temporal (TemporalType.TIMESTAMP)
118 @Column (name = "user_locked")
119 private Calendar userLocked;
124 @Column (name = "user_name", nullable = false, length = 20)
125 private String userName;
128 * Default constructor
130 public LoginUser () {
134 public void copyAll (final User user) {
135 // Copy also contact data
136 this.getUserContact().copyAll(user.getUserContact());
139 this.setUserConfirmKey(user.getUserConfirmKey());
140 this.setUserName(user.getUserName());
141 this.setUserEncryptedPassword(user.getUserEncryptedPassword());
142 this.setUserAccountStatus(user.getUserAccountStatus());
143 this.setUserCreated(user.getUserCreated());
144 this.setUserLocked(user.getUserLocked());
148 public UserAccountStatus getUserAccountStatus () {
149 return this.userAccountStatus;
153 public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
154 this.userAccountStatus = userAccountStatus;
158 public String getUserConfirmKey () {
159 return this.userConfirmKey;
163 public void setUserConfirmKey (final String customerConfirmKey) {
164 this.userConfirmKey = customerConfirmKey;
168 public Contact getUserContact () {
169 return this.userContact;
173 public void setUserContact (final Contact userContact) {
174 this.userContact = userContact;
178 public Calendar getUserCreated () {
179 return this.userCreated;
183 public void setUserCreated (final Calendar userCreated) {
184 this.userCreated = userCreated;
188 public String getUserEncryptedPassword () {
189 return this.userEncryptedPassword;
193 public void setUserEncryptedPassword (final String userEncryptedPassword) {
194 this.userEncryptedPassword = userEncryptedPassword;
198 public Long getUserId () {
203 public void setUserId (final Long userId) {
204 this.userId = userId;
208 public Calendar getUserLocked () {
209 return this.userLocked;
213 public void setUserLocked (final Calendar userLocked) {
214 this.userLocked = userLocked;
218 public String getUserName () {
219 return this.userName;
223 public void setUserName (final String userName) {
224 this.userName = userName;