package ub.scp2.daoImpl;


import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import ub.scp2.dao.FileTaskDao;
import ub.scp2.entities.FileTask;


/**
 * LanguajeBoImpl.java -this class implements the LanguajeBo. This is the Business Object of the Languaje entity 
 * 
 *
 */
public class FileTaskDaoImpl implements FileTaskDao, java.io.Serializable {
	SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

        @Override
        public void saveFileTask(FileTask fileTask) {
		 Session session = sessionFactory.getCurrentSession();
		 try{
			 session.save(fileTask);
			 session.flush();
		 }catch(Exception e){
			 e.printStackTrace();
		 }
        }

        @Override
        public void deleteFileTask(FileTask fileTask) {
		 Session session = sessionFactory.getCurrentSession();
		 try{
			 session.delete(fileTask);
			 session.flush();
		 }catch(Exception e){
			 e.printStackTrace();
		 }
        }

        @Override
        public void updateFileTask(FileTask fileTask) {
		 Session session = sessionFactory.getCurrentSession();
		 try{
			 session.update(fileTask);
			 session.flush();
		 }catch(Exception e){
			 e.printStackTrace();
		 }
        }

        @Override
        public List<FileTask> getFileTasks() {
		 Session session = sessionFactory.getCurrentSession();
		 try{
			 return session.createQuery( "FROM task_file" ).list();
		 }catch(Exception e){
			 e.printStackTrace();
		 }
		return null;
        }

        @Override
        public List<FileTask> getFileByTaskId(long id) {
		 Session session = sessionFactory.getCurrentSession();
		 try{
			 return session.createQuery( "FROM task_file tf WHERE tf.task_id = "+id ).list();
		 }catch(Exception e){
			 e.printStackTrace();
		 }
		return null;
        }
}
