本文整理匯總了Java中javax.persistence.criteria.CriteriaQuery.multiselect方法的典型用法代碼示例。如果您正苦於以下問題:Java CriteriaQuery.multiselect方法的具體用法?Java CriteriaQuery.multiselect怎麽用?Java CriteriaQuery.multiselect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.criteria.CriteriaQuery
的用法示例。
在下文中一共展示了CriteriaQuery.multiselect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: search
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
@Override
public Optional<SearchResponse> search(final ServiceUser user,
final SearchRequest request){
final String dataSourceUuid = request.getQuery().getDataSource().getUuid();
try (final Session session = database.openSession()) {
final CriteriaBuilder cb = session.getCriteriaBuilder();
final CriteriaQuery<Tuple> cq = cb.createTupleQuery();
final Root<T> root = cq.from(this.dtoClass);
cq.multiselect(this.fields.stream()
.map(f -> root.get(f.getName()))
.collect(Collectors.toList()));
final Predicate requestPredicate = getPredicate(cb, root, request.getQuery().getExpression());
final Predicate dataSourcePredicate = cb.equal(root.get(QueryableEntity.DATA_SOURCE_UUID), dataSourceUuid);
cq.where(cb.and(requestPredicate, dataSourcePredicate));
final List<Tuple> tuples = session.createQuery(cq).getResultList();
final SearchResponse searchResponse = projectResults(request, tuples);
return Optional.of(searchResponse);
}
}
示例2: aggregate
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
private <S> S aggregate(CriteriaBuilder builder, CriteriaQuery<S> query, Root<E> root, Specification<E> spec, List<Selection<?>> selectionList, LockModeType lockMode) {
if (selectionList != null) {
Predicate predicate = spec.toPredicate(root, query, builder);
if (predicate != null) {
query.where(predicate);
}
query.multiselect(selectionList);
return (S) em.createQuery(query).setLockMode(lockMode).getSingleResult();
}
return null;
}
示例3: findAllImpl2
import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
private <R> List<R> findAllImpl2(final DatatableQuery<R, T> input, final Specifications<T> specifications,
final Pageable pageable) {
// create query
final EntityManager entityManager = entityManagerFactory.createEntityManager();
final CriteriaBuilder qb = entityManager.getCriteriaBuilder();
final CriteriaQuery<R> cq = qb.createQuery(input.getQueryClass());
// Etablir entité racine
final Root<T> from = cq.from(this.entity);
// select for custom class
final List<Selection<?>> selectList = new ArrayList<Selection<?>>();
if (input.getGroupByColumns() != null) {
DatatableHelper.getExpressions(from, input.getGroupByColumns(), selectList);
} else {
DatatableHelper.getExpressions(from, input.getColumns(), selectList);
}
cq.multiselect(selectList);
// where
if (specifications != null) {
cq.where(specifications.toPredicate(from, cq, qb));
}
// group by
if (input.getGroupByColumns() != null && !input.getGroupByColumns().isEmpty()) {
final List<Expression<?>> groupByList = new ArrayList<Expression<?>>();
DatatableHelper.getExpressions(from, input.getGroupByColumns(), groupByList);
cq.groupBy(groupByList);
}
// order by
if (pageable != null && pageable.getSort() != null) {
cq.orderBy(DatatableHelper.getOrderBy(from, qb, pageable));
}
// page limit
final TypedQuery<R> q = entityManager.createQuery(cq);
if (pageable != null) {
LOGGER.log(Level.FINE, "Pageable: offset: {0}, page size: {1}", new Object[]{pageable.getOffset(), pageable.getPageSize()});
q.setFirstResult(pageable.getOffset());
q.setMaxResults(pageable.getPageSize());
}
// execute query
final List<R> ret = q.getResultList();
entityManager.close();
return ret;
}