LanEventPropertyFacade.java 1.22 KB
package fi.insomnia.bortal.facade;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.model.LanEvent;
import fi.insomnia.bortal.model.LanEventProperty;
import fi.insomnia.bortal.model.LanEventPropertyKey;
import fi.insomnia.bortal.model.LanEventProperty_;

@Stateless
@LocalBean
public class LanEventPropertyFacade extends IntegerPkGenericFacade<LanEventProperty> {

	public LanEventPropertyFacade() {
		super(LanEventProperty.class);
	}

	@EJB
	private EventBeanLocal eventbean;

	public LanEventProperty find(LanEvent currentEvent, LanEventPropertyKey property) {
		CriteriaBuilder cb = getEm().getCriteriaBuilder();
		CriteriaQuery<LanEventProperty> cq = cb.createQuery(LanEventProperty.class);
		Root<LanEventProperty> root = cq.from(LanEventProperty.class);

		CriteriaQuery<LanEventProperty> q = cq.where(cb.equal(root.get(LanEventProperty_.event), eventbean.getCurrentEvent()),
				cb.equal(root.get(LanEventProperty_.key), property)
				);
		return getSingleNullableResult(getEm().createQuery(q));
	}
}