Package javax.persistence.criteria

Examples of javax.persistence.criteria.Root


            CriteriaQuery<JPACommit> query = criteriaBuilder.createQuery(JPACommit.class);
            Root<JPACommit> from = query.from(JPACommit.class);
            query.select(from);

            Subquery<Number> subquery = query.subquery(Number.class);
            Root maxTime = subquery.from(JPACommit.class);
            subquery.select(criteriaBuilder.max(maxTime.get("timestamp")));
            subquery.where(criteriaBuilder.le(maxTime.get("timestamp"), timestamp));

            query.where(criteriaBuilder.equal(from.get("timestamp"), subquery));

            TypedQuery<JPACommit> typedQuery = entityManager.createQuery(query);
            return typedQuery.getResultList();
View Full Code Here


  private boolean hasImplicitSelection() {
    if ( getRoots().size() != 1 ) {
      return false;
    }

    Root root = getRoots().iterator().next();
        Class<?> javaType = root.getModel().getJavaType();
        if ( javaType != null && javaType != returnType ) {
      return false;
    }

    // if we get here, the query defined no selection but defined a single root of the same type as the
View Full Code Here

  private boolean hasImplicitSelection() {
    if ( getRoots().size() != 1 ) {
      return false;
    }

    Root root = getRoots().iterator().next();
        Class<?> javaType = root.getModel().getJavaType();
        if ( javaType != null && javaType != returnType ) {
      return false;
    }

    // if we get here, the query defined no selection but defined a single root of the same type as the
View Full Code Here

      EntityManager em = emf.createEntityManager();

      try {
         CriteriaBuilder cb = em.getCriteriaBuilder();
         CriteriaQuery cq = cb.createQuery();
         Root root = cq.from(configuration.entityClass());
         Type idType = root.getModel().getIdType();
         SingularAttribute idAttr = root.getModel().getId(idType.getJavaType());
         cq.select(root.get(idAttr));

         for (final Object key : em.createQuery(cq).getResultList()) {
            if (taskContext.isStopped())
               break;
            if (filter != null && !filter.shouldLoadKey(key)) {
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

  private boolean hasImplicitSelection() {
    if ( getRoots().size() != 1 ) {
      return false;
    }

    Root root = getRoots().iterator().next();
        Class<?> javaType = root.getModel().getJavaType();
        if ( javaType != null && javaType != returnType ) {
      return false;
    }

    // if we get here, the query defined no selection but defined a single root of the same type as the
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

 
  @Test
  public void shouldConstructCriteriaQuery() {
    Filter filter = new Filter(mock(Condition.class), mock(Condition.class));
    CriteriaBuilder builder = mock(CriteriaBuilder.class);
    Root root = mock(Root.class);
    Predicate p1 = mock(Predicate.class);
    Predicate p2 = mock(Predicate.class);
    when(filter.getConditions().get(0).constructQuery(builder, root)).thenReturn(p1);
    when(filter.getConditions().get(1).constructQuery(builder, root)).thenReturn(p2);
    CriteriaQuery query = mock(CriteriaQuery.class);
View Full Code Here

 
  @Test
  public void shouldConstructCriteriaDeleteQuery() {
    Filter filter = new Filter(mock(Condition.class), mock(Condition.class));
    CriteriaBuilder builder = mock(CriteriaBuilder.class);
    Root root = mock(Root.class);
    Predicate p1 = mock(Predicate.class);
    Predicate p2 = mock(Predicate.class);
    when(filter.getConditions().get(0).constructQuery(builder, root)).thenReturn(p1);
    when(filter.getConditions().get(1).constructQuery(builder, root)).thenReturn(p2);
    CriteriaDelete query = mock(CriteriaDelete.class);
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.