Advertisement
Guest User

Untitled

a guest
May 16th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.bevuta.dyndns.model;
  7.  
  8. import java.io.Serializable;
  9. import java.util.HashSet;
  10. import java.util.LinkedList;
  11. import java.util.List;
  12. import java.util.Objects;
  13. import java.util.Set;
  14. import javax.persistence.CascadeType;
  15. import javax.persistence.Entity;
  16. import javax.persistence.FetchType;
  17. import javax.persistence.GeneratedValue;
  18. import javax.persistence.GenerationType;
  19. import javax.persistence.Id;
  20. import javax.persistence.JoinTable;
  21. import javax.persistence.OneToMany;
  22. import javax.persistence.OrderColumn;
  23. import javax.persistence.Table;
  24.  
  25. /**
  26.  *
  27.  * @author klaus
  28.  */
  29. @Entity
  30. @Table(name = "users")
  31. public class User implements Serializable {
  32.  
  33.     @Id
  34.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  35.     private int id;
  36.  
  37.     private String username;
  38.     private String password;
  39.     private boolean enabled;
  40.  
  41.     @OneToMany(fetch = FetchType.LAZY)
  42.     @JoinTable
  43.     private Set<UserRole> userRole = new HashSet<UserRole>();
  44.  
  45.     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
  46. //  @JoinColumn(name="user_id", nullable=false)    
  47. //  @JoinTable(name = "HOST_USER", joinColumns = @JoinColumn(name = "USER_ID"), inverseJoinColumns = @JoinColumn(name = "HOST_ID"))
  48. //  @JoinColumn(name="user_id", nullable=false)    
  49. //  @OrderColumn
  50.     private Set<Host> hosts = new HashSet<>();
  51.  
  52.     public User() {
  53.     }
  54.  
  55.     public User(String username, String password) {
  56.         this.username = username;
  57.         this.password = password;
  58.     }
  59.  
  60.     public int getId() {
  61.         return id;
  62.     }
  63.  
  64.     public void setId(int id) {
  65.         this.id = id;
  66.     }
  67.  
  68.     public String getUsername() {
  69.         return username;
  70.     }
  71.  
  72.     public void setUsername(String username) {
  73.         this.username = username;
  74.     }
  75.  
  76.     public String getPassword() {
  77.         return password;
  78.     }
  79.  
  80.     public void setPassword(String password) {
  81.         this.password = password;
  82.     }
  83.  
  84.     public Set<Host> getHosts() {
  85.         return hosts;
  86.     }
  87.  
  88.     public void setHosts(Set<Host> hosts) {
  89.         this.hosts = hosts;
  90.     }
  91.  
  92.     public void addHost(Host host) {
  93.         this.hosts.add(host);
  94.     }
  95.  
  96.     public boolean getHost(Host host) {
  97.         return hosts.contains(host);
  98.     }
  99.  
  100.     public boolean isEnabled() {
  101.         return enabled;
  102.     }
  103.  
  104.     public void setEnabled(boolean enabled) {
  105.         this.enabled = enabled;
  106.     }
  107.  
  108.     public Set<UserRole> getUserRole() {
  109.         return userRole;
  110.     }
  111.  
  112.     public void setUserRole(Set<UserRole> userRole) {
  113.         this.userRole = userRole;
  114.     }
  115.  
  116.     public void addUserRole(UserRole userRole) {
  117.         this.userRole.add(userRole);
  118.     }
  119.  
  120.     public Host getHostIndexById(int hostId) {
  121.         for (Host host : hosts) {
  122.             if (host.getId() == hostId) {
  123.                 return host;
  124.             }
  125.         }
  126.         return null;
  127.     }
  128.  
  129.     @Override
  130.     public int hashCode() {
  131.         int hash = 7;
  132.         hash = 29 * hash + this.id;
  133.         hash = 29 * hash + Objects.hashCode(this.username);
  134.         return hash;
  135.     }
  136.  
  137.     @Override
  138.     public boolean equals(Object obj) {
  139.         if (this == obj) {
  140.             return true;
  141.         }
  142.         if (obj == null) {
  143.             return false;
  144.         }
  145.         if (getClass() != obj.getClass()) {
  146.             return false;
  147.         }
  148.         final User other = (User) obj;
  149.         return true;
  150.     }
  151.    
  152.     @Override
  153.     public String toString() {
  154.         return "User{" + "id=" + id + ", username=" + username + ", password=" + password + ", hosts=" + hosts + '}';
  155.     }    
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement