MapQueueRulesFacade.java 1.65 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
package fi.codecrew.moya.facade;

import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.MapQueueRules;
import fi.codecrew.moya.model.MapQueueRules_;

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

@Stateless
@LocalBean
public class MapQueueRulesFacade extends IntegerPkGenericFacade<MapQueueRules> {
	public MapQueueRulesFacade() {
		super(MapQueueRules.class);
	}

	public MapQueueRules findByMap(EventMap map) {

		if(map == null) {
			throw new NullPointerException("Map must be given to MapQueueRules.findByMap");
		}

		CriteriaBuilder cb = getEm().getCriteriaBuilder();
		CriteriaQuery<MapQueueRules> cq = cb.createQuery(MapQueueRules.class);

		Root<MapQueueRules> root = cq.from(MapQueueRules.class);
		cq.where(cb.equal(root.get(MapQueueRules_.map), map));

		return getSingleNullableResult(getEm().createQuery(cq).setMaxResults(1));
	}

}