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

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

/**
 * 
 * @author jkj
 */
@Entity
@Table(name = "role_rights")
@NamedQueries( {
	@NamedQuery(name = "RoleRight.findAll", query = "SELECT r FROM RoleRight r"),
	@NamedQuery(name = "RoleRight.findByRoleRights", query = "SELECT r FROM RoleRight r WHERE r.roleRights = :roleRights"),
	@NamedQuery(name = "RoleRight.findByRead", query = "SELECT r FROM RoleRight r WHERE r.read = :read"),
	@NamedQuery(name = "RoleRight.findByWrite", query = "SELECT r FROM RoleRight r WHERE r.write = :write") })
public class RoleRight implements ModelInterface {

    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "role_rights_id", nullable = false)
    private Integer id;

    @Column(name = "read", nullable = false)
    private boolean read;

    @Column(name = "write", nullable = false)
    private boolean write;
    // TODO: add execute
    @JoinColumn(name = "access_rights_id", referencedColumnName = "access_rights_id")
    @ManyToOne
    private AccessRight accessRightsId;
    @JoinColumn(name = "roles_id", referencedColumnName = "roles_id", nullable = false)
    @ManyToOne(optional = false)
    private Role rolesId;
    @Version
    @Column(nullable = false)
    private int jpaVersionField;

    public RoleRight() {
    }

    public RoleRight(Integer roleRights) {
	this.id = roleRights;
    }

    public RoleRight(Integer roleRights, boolean read, boolean write) {
	this.id = roleRights;
	this.read = read;
	this.write = write;
    }

    public boolean getRead() {
	return read;
    }

    public void setRead(boolean read) {
	this.read = read;
    }

    public boolean getWrite() {
	return write;
    }

    public void setWrite(boolean write) {
	this.write = write;
    }

    public AccessRight getAccessRightsId() {
	return accessRightsId;
    }

    public void setAccessRightsId(AccessRight accessRightsId) {
	this.accessRightsId = accessRightsId;
    }

    public Role getRolesId() {
	return rolesId;
    }

    public void setRolesId(Role rolesId) {
	this.rolesId = rolesId;
    }

    @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 RoleRight)) {
	    return false;
	}
	RoleRight other = (RoleRight) 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.RoleRight[roleRights=" + 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;
    }
}