RoleRight.java 3.86 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.findById", query = "SELECT r FROM RoleRight r WHERE r.id = :id"),
	@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"),
	@NamedQuery(name = "RoleRight.findByExecute", query = "SELECT r FROM RoleRight r WHERE r.execute = :execute") })
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;

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

    @JoinColumn(name = "access_rights_id", referencedColumnName = "access_rights_id")
    @ManyToOne
    private AccessRight accessRight;

    @JoinColumn(name = "roles_id", referencedColumnName = "roles_id", nullable = false)
    @ManyToOne(optional = false)
    private Role role;

    @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 getAccessRight() {
	return accessRight;
    }

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

    public Role getRole() {
	return role;
    }

    public void setRole(Role rolesId) {
	this.role = 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
     */
    @Override
    public Integer getId() {
	return id;
    }

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

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

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

    public void setExecute(boolean execute) {
	this.execute = execute;
    }

    public boolean isExecute() {
	return execute;
    }
}