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

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import uk.org.adamretter.webexample.dao.CategoryDao;
import uk.org.adamretter.webexample.model.Category;

/**
 *
 * @author aretter
 */
public class CategoryDaoImpl implements CategoryDao {
    
    private SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

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

    public Category getCategoryForTerm(String term) {
        return (Category) getSessionFactory().getCurrentSession()
                .createCriteria(Category.class)
                .add(Restrictions.eq("term", term))
                .uniqueResult();
    }
}
