/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author Szilárd
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Indexbook.findBySemesterAndUser", query = "SELECT i.subjectId FROM Indexbook i WHERE i.semesterId = :semesterId AND i.studentId = :studentId"),
    @NamedQuery(name = "Indexbook.findBySAndU", query = "SELECT i FROM Indexbook i WHERE i.semesterId = :semesterId AND i.studentId = :studentId"),
    @NamedQuery(name = "Indexbook.findBySemesterAndUserANDSubjectId", query = "SELECT i FROM Indexbook i WHERE i.semesterId = :semesterId AND i.studentId = :studentId AND i.subjectId = :subjectId" ),
    @NamedQuery(name = "Indexbook.findByUserAndSigned", query = "SELECT i.subjectId FROM Indexbook i WHERE i.studentId = :studentId AND i.signature = :signature AND i.mark < :mark"),
    @NamedQuery(name = "Indexbook.findByUserAndMark", query = "SELECT i.subjectId FROM Indexbook i WHERE i.studentId = :studentId AND i.mark > :mark"),
    @NamedQuery(name = "Indexbook.updateSign", query = "UPDATE Indexbook i SET i.signature = :signature, i.signed = :signed WHERE i.id = :id"),
    @NamedQuery(name = "Indexbook.updateMark", query = "UPDATE Indexbook i SET i.mark = :mark, i.marked = :marked  WHERE i.id = :id"),
    @NamedQuery(name = "Indexbook.delete", query = "DELETE FROM  Indexbook i WHERE i.id = :id")
})

public class Indexbook implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @JoinColumn(name = "Semester_Id", referencedColumnName = "ID")
    @ManyToOne
    private Semester semesterId;
     public Semester getSemesterId() {
        return semesterId;
    }

    public void setSemesterId(Semester semesterId) {
        this.semesterId = semesterId;
    }

    @JoinColumn(name = "Subject_Id", referencedColumnName = "ID")
    @ManyToOne
    private Subject subjectId;
    public Subject getSubjectId() {
        return subjectId;
    }

    public void setSubjectId(Subject subjectId) {
        this.subjectId = subjectId;
    }

    @JoinColumn(name = "Student_Id", referencedColumnName = "ID")
    @ManyToOne
    private Users studentId;

    public Users getStudentId() {
        return studentId;
    }

    public void setStudentId(Users studentId) {
        this.studentId = studentId;
    }

    @Column(name="SIGNATURE")
    protected int signature;

    public int getSignature() {
        return signature;
    }

    public void setSignature(int signature) {
        this.signature = signature;
    }

    @Column(name="SIGNED",  length=20)
    protected String signed;

    public String getSigned() {
        return signed;
    }

    public void setSigned(String signed) {
        this.signed = signed;
    }

    @Column(name="MARK")
    protected int mark;

    public int getMark() {
        return mark;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }

    @Column(name="MARKED",  length=20)
    protected String marked;

    public String getMarked() {
        return marked;
    }

    public void setMarked(String marked) {
        this.marked = marked;
    }

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

    @Override
    public String toString() {
        return "entities.Indexbook[id=" + id + "]";
    }

}
