Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaQuery.select()


    private List<Coursetag> findCoursetagEntities(boolean all, int maxResults, int firstResult) {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            cq.select(cq.from(Coursetag.class));
            Query q = em.createQuery(cq);
            if (!all) {
                q.setMaxResults(maxResults);
                q.setFirstResult(firstResult);
            }
View Full Code Here


    public int getCoursetagCount() {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            Root<Coursetag> rt = cq.from(Coursetag.class);
            cq.select(em.getCriteriaBuilder().count(rt));
            Query q = em.createQuery(cq);
            return ((Long) q.getSingleResult()).intValue();
        } finally {
            em.close();
        }
View Full Code Here

     * @param em the entitymanager to use.
     * @return a List containing all Orders.
     */
    public static List<Order> getAllOrders(EntityManager em) {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Order.class));
        return em.createQuery(cq).getResultList();
    }
   
    /**
     * Get all orders which the user with the given username has made.
View Full Code Here

        String jpql = "select c from Customer c "
                    + "where c.name='Autowest Toyota'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Customer> customer = q.from(Customer.class);
        q.select(customer)
         .where(cb.equal(
                customer.get(customer_.getSingularAttribute("name", String.class)),
                "Autowest Toyota"));

        assertEquivalence(q, jpql);
View Full Code Here

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

                LineItem.class));
        Join<Order, Customer> c = o.join(order_.getSingularAttribute("customer",
                Customer.class));
        q.where(cb.equal(c.get(customer_.getSingularAttribute("lastName", String.class)), "Smith"),
                cb.equal(c.get(customer_.getSingularAttribute("firstName", String.class)), "John"));
        q.select(cb.sum(i.get(lineItem_.getSingularAttribute("price", Double.class))));

        assertEquivalence(q, jpql);
    }
   
    public void testSizeExpressionInProjection() {
View Full Code Here

        q.where(cb.equal(
                d.get(department_.getSingularAttribute("name", String.class)),
                "Sales"));
        SetAttribute<Department, Employee> employees =
            department_.getDeclaredSet("employees", Employee.class);
        q.select(cb.size(d.get(employees)));
       
        assertEquivalence(q, jpql);
       
    }
   
View Full Code Here

    public void testEqualWithAttributeAndLiteral() {
        String jpql = "select a from Account a where a.balance=100";

        CriteriaQuery c = cb.createQuery();
        Root<Account> account = c.from(Account.class);
        c.select(account).where(cb.equal(account.get(Account_.balance), 100));

        assertEquivalence(c, jpql);
    }

    public void testEqualWithAttributeAndAttribute() {
View Full Code Here

    private List<TblMle> findTblMleEntities(boolean all, int maxResults, int firstResult) {
        EntityManager em = getEntityManager();
        try {
            CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
            cq.select(cq.from(TblMle.class));
            Query q = em.createQuery(cq);
            if (!all) {
                q.setMaxResults(maxResults);
                q.setFirstResult(firstResult);
            }
View Full Code Here

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.