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.JoinColumn;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import org.mxchange.jcontacts.contact.Contact;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
41 * A shop customer class.
43 * @author Roland Haeder<roland@mxchange.org>
45 @Entity (name = "users")
46 @Table (name = "users")
49 @NamedQuery(name = "AllUserNames", query = "SELECT DISTINCT u.userName FROM users AS u ORDER BY u.userId ASC"),
50 @NamedQuery(name = "AllEmailAddresses", query = "SELECT DISTINCT c.emailAddress FROM contacts AS c ORDER BY c.contactId ASC"),
51 @NamedQuery(name = "SearchUserName", query = "SELECT u FROM users AS u WHERE LOWER(u.userName) LIKE LOWER(:param)"),
52 @NamedQuery(name = "SearchEmailAddress", query = "SELECT u FROM users AS u INNER JOIN contacts AS c ON u.userContact = c WHERE LOWER(c.emailAddress) LIKE LOWER(:param)")
55 public class LoginUser implements User {
60 private static final long serialVersionUID = 4_328_454_581_751L;
63 * Id number from "contacts" table
65 @JoinColumn (name = "contact_id", nullable = false, updatable = false)
66 @OneToOne (cascade = CascadeType.ALL, targetEntity = UserContact.class, optional = false)
67 private Contact userContact;
72 @Basic (optional = false)
73 @Column (name = "user_account_status", nullable = false)
74 @Enumerated (value = EnumType.STRING)
75 private UserAccountStatus userAccountStatus;
80 @Column (name = "user_confirm_key", length = 50)
81 private String userConfirmKey;
86 @Basic (optional = false)
87 @Temporal (TemporalType.TIMESTAMP)
88 @Column (name = "user_created", nullable = false)
89 private Calendar userCreated;
95 @Column (name = "user_id", nullable = false, length = 20, updatable = false)
96 @GeneratedValue (strategy = GenerationType.IDENTITY)
102 @Temporal (TemporalType.TIMESTAMP)
103 @Column (name = "user_locked")
104 private Calendar userLocked;
109 @Column (name = "user_name", nullable = false, length = 20)
110 private String userName;
115 @Column (name = "user_encrypted_password", nullable = false)
116 private String userEncryptedPassword;
119 * Default constructor
121 public LoginUser () {
125 public void copyAll (final User user) {
126 // Copy also contact data
127 this.getUserContact().copyAll(user.getUserContact());
130 this.setUserConfirmKey(user.getUserConfirmKey());
131 this.setUserName(user.getUserName());
132 this.setUserEncryptedPassword(user.getUserEncryptedPassword());
133 this.setUserAccountStatus(user.getUserAccountStatus());
134 this.setUserCreated(user.getUserCreated());
135 this.setUserLocked(user.getUserLocked());
139 public Contact getUserContact () {
140 return this.userContact;
144 public void setUserContact (final Contact userContact) {
145 this.userContact = userContact;
149 public UserAccountStatus getUserAccountStatus () {
150 return this.userAccountStatus;
154 public void setUserAccountStatus (final UserAccountStatus userAccountStatus) {
155 this.userAccountStatus = userAccountStatus;
159 public String getUserConfirmKey () {
160 return this.userConfirmKey;
164 public void setUserConfirmKey (final String customerConfirmKey) {
165 this.userConfirmKey = customerConfirmKey;
169 public Calendar getUserCreated () {
170 return this.userCreated;
174 public void setUserCreated (final Calendar userCreated) {
175 this.userCreated = userCreated;
179 public Long getUserId () {
184 public void setUserId (final Long userId) {
185 this.userId = userId;
189 public Calendar getUserLocked () {
190 return this.userLocked;
194 public void setUserLocked (final Calendar userLocked) {
195 this.userLocked = userLocked;
199 public String getUserName () {
200 return this.userName;
204 public void setUserName (final String userName) {
205 this.userName = userName;
209 public String getUserEncryptedPassword () {
210 return this.userEncryptedPassword;
214 public void setUserEncryptedPassword (final String userEncryptedPassword) {
215 this.userEncryptedPassword = userEncryptedPassword;