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