javax.persistence.criteria.Root.getJoins()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中javax.persistence.criteria.Root.getJoins方法的一些代码示例,展示了Root.getJoins的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Root.getJoins方法的具体详情如下:
包路径:javax.persistence.criteria.Root
类名称:Root
方法名:getJoins

Root.getJoins介绍

暂无

代码示例

代码示例来源:origin: kiegroup/jbpm

@Override
protected <T> Expression getEntityField(CriteriaQuery<T> query, String listId, Attribute attr) {
  if( attr == null ) {
    return null;
  }
  Root<TaskImpl> taskRoot = null;
  Join<TaskImpl, TaskDataImpl> taskDataJoin = null;
  Join<TaskImpl, PeopleAssignmentsImpl> peopAssignJoin = null;
  for( Root root : query.getRoots() ) {
    if( TaskImpl.class.equals(root.getJavaType()) ) {
      taskRoot = (Root<TaskImpl>) root;
      for( Join<TaskImpl, ?> join : taskRoot.getJoins() ) {
       if( TaskDataImpl.class.equals(join.getJavaType()) ) {
         taskDataJoin = (Join<TaskImpl, TaskDataImpl>) join;
       } else if( PeopleAssignmentsImpl.class.equals(join.getJavaType()) )  {
         peopAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) join;
       }
      }
    }
  }
  assert taskRoot != null : "Unable to find TaskImpl Root in query!";
  if( taskDataJoin == null ) {
    taskDataJoin = taskRoot.join(TaskImpl_.taskData);
  }
  assert taskDataJoin != null : "Unable to find TaskDataImpl Join in query!";
  return taskImplSpecificGetEntityField(query, taskRoot,
      taskDataJoin, peopAssignJoin,
      listId, attr);
}

代码示例来源:origin: kiegroup/jbpm

Join<TaskImpl,PeopleAssignmentsImpl> peopleAssignJoin = null;
if( taskRoot != null ) {
  for( Join<TaskImpl,?> join : taskRoot.getJoins() ) {
    if( join.getJavaType().equals(PeopleAssignmentsImpl.class) ) {
      peopleAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) join;

代码示例来源:origin: kiegroup/jbpm

private <T> void useDistinctWhenLefOuterJoinsPresent(CriteriaQuery<T> criteriaQuery) {
  boolean useDistinct = false;
  Root<TaskImpl> taskRoot = null;
  ROOTS_FOR: for( Root root : criteriaQuery.getRoots() ) {
    if( TaskImpl.class.equals(root.getJavaType()) ) {
      taskRoot = (Root<TaskImpl>) root;
      for( Join<TaskImpl, ?> taskJoin : taskRoot.getJoins() ) {
       if( PeopleAssignmentsImpl.class.equals(taskJoin.getJavaType()) )  {
         Join<TaskImpl, PeopleAssignmentsImpl> peopleAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) taskJoin;
         if( JoinType.LEFT.equals(peopleAssignJoin.getJoinType()) ) {
           useDistinct = true;
           break ROOTS_FOR;
         }
         for( Join peopleAssignJoinJoin : peopleAssignJoin.getJoins() ) {
           if( JoinType.LEFT.equals(peopleAssignJoinJoin.getJoinType()) ) {
             useDistinct = true;
             break ROOTS_FOR;
           }
         }
       }
      }
    }
  }
  if( useDistinct ) {
    criteriaQuery.distinct(true);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

renderJoins( jpaqlQuery, renderingContext, root.getJoins() );
if ( root instanceof RootImpl ) {
  Set<TreatedRoot> treats = ( (RootImpl) root ).getTreats();

代码示例来源:origin: org.omnifaces/omnipersistence

@Override
public Set<Join<X, ?>> getJoins() {
  return getWrapped().getJoins();
}

代码示例来源:origin: babyfish-ct/babyfish

protected void visitOnExpressions(XAbstractQuery<?> abstractQuery) {
  for (Root<?> root : abstractQuery.getRoots()) {
    for (Join<?, ?> join : root.getJoins()) {
      this.visitOnExpressions(join);
    }
  }
}

代码示例来源:origin: org.seedstack.addons.jpa/jpa

@Override
public long count(Specification<A> specification) {
  CriteriaBuilder cb = entityManager.getCriteriaBuilder();
  Class<A> entityClass = getAggregateRootClass();
  CriteriaQuery<Long> cq = cb.createQuery(Long.class);
  Root<A> root = cq.from(entityClass);
  cq.select(cb.count(root));
  cq.where(
      specificationTranslator.translate(specification, new JpaTranslationContext<>(cb, root)));
  if (!root.getJoins().isEmpty()) {
    // When we have joins, we need to deduplicate the results
    cq.distinct(true);
  }
  return entityManager.createQuery(cq).getSingleResult();
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-persistence

private void renderRoots(StringBuilder buffer, Collection<Root<?>> roots) {
  if (roots == null) return;
  int i = 0;
  for (Root r : roots) {
    buffer.append(((ExpressionImpl<?>)r).asVariable(this));
    if (++i != roots.size()) buffer.append(", ");
    renderJoins(buffer, r.getJoins());
    renderFetches(buffer, r.getFetches());
  }
}
private void renderFetches(StringBuilder buffer, Set<Fetch> fetches) {

代码示例来源:origin: org.apache.openjpa/openjpa-all

private void renderRoots(StringBuilder buffer, Collection<Root<?>> roots) {
  if (roots == null) return;
  int i = 0;
  for (Root r : roots) {
    buffer.append(((ExpressionImpl<?>)r).asVariable(this));
    if (++i != roots.size()) buffer.append(", ");
    renderJoins(buffer, r.getJoins());
    renderFetches(buffer, r.getFetches());
  }
}
private void renderFetches(StringBuilder buffer, Set<Fetch> fetches) {

代码示例来源:origin: org.apache.openjpa/openjpa-persistence

private void renderRoots(StringBuilder buffer, Collection<Root<?>> roots) {
  if (roots == null) return;
  int i = 0;
  for (Root r : roots) {
    buffer.append(((ExpressionImpl<?>)r).asVariable(this));
    if (++i != roots.size()) buffer.append(", ");
    renderJoins(buffer, r.getJoins());
    renderFetches(buffer, r.getFetches());
  }
}
private void renderFetches(StringBuilder buffer, Set<Fetch> fetches) {

代码示例来源:origin: org.apache.openejb.patch/openjpa

private void renderRoots(StringBuilder buffer, Collection<Root<?>> roots) {
  if (roots == null) return;
  int i = 0;
  for (Root r : roots) {
    buffer.append(((ExpressionImpl<?>)r).asVariable(this));
    if (++i != roots.size()) buffer.append(", ");
    renderJoins(buffer, r.getJoins());
    renderFetches(buffer, r.getFetches());
  }
}
private void renderFetches(StringBuilder buffer, Set<Fetch> fetches) {

代码示例来源:origin: osiam/server

@SuppressWarnings("unchecked")
protected <T> SetJoin<GroupEntity, T> createOrGetJoin(String alias, Root<GroupEntity> root,
    SetAttribute<GroupEntity, T> attribute) {
  for (Join<GroupEntity, ?> currentJoin : root.getJoins()) {
    if (currentJoin.getAlias().equals(alias)) {
      return (SetJoin<GroupEntity, T>) currentJoin;
    }
  }
  final SetJoin<GroupEntity, T> join = root.join(attribute, JoinType.LEFT);
  join.alias(alias);
  return join;
}

代码示例来源:origin: osiam/server

@SuppressWarnings("unchecked")
protected Join<UserEntity, NameEntity> createOrGetJoinForName(final Root<UserEntity> root) {
  for (final Join<UserEntity, ?> currentJoin : root.getJoins()) {
    if (currentJoin.getAlias() != null && currentJoin.getAlias().equals(JOIN_ALIAS_FOR_NAME)) {
      return (Join<UserEntity, NameEntity>) currentJoin;
    }
  }
  Join<UserEntity, NameEntity> join = root.join(UserEntity_.name, JoinType.LEFT);
  join.alias(JOIN_ALIAS_FOR_NAME);
  return join;
}

代码示例来源:origin: katharsis-project/katharsis-framework

public static boolean hasManyRootsFetchesOrJoins(CriteriaQuery<?> criteriaQuery) {
 Set<Root<?>> roots = criteriaQuery.getRoots();
 // more than one root, user is supposed to handle this manually
 if (roots.size() != 1)
  return false;
 for (Root<?> root : roots) {
  if (containsMultiRelationFetch(root.getFetches()))
   return true;
  if (containsMultiRelationJoin(root.getJoins()))
   return true;
 }
 return false;
}

代码示例来源:origin: org.seedstack.addons.jpa/jpa

@Override
public Stream<A> get(Specification<A> specification, Option... options) {
  CriteriaBuilder cb = entityManager.getCriteriaBuilder();
  Class<A> entityClass = getAggregateRootClass();
  CriteriaQuery<A> cq = cb.createQuery(entityClass);
  Root<A> root = cq.from(entityClass);
  cq.where(
      specificationTranslator.translate(specification, new JpaTranslationContext<>(cb, root)));
  if (!root.getJoins().isEmpty()) {
    // When we have joins, we need to deduplicate the results
    cq.distinct(true);
  }
  for (Option option : options) {
    if (option instanceof SortOption) {
      applySort(cb, root, cq, (SortOption) option);
    }
  }
  return buildStream(applyOffsetAndLimit(entityManager.createQuery(cq), options));
}

代码示例来源:origin: osiam/server

@SuppressWarnings("unchecked")
  protected SetJoin<UserEntity, ExtensionFieldValueEntity> createOrGetJoin(String alias, Root<UserEntity> root,
      SetAttribute<UserEntity, ExtensionFieldValueEntity> attribute) {

    for (Join<UserEntity, ?> currentJoin : root.getJoins()) {
      if (currentJoin.getAlias() == null) {
        // if alias is null, it is not an alias for an extension join, so we ignore it
        continue;
      }

      if (currentJoin.getAlias().equals(alias)) {
        return (SetJoin<UserEntity, ExtensionFieldValueEntity>) currentJoin;
      }
    }

    final SetJoin<UserEntity, ExtensionFieldValueEntity> join = root.join(attribute, JoinType.LEFT);

    join.alias(alias);

    return join;
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-persistence

protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  Set<ClassMetaData> metas = new HashSet<ClassMetaData>();
  MetamodelImpl metamodel = q.getMetamodel();    
  for (Root<?> root : q.getRoots()) {
    metas.add(((AbstractManagedType<?>)root.getModel()).meta);
    for (Join<?,?> join : root.getJoins()) {
      Class<?> cls = join.getAttribute().getJavaType();
      if (join.getAttribute().isAssociation()) {
        ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true);
        PersistenceType type = MetamodelImpl.getPersistenceType(meta);
        if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) 
          metas.add(meta);
      }
    }
  }
  // TODO -- need to handle subqueries
  
  exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]);
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  Set<ClassMetaData> metas = new HashSet<ClassMetaData>();
  MetamodelImpl metamodel = q.getMetamodel();    
  for (Root<?> root : q.getRoots()) {
    metas.add(((AbstractManagedType<?>)root.getModel()).meta);
    for (Join<?,?> join : root.getJoins()) {
      Class<?> cls = join.getAttribute().getJavaType();
      if (join.getAttribute().isAssociation()) {
        ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true);
        PersistenceType type = MetamodelImpl.getPersistenceType(meta);
        if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) 
          metas.add(meta);
      }
    }
  }
  // TODO -- need to handle subqueries
  
  exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]);
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-persistence

protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  Set<ClassMetaData> metas = new HashSet<ClassMetaData>();
  MetamodelImpl metamodel = q.getMetamodel();    
  for (Root<?> root : q.getRoots()) {
    metas.add(((AbstractManagedType<?>)root.getModel()).meta);
    for (Join<?,?> join : root.getJoins()) {
      Class<?> cls = join.getAttribute().getJavaType();
      if (join.getAttribute().isAssociation()) {
        ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true);
        PersistenceType type = MetamodelImpl.getPersistenceType(meta);
        if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) 
          metas.add(meta);
      }
    }
    for (Fetch<?,?> fetch : root.getFetches()) {
      metas.add(metamodel.getRepository().getCachedMetaData(fetch.getAttribute().getJavaType()));
    }
  }
  exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]);
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  Set<ClassMetaData> metas = new HashSet<ClassMetaData>();
  MetamodelImpl metamodel = q.getMetamodel();    
  for (Root<?> root : q.getRoots()) {
    metas.add(((AbstractManagedType<?>)root.getModel()).meta);
    for (Join<?,?> join : root.getJoins()) {
      Class<?> cls = join.getAttribute().getJavaType();
      if (join.getAttribute().isAssociation()) {
        ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true);
        PersistenceType type = MetamodelImpl.getPersistenceType(meta);
        if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) 
          metas.add(meta);
      }
    }
    for (Fetch<?,?> fetch : root.getFetches()) {
      metas.add(metamodel.getRepository().getCachedMetaData(fetch.getAttribute().getJavaType()));
    }
  }
  exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]);
}

相关文章