Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.bevuta.dyndns.model;
- import java.io.Serializable;
- import java.util.HashSet;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Objects;
- import java.util.Set;
- import javax.persistence.CascadeType;
- import javax.persistence.Entity;
- import javax.persistence.FetchType;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.JoinTable;
- import javax.persistence.OneToMany;
- import javax.persistence.OrderColumn;
- import javax.persistence.Table;
- /**
- *
- * @author klaus
- */
- @Entity
- @Table(name = "users")
- public class User implements Serializable {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private int id;
- private String username;
- private String password;
- private boolean enabled;
- @OneToMany(fetch = FetchType.LAZY)
- @JoinTable
- private Set<UserRole> userRole = new HashSet<UserRole>();
- @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
- // @JoinColumn(name="user_id", nullable=false)
- // @JoinTable(name = "HOST_USER", joinColumns = @JoinColumn(name = "USER_ID"), inverseJoinColumns = @JoinColumn(name = "HOST_ID"))
- // @JoinColumn(name="user_id", nullable=false)
- // @OrderColumn
- private Set<Host> hosts = new HashSet<>();
- public User() {
- }
- public User(String username, String password) {
- this.username = username;
- this.password = password;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- 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 Set<Host> getHosts() {
- return hosts;
- }
- public void setHosts(Set<Host> hosts) {
- this.hosts = hosts;
- }
- public void addHost(Host host) {
- this.hosts.add(host);
- }
- public boolean getHost(Host host) {
- return hosts.contains(host);
- }
- public boolean isEnabled() {
- return enabled;
- }
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
- public Set<UserRole> getUserRole() {
- return userRole;
- }
- public void setUserRole(Set<UserRole> userRole) {
- this.userRole = userRole;
- }
- public void addUserRole(UserRole userRole) {
- this.userRole.add(userRole);
- }
- public Host getHostIndexById(int hostId) {
- for (Host host : hosts) {
- if (host.getId() == hostId) {
- return host;
- }
- }
- return null;
- }
- @Override
- public int hashCode() {
- int hash = 7;
- hash = 29 * hash + this.id;
- hash = 29 * hash + Objects.hashCode(this.username);
- return hash;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final User other = (User) obj;
- return true;
- }
- @Override
- public String toString() {
- return "User{" + "id=" + id + ", username=" + username + ", password=" + password + ", hosts=" + hosts + '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement