package hu.sch.domain.user;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.validation.constraints.Size;

/**
 *
 * @author balo
 */
@Entity
@Table(name = "lostpw_tokens")
@NamedQueries({
    @NamedQuery(name = LostPasswordToken.getByToken,
            query = "SELECT t FROM LostPasswordToken t WHERE t.token = :token"
    ),
    @NamedQuery(name = LostPasswordToken.removeExpired,
            query = "DELETE FROM LostPasswordToken t "
            + "WHERE t.created < :time_in_past"
    )
})
public class LostPasswordToken implements Serializable {

    public static final String getByToken = "getByToken";
    public static final String removeExpired = "removeExpired";
    //
    @Id
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "usr_id")
    private User subjectUser;
    //--------------------------------
    @Column(length = 64, unique = true)
    @Size(max = 64)
    private String token;
    //--------------------------------
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date created;

    public LostPasswordToken() {
    }

    public LostPasswordToken(final User subjectUser, final String token,
            final Date created) {

        this.subjectUser = subjectUser;
        this.token = token;
        this.created = new Date(created.getTime());
    }

    public User getSubjectUser() {
        return subjectUser;
    }

    public String getToken() {
        return token;
    }

    public Date getCreated() {
        return created;
    }
}

@@ -74,16 +74,42 @@
 l.Date;%0A
+import java.util.Objects;%0A
 import j
@@ -1887,10 +1887,870 @@
 ;%0A    %7D%0A
+%0A    @Override%0A    public int hashCode() %7B%0A        int hash = 7;%0A        hash = 59 * hash + Objects.hashCode(this.subjectUser);%0A        hash = 59 * hash + Objects.hashCode(this.token);%0A        hash = 59 * hash + Objects.hashCode(this.created);%0A        return hash;%0A    %7D%0A%0A    @Override%0A    public boolean equals(final Object obj) %7B%0A        if (obj == null) %7B%0A            return false;%0A        %7D%0A        if (getClass() != obj.getClass()) %7B%0A            return false;%0A        %7D%0A        final LostPasswordToken other = (LostPasswordToken) obj;%0A        if (!Objects.equals(this.subjectUser, other.subjectUser)) %7B%0A            return false;%0A        %7D%0A        if (!Objects.equals(this.token, other.token)) %7B%0A            return false;%0A        %7D%0A        if (!Objects.equals(this.created, other.created)) %7B%0A            return false;%0A        %7D%0A        return true;%0A    %7D%0A%0A
 %7D%0A

Add equals and hashCode methods to LostPasswordToken (#80)