Package javax.persistence.criteria

Examples of javax.persistence.criteria.Root


     * @param entity
     *            metamodel entity representing the entity of type X
     * @return query root corresponding to the given entity
     */
    public <X> Root<X> from(EntityType<X> entity){
        Root root = new RootImpl<X>(entity, this.metamodel, entity.getBindableJavaType(), new ExpressionBuilder(entity.getBindableJavaType()), entity);
        this.roots.add(root);
        return root;
    }
View Full Code Here


            }
            if (this.where != null && ((InternalSelection)this.where).getCurrentNode() != null){
                reportQuery.setReferenceClass(((InternalSelection)this.where).getCurrentNode().getBuilder().getQueryClass());
                reportQuery.setExpressionBuilder(((InternalSelection)this.where).getCurrentNode().getBuilder());
            }else{
                Root root = this.getRoots().iterator().next();
                reportQuery.setReferenceClass(root.getJavaType());
                reportQuery.setExpressionBuilder(((RootImpl)root).getCurrentNode().getBuilder());
            }
            query = reportQuery;
        }
        if (this.where != null){
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

  // for EK-RTC
  private List<Object> findAllByStaffType(Class entityClass,
      String staffType, String x) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery();
    Root r = cq.from(entityClass);
    cq.select(r.get(x));
    Predicate predicate = cb.equal(r.get("staffTypeCode"), staffType);
    cq.where(predicate);
    return em.createQuery(cq).getResultList();
  }
View Full Code Here

  private List<Object> findAllByColumnList(Class entityClass,
      List<String> colsToSelect, Map<String, String> whereClauseCriteria) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery();
    Root r = cq.from(entityClass);
    List<Selection> selections = new ArrayList<>();
    for (String col : colsToSelect) {
      selections.add(r.get(col));
    }
    // cq.multiselect(selections);


    List<Predicate> predicates = new ArrayList<Predicate>();
    for (String col : whereClauseCriteria.keySet()) {
      predicates.add(cb.equal(r.get(col), whereClauseCriteria.get(col)));
    }
    cq.multiselect(selections)
        .where(predicates.toArray(new Predicate[] {}));
    return em.createQuery(cq).getResultList();
  }
View Full Code Here

    //Object clazz = null;
    Specification spec = DynamicSpecifications.bySearchFilter(request, clazz.getClass(), filterSet);
   
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery criteriaQuery = builder.createQuery(clazz.getClass());
    Root root = criteriaQuery.from(clazz.getClass());
   
    Predicate predicate = spec.toPredicate(root, criteriaQuery, builder);
    criteriaQuery.where(predicate);
   
    List<Object> objects = em.createQuery(criteriaQuery).getResultList();
View Full Code Here

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

    Root root = getRoots().iterator().next();
    if ( root.getModel().getJavaType() != returnType ) {
      return false;
    }

    // if we get here, the query defined no selection but defined a single root of the same type as the
    // criteria query return, so we use that as the implicit selection
View Full Code Here

    if ( isDistinct() ) {
      jpaqlQuery.append( " distinct " );
    }
    if ( getSelection() == null ) {
      // we should have only a single root (query validation should have checked this...)
      final Root root = getRoots().iterator().next();
      jpaqlQuery.append( ( (ExpressionImplementor) root ).renderProjection( renderingContext) );
    }
    else {
      jpaqlQuery.append( ( (ExpressionImplementor) getSelection() ).renderProjection( renderingContext ) );
    }

    jpaqlQuery.append( " from " );
    String sep = "";
    for ( Root root : getRoots() ) {
      ( (TableExpressionMapper) root ).prepareAlias( renderingContext );
      jpaqlQuery.append( sep );
      jpaqlQuery.append( ( ( TableExpressionMapper ) root ).renderTableExpression( renderingContext ) );
      sep = ", ";
    }

    for ( Root root : getRoots() ) {
      renderJoins( jpaqlQuery, renderingContext, root.getJoins() );
      renderFetches( jpaqlQuery, renderingContext, root.getFetches() );
    }

    if ( getRestriction() != null) {
      jpaqlQuery.append( " where " )
          .append( ( (ExpressionImplementor) getRestriction() ).render( renderingContext ) );
View Full Code Here

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

    Root root = getRoots().iterator().next();
    if ( root.getModel().getJavaType() != returnType ) {
      return false;
    }

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

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.