本文整理了Java中javax.persistence.criteria.CriteriaQuery.distinct()
方法的一些代码示例,展示了CriteriaQuery.distinct()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CriteriaQuery.distinct()
方法的具体详情如下:
包路径:javax.persistence.criteria.CriteriaQuery
类名称:CriteriaQuery
方法名:distinct
[英]Specify whether duplicate query results will be eliminated. A true value will cause duplicates to be eliminated. A false value will cause duplicates to be retained. If distinct has not been specified, duplicate results must be retained. This method only overrides the return type of the corresponding AbstractQuery method.
[中]指定是否将消除重复的查询结果。真值将导致消除重复项。假值将导致保留重复项。如果未指定distinct,则必须保留重复的结果。此方法仅重写相应AbstractQuery方法的返回类型。
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
private TypedQuery<Long> getProductIdsUsingProductOptionByIdQuery(Long productOptionId, boolean count) {
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
// The root of our search is ProductOptionXref
Root<ProductOptionXrefImpl> productOptionXref = criteria.from(ProductOptionXrefImpl.class);
Join<ProductOptionXref, Product> product = productOptionXref.join("product");
Join<ProductOptionXref, ProductOption> productOption = productOptionXref.join("productOption");
if (count) {
criteria.select(builder.count(product));
} else {
// Product IDs are what we want back
criteria.select(product.get("id").as(Long.class));
}
criteria.distinct(true);
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(productOption.get("id").in(sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, productOptionId)));
// Execute the query with the restrictions
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
return em.createQuery(criteria);
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Create a new {@link JpaQueryCreator}.
*
* @param tree must not be {@literal null}.
* @param type must not be {@literal null}.
* @param builder must not be {@literal null}.
* @param provider must not be {@literal null}.
*/
public JpaQueryCreator(PartTree tree, ReturnedType type, CriteriaBuilder builder,
ParameterMetadataProvider provider) {
super(tree);
this.tree = tree;
CriteriaQuery<? extends Object> criteriaQuery = createCriteriaQuery(builder, type);
this.builder = builder;
this.query = criteriaQuery.distinct(tree.isDistinct());
this.root = query.from(type.getDomainType());
this.provider = provider;
this.returnedType = type;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
criteria.distinct(true).select(pathToUse.get(fieldName).as(fieldValueClass));
代码示例来源: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: jamesagnew/hapi-fhir
private void findMatchingTagIds(String theResourceName, IIdType theResourceId, Set<Long> tagIds, Class<? extends BaseTag> entityClass) {
{
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = builder.createTupleQuery();
Root<? extends BaseTag> from = cq.from(entityClass);
cq.multiselect(from.get("myTagId").as(Long.class)).distinct(true);
if (theResourceName != null) {
Predicate typePredicate = builder.equal(from.get("myResourceType"), theResourceName);
if (theResourceId != null) {
cq.where(typePredicate, builder.equal(from.get("myResourceId"), myIdHelperService.translateForcedIdToPid(theResourceName, theResourceId.getIdPart())));
} else {
cq.where(typePredicate);
}
}
TypedQuery<Tuple> query = myEntityManager.createQuery(cq);
for (Tuple next : query.getResultList()) {
tagIds.add(next.get(0, Long.class));
}
}
}
代码示例来源:origin: stackoverflow.com
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();
Root<A> a = cq.from(A.class);
Join<A, B> j = a.join("bcollection",JoinType.INNER);
cq.distinct(true);
Object r = em.createQuery(cq).getResultList();
代码示例来源:origin: Jasig/uPortal
@Override
public CriteriaQuery<AggregationInterval> apply(CriteriaBuilder cb) {
final CriteriaQuery<AggregationInterval> criteriaQuery =
cb.createQuery(AggregationInterval.class);
final Root<T> ba = criteriaQuery.from(aggregationEntityType);
criteriaQuery.distinct(true);
criteriaQuery.select(ba.get(BaseAggregationImpl_.interval));
return criteriaQuery;
}
});
代码示例来源:origin: Jasig/uPortal
@Override
public CriteriaQuery<AggregatedGroupMappingImpl> apply(
CriteriaBuilder cb) {
final CriteriaQuery<AggregatedGroupMappingImpl> criteriaQuery =
cb.createQuery(AggregatedGroupMappingImpl.class);
final Root<T> ba = criteriaQuery.from(aggregationEntityType);
criteriaQuery.distinct(true);
criteriaQuery.select(ba.get(BaseAggregationImpl_.aggregatedGroup));
return criteriaQuery;
}
});
代码示例来源:origin: org.jasig.portal/uPortal-persondir
@Override
public CriteriaQuery<String> apply(CriteriaBuilder cb) {
final CriteriaQuery<String> criteriaQuery =
cb.createQuery(String.class);
final Root<LocalAccountPersonAttributeImpl> accountRoot =
criteriaQuery.from(LocalAccountPersonAttributeImpl.class);
criteriaQuery.select(
accountRoot.get(LocalAccountPersonAttributeImpl_.name));
criteriaQuery.distinct(true);
return criteriaQuery;
}
});
代码示例来源:origin: Jasig/uPortal
@Override
public CriteriaQuery<String> apply(CriteriaBuilder cb) {
final CriteriaQuery<String> criteriaQuery =
cb.createQuery(String.class);
final Root<LocalAccountPersonAttributeImpl> accountRoot =
criteriaQuery.from(LocalAccountPersonAttributeImpl.class);
criteriaQuery.select(
accountRoot.get(LocalAccountPersonAttributeImpl_.name));
criteriaQuery.distinct(true);
return criteriaQuery;
}
});
代码示例来源:origin: adamzareba/company-structure-spring-security-oauth2-authorities
@Override
public List<Company> findAll() {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Company> query = builder.createQuery(Company.class);
Root<Company> root = query.from(Company.class);
query.select(root).distinct(true);
TypedQuery<Company> allQuery = entityManager.createQuery(query);
return allQuery.getResultList();
}
代码示例来源:origin: com.blazebit/blaze-persistence-integration-spring-data-base
public FixedJpaQueryCreator(PartTree tree, Class<?> domainClass, CriteriaBuilder builder,
ParameterMetadataProvider provider) {
super(tree);
this.builder = builder;
this.query = builder.createQuery().distinct(tree.isDistinct());
this.root = query.from(domainClass);
this.provider = provider;
}
代码示例来源:origin: Blazebit/blaze-persistence
public FixedJpaQueryCreator(PartTree tree, Class<?> domainClass, CriteriaBuilder builder,
ParameterMetadataProvider provider) {
super(tree);
this.builder = builder;
this.query = builder.createQuery().distinct(tree.isDistinct());
this.root = query.from(domainClass);
this.provider = provider;
}
代码示例来源:origin: com.blazebit/blaze-persistence-integration-spring-data
public FixedJpaQueryCreator(PartTree tree, Class<?> domainClass, CriteriaBuilder builder,
ParameterMetadataProvider provider) {
super(tree);
this.builder = builder;
this.query = builder.createQuery().distinct(tree.isDistinct());
this.root = query.from(domainClass);
this.provider = provider;
}
代码示例来源:origin: net.leadware/jpersistence-tools-core
/**
* Methode d'ajout des Proprietes a charger a la requete de recherche
* @param root Entités objet du from
* @param query Requete sur l'entité
* @param properties Conteneur de propriétés
*/
protected void addProperties(Root<T> root, CriteriaQuery<T> query, Set<String> properties) {
// Ajout des ppt
addProperties(root, properties);
// On positionne le distict
query.distinct(true);
}
代码示例来源:origin: org.smartdeveloperhub.harvesters.ci.backend/ci-backend-core
@Override
public List<URI> serviceIds() {
CriteriaQuery<URI> query =
entityManager().
getCriteriaBuilder().
createQuery(URI.class);
Root<Service> service = query.from(Service.class);
query.
select(service.<URI>get("serviceId")).
distinct(true);
return entityManager().createQuery(query).getResultList();
}
代码示例来源:origin: org.smartdeveloperhub.harvesters.ci.backend/ci-backend-core
@Override
public List<URI> executionIds() {
final CriteriaQuery<URI> query =
entityManager().
getCriteriaBuilder().
createQuery(URI.class);
final Root<Execution> execution = query.from(Execution.class);
query.
select(execution.<URI>get("executionId")).
distinct(true);
return entityManager().createQuery(query).getResultList();
}
代码示例来源:origin: org.smartdeveloperhub.harvesters.ci.backend/ci-backend-core
@Override
public List<URI> repositoryLocations() {
final CriteriaQuery<URI> query =
entityManager().
getCriteriaBuilder().
createQuery(URI.class);
final Root<Repository> service = query.from(Repository.class);
query.
select(service.<URI>get("location")).
distinct(true);
return entityManager().createQuery(query).getResultList();
}
代码示例来源:origin: org.eclipse.hawkbit/hawkbit-repository-jpa
@Override
public long countByRsql(final String targetFilterQuery) {
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
virtualPropertyReplacer, database);
return targetRepository.count((root, query, cb) -> {
query.distinct(true);
return specs.toPredicate(root, query, cb);
});
}
代码示例来源:origin: eclipse/hawkbit
@Override
public long countByRsql(final String targetFilterQuery) {
final Specification<JpaTarget> specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class,
virtualPropertyReplacer, database);
return targetRepository.count((root, query, cb) -> {
query.distinct(true);
return specs.toPredicate(root, query, cb);
});
}
内容来源于网络,如有侵权,请联系作者删除!