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

package manager;

import entities.Semester;
import entities.Thesis;
import entities.Users;
import helper.SchoolYearState;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Szilárd
 */
@Stateless
public class ThesisSessionBean implements ThesisSessionBeanRemote {
    
    @PersistenceContext
    private EntityManager em;

    public void newThesis(Thesis t) {
        em.persist(t);
    }

    public List<Thesis> allThesis() {
        Query query = em.createNamedQuery("Thesis.findAll");
        return query.getResultList();
    }

    public List<Thesis> findAktiv(){
        Semester aktivSemester;
        Query q = em.createNamedQuery("Semester.findOpen");
        q.setParameter("state", SchoolYearState.OPEN);
        aktivSemester =(Semester) q.getResultList().get(0);

        Query query = em.createNamedQuery("Thesis.findBySemester");
        query.setParameter("semesterId", aktivSemester);
        return query.getResultList();
    }

    public List<Thesis> findBySemester(Semester sem){
        Query query = em.createNamedQuery("Thesis.findBySemester");
        query.setParameter("semesterId", sem);
        return query.getResultList();
    }

    public List<Thesis> findBySemesterANDTeeacher(Semester sem, Users u){
        Query query = em.createNamedQuery("Thesis.findBySemesterANDTeacher");
        query.setParameter("semesterId", sem);
        query.setParameter("teacherId", u);
        return query.getResultList();
    }

 
}
