Package ru.portnyagin.helpdeskru.service

Source Code of ru.portnyagin.helpdeskru.service.HistoryRequestService

/**
*
* @author ilya portnyagin iportnyagin@gmail.com
*/

package ru.portnyagin.helpdeskru.service;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import ru.portnyagin.helpdeskru.model.HistoryRequest;
import ru.portnyagin.helpdeskru.model.HistoryRequest_;
import ru.portnyagin.helpdeskru.model.Request;

@Stateless
public class HistoryRequestService extends AbstractService<HistoryRequest> {
    @PersistenceContext(unitName = "HelpDeskRuPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public HistoryRequestService() {
        super(HistoryRequest.class);
    }
   
    public List<HistoryRequest> find(Request request) {
        if (request == null) {
            return null;
        }
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<HistoryRequest> h = cq.from(HistoryRequest.class);
        cq.where(cb.equal(h.get(HistoryRequest_.request), request));
        cq.orderBy(cb.desc(h.get(HistoryRequest_.modifiedDate)));
       
        cq.select(h);

        return em.createQuery(cq).getResultList();
    }
       
           
           
       
}
TOP

Related Classes of ru.portnyagin.helpdeskru.service.HistoryRequestService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.