Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaBuilder.desc()


        CriteriaQuery<Person> personQuery = criteriaBuilder.createQuery(Person.class);
        Root<Person> from = personQuery.from(Person.class);
        personQuery.select(from.alias("p"));
        personQuery.where(criteriaBuilder.and(criteriaBuilder.equal(from.get("personName"), "vivek"),
                criteriaBuilder.gt((Expression)from.get("age"), 32),criteriaBuilder.le((Expression)from.get("salary"), 3200.01)));
        personQuery.orderBy(criteriaBuilder.desc(from.get("personName")));
        String actual = CriteriaQueryTranslator.translate(personQuery);
        Assert.assertEquals(expected.trim(), actual.trim());
    }

    @Test
View Full Code Here


    public final void whenSortingFooWithCriteriaAndMultipleAttributes_thenPrintSortedFoos() {
        final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
        final CriteriaQuery<Foo> criteriaQuery = criteriaBuilder.createQuery(Foo.class);
        final Root<Foo> from = criteriaQuery.from(Foo.class);
        final CriteriaQuery<Foo> select = criteriaQuery.select(from);
        criteriaQuery.orderBy(criteriaBuilder.asc(from.get("name")), criteriaBuilder.desc(from.get("id")));
        final TypedQuery<Foo> typedQuery = entityManager.createQuery(select);
        final List<Foo> fooList = typedQuery.getResultList();
        for (final Foo foo : fooList) {
            System.out.println("Name:" + foo.getName() + "-------Id:" + foo.getId());
        }
View Full Code Here

        query.select(product);

        if(asc) {
            query.orderBy(cb.asc(product.get("price")));
        } else {
            query.orderBy(cb.desc(product.get("price")));
        }

        if(filter != null && filter.length() > 0) {
            query.where(cb.like(product.<String>get("name"), filter + "%"));
        }
View Full Code Here

          currentNode = currentNode.get(propPart);
        }
       
        String d = sorter.getDirection();
        boolean isDesc = d != null && d.toLowerCase().equals("desc");
        order.add(isDesc ? builder.desc(currentNode) : builder.asc(currentNode));
      }
      query.orderBy(order);

     
      /*
 
View Full Code Here

        spentSort.add(prop);
       
        Path<String> p = root.get(prop);
        String d = sorter.getDirection();
        boolean isDesc = d != null && d.toLowerCase().equals("desc");
        order.add(isDesc ? builder.desc(p) : builder.asc(p));
      }
      query.orderBy(order);

     
      /*
 
View Full Code Here

        PersistenceOrdering ordering = (PersistenceOrdering) it.next();

        if (ordering.isAscending())
          cq.orderBy(cb.asc(entity.get(ordering.getPropertyName())));
        else
          cq.orderBy(cb.desc(entity.get(ordering.getPropertyName())));
      }
      // cq.where(cb.equal(entity.get(Order_.orderNumber), orderNumber));

      for (Iterator it = query.getCriterions(); it.hasNext();)
      {
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.