2 * Copyright (C) 2016 Cho-Time GmbH
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.password_history;
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
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 javax.persistence.Transient;
36 import org.mxchange.jusercore.model.user.LoginUser;
37 import org.mxchange.jusercore.model.user.User;
40 * A POJO for user password history
42 * @author Roland Haeder<rhaeder@cho-time.de>
44 @Entity (name = "user_password_history")
46 name = "user_password_history"
50 @NamedQuery (name = "AllUsersHistoryEntries", query = "SELECT h FROM user_password_history AS h WHERE h.userPasswordHistoryUser = :user ORDER BY h.userPasswordHistoryId ASC")
53 @SuppressWarnings ("PersistenceUnitPresent")
54 public class UserPasswordHistory implements PasswordHistory {
60 private static final long serialVersionUID = 1L;
63 * Timestamp when this entry has been created
65 @Basic (optional = false)
66 @Column (name = "history_created", nullable = false, updatable = false)
67 @Temporal (TemporalType.TIMESTAMP)
68 private Calendar userPasswordHistoryCreated;
71 * Id number (primary key)
74 @Column (name = "history_id", updatable = false)
75 @GeneratedValue (strategy = GenerationType.IDENTITY)
76 private Long userPasswordHistoryId;
79 * Password hash being used
81 @Basic (optional = false)
82 @Column (name = "history_password_hash", nullable = false, updatable = false)
83 private String userPasswordHistoryPasswordHash;
86 * User instance for this history entry
88 @JoinColumn (name = "history_user_id", nullable = true, updatable = false)
89 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
90 private User userPasswordHistoryUser;
95 public UserPasswordHistory () {
99 * Constructor with password hash and user instance
101 * @param userPasswordHistoryPasswordHash Password hash
102 * @param userPasswordHistoryUser User instance
104 public UserPasswordHistory (final String userPasswordHistoryPasswordHash, final User userPasswordHistoryUser) {
106 this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash;
107 this.userPasswordHistoryUser = userPasswordHistoryUser;
111 public boolean equals (final Object object) {
112 if (this == object) {
114 } else if (object == null) {
116 } else if (this.getClass() != object.getClass()) {
120 final PasswordHistory other = (PasswordHistory) object;
122 if (!Objects.equals(this.getUserPasswordHistoryPasswordHash(), other.getUserPasswordHistoryPasswordHash())) {
124 } else if (!Objects.equals(this.getUserPasswordHistoryId(), other.getUserPasswordHistoryId())) {
126 } else if (!Objects.equals(this.getUserPasswordHistoryUser(), other.getUserPasswordHistoryUser())) {
134 @SuppressWarnings ("ReturnOfDateField")
135 public Calendar getUserPasswordHistoryCreated () {
136 return this.userPasswordHistoryCreated;
140 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
141 public void setUserPasswordHistoryCreated (final Calendar userPasswordHistoryCreated) {
142 this.userPasswordHistoryCreated = userPasswordHistoryCreated;
146 public Long getUserPasswordHistoryId () {
147 return this.userPasswordHistoryId;
151 public void setUserPasswordHistoryId (final Long userPasswordHistoryId) {
152 this.userPasswordHistoryId = userPasswordHistoryId;
156 public String getUserPasswordHistoryPasswordHash () {
157 return this.userPasswordHistoryPasswordHash;
161 public void setUserPasswordHistoryPasswordHash (final String userPasswordHistoryPasswordHash) {
162 this.userPasswordHistoryPasswordHash = userPasswordHistoryPasswordHash;
166 public User getUserPasswordHistoryUser () {
167 return this.userPasswordHistoryUser;
171 public void setUserPasswordHistoryUser (final User userPasswordHistoryUser) {
172 this.userPasswordHistoryUser = userPasswordHistoryUser;
176 public int hashCode () {
179 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryId());
180 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryPasswordHash());
181 hash = 79 * hash + Objects.hashCode(this.getUserPasswordHistoryUser());