Role.java 4.97 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.Basic;
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;

/**
 *
 * @author jkj
 */
@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;
    @OneToMany(mappedBy = "defaultRole")
    private List<Event> eventList;
    @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 cardTemplatesId;
    @JoinColumn(name = "events_id", referencedColumnName = "events_id", nullable = false)
    @ManyToOne(optional = false)
    private Event eventsId;
    @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<Event> getEventList() {
        return eventList;
    }

    public void setEventList(List<Event> eventList) {
        this.eventList = eventList;
    }

    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 getCardTemplatesId() {
        return cardTemplatesId;
    }

    public void setCardTemplatesId(CardTemplate cardTemplatesId) {
        this.cardTemplatesId = 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;
    }
}