package uk.org.adamretter.webexample.dao.hibernate;

import java.util.Date;
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import uk.org.adamretter.webexample.dao.ConferenceDao;
import uk.org.adamretter.webexample.model.Conference;

/**
 *
 * @author aretter
 */
public class ConferenceDaoImpl implements ConferenceDao {
    
    private SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
    
    public List<Conference> getConferencesAfter(Date date) {
        return (List<Conference>) getSessionFactory().getCurrentSession()
                .createCriteria(Conference.class)
                .add(Restrictions.ge("date", date))
                .list();
    }

    public void persist(Conference conference) {
        getSessionFactory().getCurrentSession()
                .saveOrUpdate(conference);
    }
}
