当前位置: 首页>>代码示例>>Java>>正文


Java Subquery.select方法代码示例

本文整理汇总了Java中javax.persistence.criteria.Subquery.select方法的典型用法代码示例。如果您正苦于以下问题:Java Subquery.select方法的具体用法?Java Subquery.select怎么用?Java Subquery.select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.criteria.Subquery的用法示例。


在下文中一共展示了Subquery.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findPage

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
public Page<Article> findPage(ArticleCategory articleCategory, List<Tag> tags, Pageable pageable) {
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<Article> criteriaQuery = criteriaBuilder.createQuery(Article.class);
	Root<Article> root = criteriaQuery.from(Article.class);
	criteriaQuery.select(root);
	Predicate restrictions = criteriaBuilder.conjunction();
	restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isPublication"), true));
	if (articleCategory != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.equal(root.get("articleCategory"), articleCategory), criteriaBuilder.like(root.get("articleCategory").<String> get("treePath"), "%" + ArticleCategory.TREE_PATH_SEPARATOR + articleCategory.getId() + ArticleCategory.TREE_PATH_SEPARATOR + "%")));
	}
	if (tags != null && !tags.isEmpty()) {
		Subquery<Article> subquery = criteriaQuery.subquery(Article.class);
		Root<Article> subqueryRoot = subquery.from(Article.class);
		subquery.select(subqueryRoot);
		subquery.where(criteriaBuilder.equal(subqueryRoot, root), subqueryRoot.join("tags").in(tags));
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.exists(subquery));
	}
	criteriaQuery.where(restrictions);
	criteriaQuery.orderBy(criteriaBuilder.desc(root.get("isTop")));
	return super.findPage(criteriaQuery, pageable);
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:22,代码来源:ArticleDaoImpl.java

示例2: findList

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
public List<Article> findList(ArticleCategory articleCategory, List<Tag> tags, Integer count, List<Filter> filters, List<Order> orders) {
	CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
	CriteriaQuery<Article> criteriaQuery = criteriaBuilder.createQuery(Article.class);
	Root<Article> root = criteriaQuery.from(Article.class);
	criteriaQuery.select(root);
	Predicate restrictions = criteriaBuilder.conjunction();
	restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.equal(root.get("isPublication"), true));
	if (articleCategory != null) {
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.or(criteriaBuilder.equal(root.get("articleCategory"), articleCategory), criteriaBuilder.like(root.get("articleCategory").<String> get("treePath"), "%" + ArticleCategory.TREE_PATH_SEPARATOR + articleCategory.getId() + ArticleCategory.TREE_PATH_SEPARATOR + "%")));
	}
	if (tags != null && !tags.isEmpty()) {
		Subquery<Article> subquery = criteriaQuery.subquery(Article.class);
		Root<Article> subqueryRoot = subquery.from(Article.class);
		subquery.select(subqueryRoot);
		subquery.where(criteriaBuilder.equal(subqueryRoot, root), subqueryRoot.join("tags").in(tags));
		restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.exists(subquery));
	}
	criteriaQuery.where(restrictions);
	criteriaQuery.orderBy(criteriaBuilder.desc(root.get("isTop")));
	return super.findList(criteriaQuery, null, count, filters, orders);
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:22,代码来源:ArticleDaoImpl.java

示例3: existsInForeignBuilder

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
private void existsInForeignBuilder(Subquery<Long> subquery, Root<RtRegistration> subroot, AbstractJPASearchFormDataStatementBuilder<?> foreignBuilder) {
  CriteriaBuilder b = JPA.getCriteriaBuilder();

  subquery.select(subroot.get(RtRegistration_.id).get(RtRegistrationKey_.registrationNr));
  Predicate entityExists = b.exists(
      subquery.where(
          b.and(
              b.equal(
                  subroot.get(RtRegistration_.id).get(RtRegistrationKey_.registrationNr),
                  registration.get(RtRegistration_.id).get(RtRegistrationKey_.registrationNr)
                  ),
              b.equal(
                  subroot.get(RtRegistration_.id).get(RtRegistrationKey_.clientNr),
                  registration.get(RtRegistration_.id).get(RtRegistrationKey_.clientNr)
                  ),
              foreignBuilder.getPredicate())
          )
      );
  addForeignBuilder(foreignBuilder, entityExists);
}
 
开发者ID:innovad,项目名称:4mila-1.0,代码行数:21,代码来源:JPARegistrationsSearchFormDataStatementBuilder.java

示例4: visit

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public boolean visit(JpqlSubselect node, CriteriaHolder query) {
    try {
        Subquery<Object> subquery = query.createSubquery();
        node.jjtGetChild(1).visit(this, query);
        node.jjtGetChild(0).visit(this, query);
        List<Selection<?>> selections = query.<List<Selection<?>>>getCurrentValue();
        subquery.select((Expression<Object>)selections.iterator().next());
        query.setValue(subquery);
        for (int i = 2; i < node.jjtGetNumChildren(); i++) {
            node.jjtGetChild(i).visit(this, query);
        }
        query.setValue(subquery);
        return false;
    } finally {
        query.removeSubquery();
    }
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:21,代码来源:CriteriaVisitor.java

示例5: getChanges

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public List<RegistryOperation> getChanges(Date from, Date until) {
    CriteriaQuery<RegistryOperation> query = criteriaBuilder.createQuery(RegistryOperation.class);
    Root<RegistryOperation> root = query.from(clazz);
    Subquery<Long> subquery = query.subquery(Long.class);
    Root<RegistryOperation> subqueryRoot = subquery.from(clazz);
    subquery = subquery.select(criteriaBuilder.max(subqueryRoot.get(RegistryOperation_.id)));
    Predicate subqueryPredicate = criteriaBuilder.isTrue(subqueryRoot.get(RegistryOperation_.exposed));
    subqueryPredicate = criteriaBuilder.and(subqueryPredicate,
        criteriaBuilder.lessThanOrEqualTo(subqueryRoot.get(RegistryOperation_.date), until));
    if (from != null) {
        subqueryPredicate = criteriaBuilder.and(subqueryPredicate,
            criteriaBuilder.greaterThanOrEqualTo(subqueryRoot.get(RegistryOperation_.date), from));
    }
    subquery = subquery.where(subqueryPredicate);
    subquery = subquery.groupBy(subqueryRoot.get(RegistryOperation_.target).get(SemanticDescriptor_.id));
    query = query.where(root.get(RegistryOperation_.id).in(subquery));
    query.orderBy(criteriaBuilder.asc(root.get(RegistryOperation_.date)));
    return entityManager.createQuery(query).getResultList();
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:21,代码来源:RegistryOperationDaoBean.java

示例6: getSizeGroupByOwner

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public Map<Long, Long> getSizeGroupByOwner() {
    CriteriaQuery<Tuple> query = criteriaBuilder.createTupleQuery();
    Root<DataFile> root = query.from(clazz);
    Root<DigitalObject> objectRoot = query.from(DigitalObject.class);

    Subquery<DataFileVersion> subquery = query.subquery(DataFileVersion.class);
    Root<DataFileVersion> subqueryRoot = subquery.from(DataFileVersion.class);
    Join<DataFileVersion, ContentVersion> joinVersion = subqueryRoot.join(DataFileVersion_.contentVersion);
    Join<ContentVersion, DigitalObject> joinObject = joinVersion.join(ContentVersion_.object);
    subquery.where(criteriaBuilder.and(criteriaBuilder.equal(joinObject, objectRoot),
        criteriaBuilder.equal(root, subqueryRoot.get(DataFileVersion_.dataFile))));
    subquery.select(subqueryRoot);

    query.where(criteriaBuilder.exists(subquery));
    query.groupBy(objectRoot.get(DigitalObject_.ownerId));
    query.multiselect(objectRoot.get(DigitalObject_.ownerId), criteriaBuilder.sum(root.get(DataFile_.size)));

    Map<Long, Long> results = new HashMap<Long, Long>();
    for (Tuple tuple : entityManager.createQuery(query).getResultList()) {
        results.put((Long) tuple.get(0), (Long) tuple.get(1));
    }

    return results;
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:26,代码来源:DataFileDaoBean.java

示例7: getSizeGroupByOwner

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public Map<Long, Long> getSizeGroupByOwner() {
    CriteriaQuery<Tuple> query = criteriaBuilder.createTupleQuery();
    Root<T> root = query.from(clazz);
    Root<DigitalObject> objectRoot = query.from(DigitalObject.class);

    Subquery<T> subquery = query.subquery(clazz);
    Root<T> subqueryRoot = subquery.from(clazz);
    Join<?, ContentVersion> joinVersion = joinVersions(subqueryRoot);
    Join<ContentVersion, DigitalObject> joinObject = joinVersion.join(ContentVersion_.object);
    subquery.where(criteriaBuilder.and(criteriaBuilder.equal(joinObject, objectRoot),
        criteriaBuilder.equal(root, subqueryRoot)));
    subquery.select(subqueryRoot);

    query.where(criteriaBuilder.exists(subquery));
    query.groupBy(objectRoot.get(DigitalObject_.ownerId));
    query.multiselect(objectRoot.get(DigitalObject_.ownerId), criteriaBuilder.sum(root.get(MetadataFile_.size)));

    Map<Long, Long> results = new HashMap<Long, Long>();
    for (Tuple tuple : entityManager.createQuery(query).getResultList()) {
        results.put((Long) tuple.get(0), (Long) tuple.get(1));
    }

    return results;
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:26,代码来源:MetadataFileDaoBean.java

示例8: findNextActiveIdentifier

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public Identifier findNextActiveIdentifier(String previousIdentifierValue) {

    CriteriaQuery<Identifier> query = criteriaBuilder.createQuery(Identifier.class);
    Root<Identifier> root = query.from(Identifier.class);
    query.select(root);
    query.where(criteriaBuilder.notEqual(root.get(Identifier_.isActive), false));
    query.orderBy(criteriaBuilder.asc(root.get(Identifier_.id)));

    if (previousIdentifierValue != null) {
        Subquery<Long> subquery = query.subquery(Long.class);
        Root<Identifier> subqueryRoot = subquery.from(Identifier.class);
        subquery.select(subqueryRoot.get(Identifier_.id));
        subquery.where(criteriaBuilder.equal(subqueryRoot.get(Identifier_.identifier), previousIdentifierValue));
        query.where(criteriaBuilder.greaterThan(root.get(Identifier_.id), criteriaBuilder.any(subquery)));
    }

    List<Identifier> identifiers = entityManager.createQuery(query).setMaxResults(1).getResultList();
    if (identifiers != null && !identifiers.isEmpty()) {
        return identifiers.get(0);
    }

    return null;
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:25,代码来源:IdentifierDaoBean.java

示例9: hasUserName

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
public static Specification<Meeting> hasUserName(String searchTerm, Collection<Long> mepIds) {
	return new Specification<Meeting>() {
		@Override
		public Predicate toPredicate(Root<Meeting> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
			query.distinct(true);
			String containsLikePattern = getContainsLikePattern(searchTerm);
			log.trace(searchTerm + "," + mepIds);
			Root<Meeting> meeting = root;
			Subquery<User> userSubQuery = query.subquery(User.class);
			Root<User> user = userSubQuery.from(User.class);
			Expression<Collection<Meeting>> userMeetings = user.get("meetings");
			userSubQuery.select(user);
			userSubQuery.where(
					cb.or(cb.like(user.get("firstName"), containsLikePattern),
							cb.like(user.get("lastName"), containsLikePattern)),
					cb.isMember(meeting, userMeetings));
			return cb.exists(userSubQuery);
		}
	};
}
 
开发者ID:TransparencyInternationalEU,项目名称:lobbycal,代码行数:21,代码来源:MeetingSpecifications.java

示例10: getEntitiesNotDefinedForScope

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public List<EntityTypeDO> getEntitiesNotDefinedForScope(Long scopeId) {
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<EntityTypeDO> cq = cb.createQuery(EntityTypeDO.class);
	Root<EntityTypeDO> root = cq.from(EntityTypeDO.class);

	Subquery<EntityTypeDO> subQuery = cq.subquery(EntityTypeDO.class);
	Root<EntityDO> fromEntity = subQuery.from(EntityDO.class);
	subQuery.select(fromEntity.get(EntityDO_.entityType));
	Predicate scope = cb.equal(fromEntity.get(EntityDO_.scope).get(ScopeDO_.scopeId), scopeId);
	subQuery.where(scope);

	cq.where(cb.not(cb.in(root).value(subQuery)));

	return em.createQuery(cq).setHint("org.hibernate.cacheable", Boolean.TRUE).getResultList();
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:17,代码来源:EntityTypeDAOImpl.java

示例11: getListOfNodesForDatasetsWithStatus

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public List<Node> getListOfNodesForDatasetsWithStatus(DataSetStatus[] status){
	CriteriaBuilder builder = getCriteriaBuilder();
	
	CriteriaQuery<Node> query = builder.createQuery(Node.class);
	Root<Node> nodeR = query.from(Node.class);
	query.select(nodeR);
	
	Subquery<DataSet> subQuery = query.subquery(DataSet.class);
	Root<DataSet> datSet = subQuery.from(DataSet.class);
	subQuery.select(datSet);
	
	Predicate statusPredicate = datSet.get(DataSet_.status).in(status);
	Predicate correlatePredicate = builder.equal(datSet.get(DataSet_.node), nodeR);
	
	subQuery.where(builder.and(statusPredicate, correlatePredicate));

	query.where(builder.exists(subQuery));
	
	TypedQuery<Node> q = getEntityManager().createQuery(query);
	return q.getResultList();
}
 
开发者ID:PE-INTERNATIONAL,项目名称:soda4lca,代码行数:23,代码来源:NodeDaoImpl.java

示例12: hasProperties

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
public WordTemplateQuery hasProperties(Map<String, String> someProperties) {
	Subquery<Long> subQuery = query.subquery(Long.class);
	Root<PersistentTemplate> fromSubQuery = subQuery
			.from(PersistentTemplate.class);
	Path<Long> id = fromSubQuery.get("id");
	subQuery.select(id);
	MapJoin<PersistentTemplate, String, String> propertiesMap = fromSubQuery
			.joinMap("properties", JoinType.INNER);
	subQuery.where(buildPropertyRestriction(propertiesMap, someProperties));
	subQuery.groupBy(id);
	subQuery.having(criteriaBuilder.equal(criteriaBuilder.count(id),
			someProperties.size()));
	restrictions.add(persistentTemplate.get("id").in(subQuery));
	return this;
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:16,代码来源:WordTemplateQuery.java

示例13: getRuleResponsibilitySubQuery

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
private Subquery<RuleResponsibilityBo> getRuleResponsibilitySubQuery(String ruleRespName,
                    CriteriaQuery<RuleBaseValues> query){
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    Subquery<RuleResponsibilityBo> subquery = query.subquery(RuleResponsibilityBo.class);
    Root fromResp = subquery.from(RuleResponsibilityBo.class);
    subquery.where(cb.equal(fromResp.get("ruleResponsibilityName"),ruleRespName));
    subquery.select(fromResp.get("ruleBaseValuesId"));

    return subquery;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:11,代码来源:RuleDAOJpa.java

示例14: getRuleResponsibilitySubQuery

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
/**
 * Method that selects the responsibility id from rule responsibility table where rule id is equal to the value that is passed as parameter to this method
 * @param ruleBaseValuesId is the rule id
 * @param query is the criteria query
 * @return a subquery
 */
private Subquery<RuleResponsibilityBo> getRuleResponsibilitySubQuery(Long ruleBaseValuesId, CriteriaQuery<RuleDelegationBo> query){
    CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
    Subquery<RuleResponsibilityBo> ruleResponsibilityBoSubquery = query.subquery(RuleResponsibilityBo.class);
    Root fromResp = ruleResponsibilityBoSubquery.from(RuleResponsibilityBo.class);
    ruleResponsibilityBoSubquery.where(criteriaBuilder.equal(fromResp.get("ruleBaseValuesId"),ruleBaseValuesId));
    ruleResponsibilityBoSubquery.select(fromResp.get("responsibilityId"));

    return ruleResponsibilityBoSubquery;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:16,代码来源:RuleDelegationDAOJpa.java

示例15: getSearchCriteria

import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
private List<javax.persistence.criteria.Predicate> getSearchCriteria(Root<RuleBaseValues> root,CriteriaQuery<RuleBaseValues> query,
        String docTypeName, String ruleTemplateId,
        String ruleDescription, Boolean activeInd, Map<String,String> extensionValues) {
    List<javax.persistence.criteria.Predicate> predicates = new ArrayList<javax.persistence.criteria.Predicate>();
    CriteriaBuilder criteribaBuilder = getEntityManager().getCriteriaBuilder();

    predicates.add(criteribaBuilder.equal(root.get("currentInd"),Boolean.TRUE));
    predicates.add(criteribaBuilder.equal(root.get("templateRuleInd"), Boolean.FALSE));
    if (activeInd != null) {
        predicates.add(criteribaBuilder.equal(root.get("active"),activeInd));
    }
    if (docTypeName != null) {
        predicates.add(criteribaBuilder.like(criteribaBuilder.upper(root.<String>get("docTypeName")), docTypeName.toUpperCase()));
    }
    if (ruleDescription != null && !ruleDescription.trim().equals("")) {
        predicates.add(criteribaBuilder.like(criteribaBuilder.upper(root.<String>get("description")),ruleDescription.toUpperCase()));
    }
    if (ruleTemplateId != null) {
        predicates.add(criteribaBuilder.equal(root.get("ruleTemplateId"),ruleTemplateId));
    }

    if (extensionValues != null && !extensionValues.isEmpty()) {
        for (Map.Entry<String,String> entry : extensionValues.entrySet()) {
            if (!StringUtils.isEmpty(entry.getValue())) {
                Subquery ruleExtSubQuery = query.subquery(RuleExtensionBo.class);
                Root<RuleExtensionBo> ruleExtRoot = ruleExtSubQuery.from(RuleExtensionBo.class);
                javax.persistence.criteria.Predicate predAnd = criteribaBuilder.and(
                        criteribaBuilder.equal(ruleExtRoot.get("extensionValues").get("key"),entry.getKey()),
                        criteribaBuilder.like(ruleExtRoot.get("extensionValues").<String>get("value"),
                                ("%" + (String) entry.getValue() + "%").toUpperCase()));
                ruleExtSubQuery.where(predAnd);
                ruleExtSubQuery.select(ruleExtRoot.get("ruleBaseValuesId"));

                predicates.add(criteribaBuilder.in(root.get("id")).value(ruleExtSubQuery));
            }
        }
    }
    return predicates;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:40,代码来源:RuleDelegationDAOJpa.java


注:本文中的javax.persistence.criteria.Subquery.select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。