de.terrestris.shoguncore.model.UserGroup Maven / Gradle / Ivy
package de.terrestris.shoguncore.model;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
/**
* @author Nils Bühner
*/
@Entity
@Table
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class UserGroup extends PersistentObject {
private static final long serialVersionUID = 1L;
@Column
private String name;
@ManyToOne
private User owner;
@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Fetch(FetchMode.JOIN)
@JoinTable(
name = "user_usergroup",
joinColumns = {@JoinColumn(name = "USERGROUP_ID")},
inverseJoinColumns = {@JoinColumn(name = "USER_ID")}
)
private Set members = new HashSet();
@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JoinTable(
joinColumns = {@JoinColumn(name = "USERGROUP_ID")},
inverseJoinColumns = {@JoinColumn(name = "ROLE_ID")}
)
private Set roles = new HashSet();
/**
* Default Constructor
*/
public UserGroup() {
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the owner
*/
public User getOwner() {
return owner;
}
/**
* @param owner the owner to set
*/
public void setOwner(User owner) {
this.owner = owner;
}
/**
* @return the members
*/
public Set getMembers() {
return members;
}
/**
* @param members the members to set
*/
public void setMembers(Set members) {
this.members = members;
}
/**
* @return the roles
*/
public Set getRoles() {
return roles;
}
/**
* @param roles the roles to set
*/
public void setRoles(Set roles) {
this.roles = roles;
}
/**
* @see java.lang.Object#hashCode()
*
* According to
* http://stackoverflow.com/questions/27581/overriding-equals
* -and-hashcode-in-java it is recommended only to use getter-methods
* when using ORM like Hibernate
*/
@Override
public int hashCode() {
// two randomly chosen prime numbers
return new HashCodeBuilder(53, 19).
appendSuper(super.hashCode()).
append(getName()).
append(getOwner()).
append(getMembers()).
append(getRoles()).
toHashCode();
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*
* According to
* http://stackoverflow.com/questions/27581/overriding-equals
* -and-hashcode-in-java it is recommended only to use getter-methods
* when using ORM like Hibernate
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof UserGroup)) {
return false;
}
UserGroup other = (UserGroup) obj;
return new EqualsBuilder().
appendSuper(super.equals(other)).
append(getName(), other.getName()).
append(getOwner(), other.getOwner()).
append(getMembers(), other.getMembers()).
append(getRoles(), other.getRoles()).
isEquals();
}
}