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

x33g5p2x  于2022-01-18 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(208)

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

CriteriaQuery.subquery介绍

暂无

代码示例

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

Subquery<VariableInstanceLog> maxIdSubQuery = query.subquery(VariableInstanceLog.class);
Root from = maxIdSubQuery.from(VariableInstanceLog.class);
maxIdSubQuery.select(builder.max(from.get(VariableInstanceLog_.id)));

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

Subquery<Long> subquery = criteria.subquery(Long.class);
Root orderRoot = subquery.from(OrderImpl.class);
subquery.select(builder.count(orderRoot));

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

public <R> Predicate createPredicate(QueryCriteria criteria, CriteriaQuery<R> query, CriteriaBuilder builder) {
  // subquery and root
  Root<TaskImpl> taskRoot = getRoot(query, TaskImpl.class);
  Subquery<Long> subQuery = query.subquery(Long.class);
  Root<TaskVariableImpl> taskVarRoot = subQuery.from(TaskVariableImpl.class);
  subQuery.select(taskVarRoot.get(TaskVariableImpl_.taskId));
  // task variable predicate (in subquery)
  Predicate taskVariablePredicate = null;
  String listId = criteria.getListId();
  if( TASK_VARIABLE_COMBINED_ID.equals(listId) ) {
    List<QueryCriteria> taskVarSubCriteriaList = criteria.getCriteria();
    int size = taskVarSubCriteriaList.size();
    Predicate[] taskVarSubPredicates = new Predicate[size];
    for( int i = 0; i < size; ++i ) {
      taskVarSubPredicates[i] = createSingleTaskVariableCriteriaPredicate(
          builder, taskVarRoot, taskVarSubCriteriaList.get(i));
    }
    taskVariablePredicate = builder.and(taskVarSubPredicates);
  } else {
    taskVariablePredicate = createSingleTaskVariableCriteriaPredicate(builder, taskVarRoot, criteria);
  }
  // add predicate to subquery
  subQuery.where(taskVariablePredicate);
  // create predicate for actual query that references subquery
  return taskRoot.get(TaskImpl_.id).in(subQuery);
}

代码示例来源:origin: stackoverflow.com

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery query = cb.createQuery(EntityX.class);
Root<EntityX> root = query.from(EntityX.class);

Subquery<String> maxSubQuery = query.subquery(String.class);
Root<EntityX> fromEntityX = maxSubQuery.from(EntityX.class);
maxSubQuery.select(cb.greatest(fromEntityX.get(EntityX_.nameX)));
query.where(cb.equal(root.get(EntityX_.nameX), maxSubQuery));

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

protected BaseTopicFilterQueryBuilder(final Class<T> clazz, final BaseFieldFilter fieldFilter, final EntityManager entityManager,
    final boolean useTopicSubquery) {
  super(clazz, fieldFilter, entityManager);
  this.useTopicSubquery = useTopicSubquery;
  if (useTopicSubquery) {
    topicQuery = super.getCriteriaQuery().subquery(Topic.class);
    from = topicQuery.from(Topic.class);
  } else {
    topicQuery = null;
    from = null;
  }
}

代码示例来源:origin: xautlx/s2jh4net

@Override
  public Predicate toPredicate(Root<Privilege> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
    Predicate predicate = buildPredicatesFromFilters(groupFilter, root, query, builder);
    Subquery<RoleR2Privilege> sq = query.subquery(RoleR2Privilege.class);
    Root<RoleR2Privilege> r2 = sq.from(RoleR2Privilege.class);
    sq.where(builder.equal(r2.get("privilege"), root), builder.equal(r2.get("role").get("id"), roleId)).select(r2);
    return builder.and(predicate, builder.not(builder.exists(sq)));
  }
};

代码示例来源:origin: DSpace/DSpace

@Override
  public List<MostRecentChecksum> findNotInHistory(Context context) throws SQLException {

    CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
    CriteriaQuery<MostRecentChecksum> criteriaQuery = getCriteriaQuery(criteriaBuilder, MostRecentChecksum.class);
    Root<MostRecentChecksum> checksumRoot = criteriaQuery.from(MostRecentChecksum.class);

    Subquery<Bitstream> subQuery = criteriaQuery.subquery(Bitstream.class);
    Root<ChecksumHistory> historyRoot = subQuery.from(ChecksumHistory.class);
    subQuery.select(historyRoot.get(ChecksumHistory_.bitstream));

    criteriaQuery.where(
      criteriaBuilder.not(checksumRoot.get(MostRecentChecksum_.bitstream).in(subQuery)));

    return list(context, criteriaQuery, false, MostRecentChecksum.class, -1, -1);
  }
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
protected Subquery<TopicToPropertyTag> getPropertyTagExistsSubquery(final Integer propertyTagId) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<TopicToPropertyTag> subQuery = getCriteriaQuery().subquery(TopicToPropertyTag.class);
  final Root<TopicToPropertyTag> root = subQuery.from(TopicToPropertyTag.class);
  subQuery.select(root);
  // Create the Condition for the subquery
  final Predicate topicIdMatch = criteriaBuilder.equal(getRootPath(), root.get("topic"));
  final Predicate propertyTagIdMatch = criteriaBuilder.equal(root.get("propertyTag").get("propertyTagId"), propertyTagId);
  subQuery.where(criteriaBuilder.and(topicIdMatch, propertyTagIdMatch));
  return subQuery;
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
protected Subquery<ContentSpecToPropertyTag> getPropertyTagExistsSubquery(Integer propertyTagId) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<ContentSpecToPropertyTag> subQuery = getCriteriaQuery().subquery(ContentSpecToPropertyTag.class);
  final Root<ContentSpecToPropertyTag> root = subQuery.from(ContentSpecToPropertyTag.class);
  subQuery.select(root);
  // Create the Condition for the subquery
  final Predicate contentSpecIdMatch = criteriaBuilder.equal(getRootPath(), root.get("contentSpec"));
  final Predicate propertyTagIdMatch = criteriaBuilder.equal(root.get("propertyTag").get("propertyTagId"), propertyTagId);
  subQuery.where(criteriaBuilder.and(contentSpecIdMatch, propertyTagIdMatch));
  return subQuery;
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
public Predicate getMatchingLocaleString(final String locale) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<LanguageFile> subquery = getCriteriaQuery().subquery(LanguageFile.class);
  final Root<LanguageFile> from = subquery.from(LanguageFile.class);
  final Predicate languageFileEqual = criteriaBuilder.equal(getRootPath(), from.get("file"));
  final Predicate localeEqual = criteriaBuilder.equal(from.get("locale").get("value"), locale);
  subquery.where(criteriaBuilder.and(languageFileEqual, localeEqual));
  return criteriaBuilder.exists(subquery);
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
public Predicate getMatchingLocaleString(final String locale) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<LanguageImage> subquery = getCriteriaQuery().subquery(LanguageImage.class);
  final Root<LanguageImage> from = subquery.from(LanguageImage.class);
  final Predicate languageImageEqual = criteriaBuilder.equal(getRootPath(), from.get("imageFile"));
  final Predicate localeEqual = criteriaBuilder.equal(from.get("locale").get("value"), locale);
  subquery.where(criteriaBuilder.and(languageImageEqual, localeEqual));
  return criteriaBuilder.exists(subquery);
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
protected Subquery<TagToPropertyTag> getPropertyTagExistsSubquery(final Integer propertyTagId) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<TagToPropertyTag> subQuery = getCriteriaQuery().subquery(TagToPropertyTag.class);
  final Root<TagToPropertyTag> root = subQuery.from(TagToPropertyTag.class);
  subQuery.select(root);
  // Create the Condition for the subquery
  final Predicate tagIdMatch = criteriaBuilder.equal(getRootPath(), root.get("tag"));
  final Predicate propertyTagIdMatch = criteriaBuilder.equal(root.get("propertyTag").get("propertyTagId"), propertyTagId);
  subQuery.where(criteriaBuilder.and(tagIdMatch, propertyTagIdMatch));
  return subQuery;
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
public Predicate getMatchTagString(final Integer tagId) {
  final CriteriaBuilder queryBuilder = getCriteriaBuilder();
  final Subquery<TopicToTag> subQuery = getCriteriaQuery().subquery(TopicToTag.class);
  final Root<TopicToTag> from = subQuery.from(TopicToTag.class);
  final Predicate topic = queryBuilder.equal(from.get("topic"), getRootPath());
  final Predicate tag = queryBuilder.equal(from.get("tag").get("tagId"), tagId);
  subQuery.select(from);
  subQuery.where(queryBuilder.and(topic, tag));
  return queryBuilder.exists(subQuery);
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
public Predicate getNotMatchingLocaleString(final String locale) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<LanguageImage> subquery = getCriteriaQuery().subquery(LanguageImage.class);
  final Root<LanguageImage> from = subquery.from(LanguageImage.class);
  final Predicate languageImageEqual = criteriaBuilder.equal(getRootPath(), from.get("imageFile"));
  final Predicate localeEqual = criteriaBuilder.equal(from.get("locale").get("value"), locale);
  subquery.where(criteriaBuilder.and(languageImageEqual, localeEqual));
  return criteriaBuilder.not(criteriaBuilder.exists(subquery));
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
  public Predicate getNotMatchingLocaleString(final String locale) {
    final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
    final Subquery<LanguageFile> subquery = getCriteriaQuery().subquery(LanguageFile.class);
    final Root<LanguageFile> from = subquery.from(LanguageFile.class);
    final Predicate languageFileEqual = criteriaBuilder.equal(getRootPath(), from.get("file"));
    final Predicate localeEqual = criteriaBuilder.equal(from.get("locale").get("value"), locale);
    subquery.where(criteriaBuilder.and(languageFileEqual, localeEqual));

    return criteriaBuilder.not(criteriaBuilder.exists(subquery));
  }
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
public Predicate getMatchTagString(final Integer tagId) {
  final CriteriaBuilder queryBuilder = getCriteriaBuilder();
  final Subquery<TopicToTag> subQuery = getCriteriaQuery().subquery(TopicToTag.class);
  final Root<TopicToTag> from = subQuery.from(TopicToTag.class);
  final Predicate topic = queryBuilder.equal(from.get("topic").get("topicId"), translatedTopic.get("topicId"));
  final Predicate tag = queryBuilder.equal(from.get("tag").get("tagId"), tagId);
  subQuery.select(from);
  subQuery.where(queryBuilder.and(topic, tag));
  return queryBuilder.exists(subQuery);
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
public Predicate getNotMatchTagString(final Integer tagId) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<TopicToTag> subQuery = getCriteriaQuery().subquery(TopicToTag.class);
  final Root<TopicToTag> from = subQuery.from(TopicToTag.class);
  final Predicate topic = criteriaBuilder.equal(from.get("topic"), getRootPath());
  final Predicate tag = criteriaBuilder.equal(from.get("tag").get("tagId"), tagId);
  subQuery.select(from);
  subQuery.where(criteriaBuilder.and(topic, tag));
  return criteriaBuilder.not(criteriaBuilder.exists(subQuery));
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

protected Subquery<TagToProject> getTagInProjectSubquery(final List<Integer> projectIds) {
    final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
    final Subquery<TagToProject> subQuery = getCriteriaQuery().subquery(TagToProject.class);
    final Root<TagToProject> root = subQuery.from(TagToProject.class);
    subQuery.select(root);

    // Create the Condition for the subquery
    final Predicate tagIdMatch = criteriaBuilder.equal(getRootPath(), root.get("tag"));
    final Predicate projectIdMatch = root.get("project").get("projectId").in(projectIds);
    subQuery.where(criteriaBuilder.and(tagIdMatch, projectIdMatch));

    return subQuery;
  }
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

@Override
public Predicate getNotMatchTagString(final Integer tagId) {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<TopicToTag> subQuery = getCriteriaQuery().subquery(TopicToTag.class);
  final Root<TopicToTag> from = subQuery.from(TopicToTag.class);
  final Predicate topic = criteriaBuilder.equal(from.get("topic").get("topicId"), translatedTopic.get("topicId"));
  final Predicate tag = criteriaBuilder.equal(from.get("tag").get("tagId"), tagId);
  subQuery.select(from);
  subQuery.where(criteriaBuilder.and(topic, tag));
  return criteriaBuilder.not(criteriaBuilder.exists(subQuery));
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

protected Subquery<Integer> getLatestCompleteRevisionSubquery() {
  final CriteriaBuilder criteriaBuilder = getCriteriaBuilder();
  final Subquery<Integer> subQuery = getCriteriaQuery().subquery(Integer.class);
  final Root<TranslatedTopicData> root = subQuery.from(TranslatedTopicData.class);
  subQuery.select(criteriaBuilder.max(root.get("translatedTopic").get("topicRevision").as(Integer.class)));
  final Predicate topicIdMatch = criteriaBuilder.equal(root.get("translatedTopic").get("topicId"), translatedTopic.get("topicId"));
  final Predicate localeMatch = criteriaBuilder.equal(getOriginalRootPath().get("translationLocale"), root.get("translationLocale"));
  final Predicate complete = criteriaBuilder.ge(root.get("translationPercentage").as(Integer.class), 100);
  subQuery.where(criteriaBuilder.and(topicIdMatch, localeMatch, complete));
  subQuery.groupBy(root.get("translatedTopic").get("topicId"));
  return subQuery;
}

相关文章