package dao.jpa;
import dao.DataAccessException;
import dao.OrderStateDao;
import models.entities.OrderState;
import play.Logger;
import play.db.jpa.JPA;
import javax.persistence.TypedQuery;
/**
* Created by kiryl on 17.08.2014.
*/
public class OrderStateJpaDao extends BaseJpaDao<OrderState, Integer> implements OrderStateDao {
public OrderState findByName(String stateName) throws DataAccessException {
if (stateName == null) {
return null;
}
try {
TypedQuery<OrderState> query = JPA.em()
.createQuery("SELECT r FROM OrderState r WHERE r.name = :stateName", OrderState.class);
query.setParameter("stateName", stateName);
return query.getSingleResult();
} catch (Throwable throwable) {
Logger.error("Failed to get role by name: " + stateName);
throw new DataAccessException("Failed to get role by name: " + stateName, throwable);
}
}
}