Role.java 4.74 KB
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fi.insomnia.bortal.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

/**
 * 
 */
@Entity
@Table(name = "roles")
@NamedQueries( {
	@NamedQuery(name = "Role.findAll", query = "SELECT r FROM Role r"),
	@NamedQuery(name = "Role.findByRolesId", query = "SELECT r FROM Role r WHERE r.rolesId = :rolesId"),
	@NamedQuery(name = "Role.findByRoleName", query = "SELECT r FROM Role r WHERE r.roleName = :roleName") })
public class Role implements ModelInterface {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "roles_id", nullable = false)
    private Integer id;

    @Column(name = "role_name", nullable = false)
    private String roleName;

    @ManyToMany(cascade = CascadeType.ALL)
    private List<User> users;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "rolesId")
    private List<RoleInheritance> roleInheritanceList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "inherits")
    private List<RoleInheritance> roleInheritanceList1;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "rolesId")
    private List<RoleRight> roleRightList;

    @JoinColumn(name = "card_templates_id", referencedColumnName = "card_templates_id")
    @ManyToOne
    private CardTemplate cardTemplate;

    @JoinColumn(name = "events_id", referencedColumnName = "events_id", nullable = false)
    @ManyToOne(optional = false)
    private Event eventsId;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "role")
    private List<Discount> discounts;

    @Version
    @Column(nullable = false)
    private int jpaVersionField;

    public Role() {
    }

    public Role(Integer rolesId) {
	this.id = rolesId;
    }

    public Role(Integer rolesId, String roleName) {
	this.id = rolesId;
	this.roleName = roleName;
    }

    public String getRoleName() {
	return roleName;
    }

    public void setRoleName(String roleName) {
	this.roleName = roleName;
    }

    public List<RoleInheritance> getRoleInheritanceList() {
	return roleInheritanceList;
    }

    public void setRoleInheritanceList(List<RoleInheritance> roleInheritanceList) {
	this.roleInheritanceList = roleInheritanceList;
    }

    public List<RoleInheritance> getRoleInheritanceList1() {
	return roleInheritanceList1;
    }

    public void setRoleInheritanceList1(
	    List<RoleInheritance> roleInheritanceList1) {
	this.roleInheritanceList1 = roleInheritanceList1;
    }

    public List<RoleRight> getRoleRightList() {
	return roleRightList;
    }

    public void setRoleRightList(List<RoleRight> roleRightList) {
	this.roleRightList = roleRightList;
    }

    public CardTemplate getCardTemplate() {
	return cardTemplate;
    }

    public void setCardTemplate(CardTemplate cardTemplatesId) {
	this.cardTemplate = cardTemplatesId;
    }

    public Event getEventsId() {
	return eventsId;
    }

    public void setEventsId(Event eventsId) {
	this.eventsId = eventsId;
    }

    @Override
    public int hashCode() {
	int hash = 0;
	hash += (getId() != null ? getId().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 Role)) {
	    return false;
	}
	Role other = (Role) object;
	if ((this.getId() == null && other.getId() != null)
		|| (this.getId() != null && !this.id.equals(other.id))) {
	    return false;
	}
	return true;
    }

    @Override
    public String toString() {
	return "fi.insomnia.bortal.model.Role[rolesId=" + getId() + "]";
    }

    /**
     * @return the id
     */
    public Integer getId() {
	return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(Integer id) {
	this.id = id;
    }

    /**
     * @return the jpaVersionField
     */
    public int getJpaVersionField() {
	return jpaVersionField;
    }

    /**
     * @param jpaVersionField
     *            the jpaVersionField to set
     */
    public void setJpaVersionField(int jpaVersionField) {
	this.jpaVersionField = jpaVersionField;
    }

    public void setUsers(List<User> users) {
	this.users = users;
    }

    public List<User> getUsers() {
	return users;
    }

    public void setDiscounts(List<Discount> discounts) {
	this.discounts = discounts;
    }

    public List<Discount> getDiscounts() {
	return discounts;
    }
}