package ub.scp2.daoImpl;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import ub.scp2.dao.TestResultDao;
import ub.scp2.entities.TestResult;

/**
 * TaskDaoImpl.java -this class implements the TaskDao. This is the Data Acces Object of the Task entity
 * @author serral
 *
 */
public class TestResultDaoImpl implements TestResultDao, java.io.Serializable {
	
	SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	/**
	 * Delete testresult in database
	 */
	@Override
	public void deleteTestResult(TestResult testResult) {
		 Session session = sessionFactory.getCurrentSession();
		 
		 try{
			 session.delete(testResult);
			 session.flush(); 
		 }catch(Exception e){
			 e.printStackTrace();
		 }
	}

	/**
	 * Save testresult in database
	 */
	@Override
	public void saveTestResult(TestResult testResult) {
		 Session session = sessionFactory.getCurrentSession();
		 
		 try{
			 session.save(testResult);
			 session.flush(); 
		 }catch(Exception e){
			 e.printStackTrace();
		 }
	}

}
