Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package pt.eoliveira.appmanager.dao;
- import java.io.Serializable;
- import java.security.NoSuchAlgorithmException;
- import java.util.Collection;
- import javax.persistence.Basic;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.NamedQueries;
- import javax.persistence.NamedQuery;
- import javax.persistence.OneToMany;
- import javax.persistence.OneToOne;
- import javax.persistence.Table;
- import javax.xml.bind.annotation.XmlRootElement;
- import javax.xml.bind.annotation.XmlTransient;
- import org.codehaus.jackson.annotate.JsonIgnore;
- import pt.eoliveira.appmanager.utils.MySqlTools;
- @Entity
- @Table(name = "users")
- @XmlRootElement
- @NamedQueries({
- @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
- @NamedQuery(name = "Users.findByUserId", query = "SELECT u FROM Users u WHERE u.userId = :userId"),
- @NamedQuery(name = "Users.findByUsername", query = "SELECT u FROM Users u WHERE u.username = :username"),
- @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"),
- @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"),
- @NamedQuery(name = "Users.findByPermissions", query = "SELECT u FROM Users u WHERE u.permissions = :permissions")
- })
- public class Users implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Basic(optional = false)
- @Column(name = "user_id")
- private Integer userId;
- @Basic(optional = false)
- @Column(name = "username")
- private String username;
- @Basic(optional = false)
- @Column(name = "password")
- @XmlTransient
- @JsonIgnore
- private String password;
- @Basic(optional = false)
- @Column(name = "email")
- private String email;
- @Basic(optional = false)
- @Column(name = "permissions")
- private int permissions;
- @OneToOne(mappedBy = "owner")
- private Sessions sessions;
- @JoinColumn(name = "country", referencedColumnName = "country_id")
- @ManyToOne(optional = false)
- private Country country;
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
- private Collection<Apps> appsCollection;
- public Users() {
- }
- public Users(String username) {
- this.username = username;
- }
- public Users(Integer userId) {
- this.userId = userId;
- }
- public Users(Integer userId, String username, String password, String email, int permissions) {
- this.userId = userId;
- this.username = username;
- this.password = password;
- this.email = email;
- this.permissions = permissions;
- }
- public Integer getUserId() {
- return userId;
- }
- public void setUserId(Integer userId) {
- this.userId = userId;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public int getPermissions() {
- return permissions;
- }
- public void setPermissions(int permissions) {
- this.permissions = permissions;
- }
- public Sessions getSessions() {
- return sessions;
- }
- public void setSessions(Sessions sessions) {
- this.sessions = sessions;
- }
- public Country getCountry() {
- return country;
- }
- public void setCountry(Country country) {
- this.country = country;
- }
- @XmlTransient
- public Collection<Apps> getAppsCollection() {
- return appsCollection;
- }
- public void setAppsCollection(Collection<Apps> appsCollection) {
- this.appsCollection = appsCollection;
- }
- public boolean isValid(String password) {
- try {
- return this.password.equals(MySqlTools.MD5Encode(password));
- } catch (NoSuchAlgorithmException ex) {
- ex.printStackTrace();
- }
- return false;
- }
- @Override
- public int hashCode() {
- int hash = 0;
- hash += (userId != null ? userId.hashCode() : 0);
- return hash;
- }
- @Override
- public boolean equals(Object object) {
- // TODO: Warning - this method won't work in the case the id fields are not set
- if (!(object instanceof Users)) {
- return false;
- }
- Users other = (Users) object;
- if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return "Users{" + "userId=" + userId + ", username=" + username + ", password=" + password + ", email=" + email + ", permissions=" + permissions + ", sessions=" + sessions + ", country=" + country + ", appsCollection=" + appsCollection + '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement