Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaQuery


        super(Priority.class);
    }
   
    public List<Priority> findAll() {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<Priority> h = cq.from(Priority.class);
        cq.orderBy(cb.asc(h.get(Priority_.id)));
        return getEntityManager().createQuery(cq).getResultList();
    }
View Full Code Here


        super(StateRequest.class);
    }
   
    public void findMapStateRequest(Map<String, StateRequest> map) {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<StateRequest> z = cq.from(StateRequest.class);
        cq.select(z);
       
        List<StateRequest>x = em.createQuery(cq).getResultList();
       
        for(StateRequest xx: x) {
            map.put(xx.getId(), xx);
View Full Code Here

    // for CustomerController
    public List<Request> findByStateAndCustomer(List<StateRequest> listStateRequest, UserHD createdBy) {
       
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<Request> z = cq.from(Request.class);
           
        Predicate whereState = null;
       
        if(listStateRequest != null && !listStateRequest.isEmpty()) {
            for(StateRequest st: listStateRequest) {
                if(whereState == null) {
                    whereState = cb.equal(z.get(Request_.stateRequest), st);
                } else {
                    whereState = cb.or(whereState, cb.equal(z.get(Request_.stateRequest), st));
                }
            }
        }
       
        Predicate whereCreatedBy = null;
        Predicate whereCreatedByOrg = null;
       
        if(createdBy != null) {
           
            whereCreatedBy = cb.equal(z.get(Request_.createdBy), createdBy);
           
            if(createdBy.getOrganization() != null) {
                List<UserHD> listUsers = userHDService.findUsersByOrganization(createdBy.getOrganization());
                for(UserHD us: listUsers) {
                    if(whereCreatedByOrg == null) {
                        whereCreatedByOrg = cb.equal(z.get(Request_.createdBy), us);
                    } else {
                        whereCreatedByOrg = cb.or(whereCreatedByOrg, cb.equal(z.get(Request_.createdBy), us));
                    }
                }
            }       
        }
       
       
       
//        cq.where(cb.and(whereState, cb.or(whereCreatedBy, whereCreatedByOrg))); // у заказчика не задана орг-ия - whereCreatedByOrg - NPE

        if(whereCreatedByOrg == null) {
            cq.where(cb.and(whereState, whereCreatedBy));
        } else {
            cq.where(cb.and(whereState, cb.or(whereCreatedBy, whereCreatedByOrg)));
        }
       
       
        cq.orderBy(cb.desc(z.get(Request_.id)));
        cq.select(z);

        return getEntityManager().createQuery(cq).getResultList();
    }       
View Full Code Here

    // for ServiceController
    public List<Request> findByStateAndPerfomer(List<StateRequest> listStateRequest, UserHD perfomer,
            boolean showRequestOnlyForCurrentUser) {
       
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<Request> z = cq.from(Request.class);
           
        Predicate whereState = null;
       
        if(listStateRequest != null && !listStateRequest.isEmpty()) {
            for(StateRequest st: listStateRequest) {
                if(whereState == null) {
                    whereState = cb.equal(z.get(Request_.stateRequest), st);
                } else {
                    whereState = cb.or(whereState, cb.equal(z.get(Request_.stateRequest), st));
                }
            }
        }
       
        Predicate wherePerfomer = null;
       
        if(perfomer != null && showRequestOnlyForCurrentUser) {
            wherePerfomer = cb.equal(z.get(Request_.performer), perfomer);
        }
       
       
       
        if(wherePerfomer == null) {
            cq.where(whereState);
        } else {
            cq.where(cb.and(whereState, wherePerfomer));
        }

        cq.orderBy(cb.desc(z.get(Request_.id)));
        cq.select(z);

        return getEntityManager().createQuery(cq).getResultList();
    }       
View Full Code Here

    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();
    }
View Full Code Here

        super(ServiceObject.class);
    }
   
    public List<ServiceObject> findServiceObject(UserHD curUser) {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<ServiceObject> s = cq.from(ServiceObject.class);
       
        cq.where(cb.equal(s.get(ServiceObject_.organization), curUser.getOrganization()));
       
        cq.orderBy(cb.asc(s.get(ServiceObject_.id)));
        cq.select(s);
       
        return getEntityManager().createQuery(cq).getResultList();

       
    }
View Full Code Here

    }
   
    public List<FileHD> findByRequest(Request request) {
       
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery cq = cb.createQuery();
        Root<FileHD> z = cq.from(FileHD.class);
        cq.where(cb.equal(z.get(FileHD_.request), request));
        cq.select(z);
        return getEntityManager().createQuery(cq).getResultList();
       
    }
View Full Code Here

    public void testSetAndListJoins() {
        String jpql = "SELECT c.name FROM Customer c "
                    + "JOIN c.orders o JOIN o.lineItems i "
                    + "WHERE i.product.productType = 'printer'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Customer> c = q.from(Customer.class);
        SetJoin<Customer, Order> o = c.join(customer_.getSet("orders",
                Order.class));
        ListJoin<Order, LineItem> i = o.join(order_.getList("lineItems",
                LineItem.class));
        q.select(c.get(Customer_.name)).where(
                cb.equal(i.get(lineItem_.getSingularAttribute("product", Product.class))
                    .get(product_.getSingularAttribute("productType", String.class)),
                    "printer"));

        assertEquivalence(q, jpql);
View Full Code Here

    }

    public void testFetchJoins() {
        String jpql = "SELECT d FROM Department d LEFT JOIN FETCH d.employees "
                + "WHERE d.deptNo = 1";
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        d.fetch(department_.getSet("employees", Employee.class), JoinType.LEFT);
        q.where(
                cb.equal(d.get(department_
                        .getSingularAttribute("deptNo", Integer.class)), 1)).select(d);

        assertEquivalence(q, jpql);
    }
View Full Code Here

        assertEquivalence(q, jpql);
    }
   
    public void testTypeExpression() {
        String jpql = "SELECT TYPE(e) FROM Employee e WHERE TYPE(e) <> Exempt";
        CriteriaQuery q = cb.createQuery();
        Root<Employee> emp = q.from(Employee.class);
        q.select(emp.type()).where(cb.notEqual(emp.type(), Exempt.class));

        assertEquivalence(q, jpql);
    }
View Full Code Here

TOP

Related Classes of javax.persistence.criteria.CriteriaQuery

Copyright © 2018 www.massapicom. 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.