Package javax.persistence.criteria

Examples of javax.persistence.criteria.Root


  public void shouldConstructCriteriaQueryWithSortFields() {
    Filter filter = new Filter();
    filter.addSortField(mock(SortField.class));
    filter.addSortField(mock(SortField.class));
    CriteriaBuilder builder = mock(CriteriaBuilder.class);
    Root root = mock(Root.class);
    Order order1 = mock(Order.class);
    Order order2 = mock(Order.class);
    when(filter.getSortFields().get(0).getOrder(builder, root)).thenReturn(order1);
    when(filter.getSortFields().get(1).getOrder(builder, root)).thenReturn(order2);
    CriteriaQuery query = mock(CriteriaQuery.class);
View Full Code Here


        }
        if (query.getReferenceClass() == null){
            if (this.where != null && ((InternalSelection) this.where).getCurrentNode() != null && ((InternalSelection) this.where).getCurrentNode().getBuilder() != null && ((InternalSelection) this.where).getCurrentNode().getBuilder().getQueryClass() != null) {
                query.setReferenceClass(((InternalSelection) this.where).getCurrentNode().getBuilder().getQueryClass());
            } else if (roots != null && ! roots.isEmpty()){
                Root root = this.getRoots().iterator().next();
                query.setReferenceClass(root.getJavaType());
            }
        }

        if (selection == null) {
            //the builder in the where clause  may not be the correct builder for this query.  Search for a root that matches the query type.
            if (roots != null && ! roots.isEmpty()){
                for (Root root : this.getRoots()){
                    if (root.getJavaType().equals(this.queryType)){
                        query.setExpressionBuilder(((RootImpl) root).getCurrentNode().getBuilder());
                        break;
                    }
                }
            }
View Full Code Here

        }
        if (query.getReferenceClass() == null){
            if (this.where != null && ((InternalSelection) this.where).getCurrentNode() != null && ((InternalSelection) this.where).getCurrentNode().getBuilder() != null && ((InternalSelection) this.where).getCurrentNode().getBuilder().getQueryClass() != null) {
                query.setReferenceClass(((InternalSelection) this.where).getCurrentNode().getBuilder().getQueryClass());
            } else if (roots != null && ! roots.isEmpty()){
                Root root = this.getRoots().iterator().next();
                query.setReferenceClass(root.getJavaType());
            }
        }

        if (selection == null) {
            //the builder in the where clause  may not be the correct builder for this query.  Search for a root that matches the query type.
            if (roots != null && ! roots.isEmpty()){
                for (Root root : this.getRoots()){
                    if (root.getJavaType().equals(this.queryType)){
                        query.setExpressionBuilder(((RootImpl) root).getCurrentNode().getBuilder());
                        break;
                    }
                }
            }
View Full Code Here

        return q.getResultList();
    }

    public int count(Class classe) {
        CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        Root rt = cq.from(classe);
        cq.select(getEntityManager().getCriteriaBuilder().count(rt));
        Query q = getEntityManager().createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }
View Full Code Here

        return q.getResultList();
    }

    public int count(Class classe) {
        CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        Root rt = cq.from(classe);
        cq.select(getEntityManager().getCriteriaBuilder().count(rt));
        Query q = getEntityManager().createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }
View Full Code Here

      Class beanClass = determineEntityClass(query.getObjectClass());

      CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
      CriteriaQuery cq = cb.createQuery(beanClass);

      Root entity = cq.from(beanClass);
      cq.select(entity);

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

Related Classes of javax.persistence.criteria.Root

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.