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

package manager;

import entities.Thesis;
import entities.ThesisStudent;
import entities.Users;
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 ThesisStudentSessionBean implements ThesisStudentSessionBeanRemote {
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @PersistenceContext
    private EntityManager em;

    public void newThesisStudent(ThesisStudent t) {
        em.persist(t);
    }

    public List<Thesis> findByStudent(Users u){
        Query query = em.createNamedQuery("ThesisStudent.findByStudent");
        query.setParameter("studentId", u);
        return query.getResultList();
    }

    public ThesisStudent findByStudentID(Users u){
        Query query = em.createNamedQuery("ThesisStudent.findByStudentID");
        query.setParameter("studentId", u);
        return (ThesisStudent)query.getResultList().get(0);
    }

    public List<Users> findByThesisID(Thesis t){
        Query query = em.createNamedQuery("ThesisStudent.findByThesis");
        query.setParameter("thesisId", t);
        return query.getResultList();
    }

    public void update(ThesisStudent t) {
        Query q = em.createNamedQuery("ThesisStudent.update");
        q.setParameter("id", t.getId());
        q.setParameter("thesisId", t.getThesisId());
        q.executeUpdate();
    }

    public void delete(ThesisStudent t) {
        Query q = em.createNamedQuery("ThesisStudent.delete");
        q.setParameter("id", t.getId());
        q.executeUpdate();
    }
}
