本文整理汇总了Java中javax.persistence.criteria.Selection类的典型用法代码示例。如果您正苦于以下问题:Java Selection类的具体用法?Java Selection怎么用?Java Selection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Selection类属于javax.persistence.criteria包,在下文中一共展示了Selection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: findByCriteriaAndMapConstructor
import javax.persistence.criteria.Selection; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <T extends BaseEntity, C> List<C> findByCriteriaAndMapConstructor(ConstructorCriteria<T, C> criteria) {
EntityManager em = this.emf.createEntityManager();
try {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<C> cq = cb.createQuery(criteria.getConstructorClass());
Root<T> root = cq.from(criteria.getEntity());
return em.createQuery(cq.select(cb.construct(criteria.getConstructorClass(), criteria.getSelections()
.stream()
.map(root::get)
.collect(Collectors.toList())
.toArray(new Selection[LEN_ZERO])))
.where(JpaUtil.getPredicates(criteria.getCriteriaAttributes(), cb, root)))
.getResultList();
} catch (RuntimeException ex) {
LOGGER.error(ex.getMessage(), ex);
throw new PersistenceException(ex.getMessage(), ex);
} finally {
JpaUtil.closeEntityManager(em);
}
}
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:25,代码来源:EclipseLinkCrudRepository.java
示例2: aggregate
import javax.persistence.criteria.Selection; //导入依赖的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;
}
开发者ID:onsoul,项目名称:os,代码行数:12,代码来源:GenericRepositoryImpl.java
示例3: select
import javax.persistence.criteria.Selection; //导入依赖的package包/类
@Override
public T select(Object... selections) {
if (!beforeMethodInvoke()) {
return (T) this;
}
List<Selection<?>> list = new ArrayList<Selection<?>>(selections.length);
for (Object selection : selections) {
if (selection instanceof String) {
parseSelectionStr(list, (String) selection);
} else if (selection instanceof Selection) {
list.add((Selection<?>) selection);
}
}
select(list.toArray(new Selection<?>[list.size()]));
return (T) this;
}
开发者ID:muxiangqiu,项目名称:linq,代码行数:17,代码来源:LinImpl.java
示例4: parseSelectionStr
import javax.persistence.criteria.Selection; //导入依赖的package包/类
private void parseSelectionStr(List<Selection<?>> result, String selection) {
String[] ps = selection.split("\\s*,\\s*");
for (String p : ps) {
String alias = p.trim();
String[] pa = alias.split("\\s+[aA][sS]\\s+");
if (pa.length > 1) {
alias = pa[1];
} else {
pa = alias.split("\\s+");
if (pa.length > 1) {
alias = pa[1];
}
}
result.add(root.get(ps[0]).alias(alias));
}
}
开发者ID:muxiangqiu,项目名称:linq,代码行数:17,代码来源:LinImpl.java
示例5: distinct
import javax.persistence.criteria.Selection; //导入依赖的package包/类
/**
* @param distinctFields
* @return
* @throws IllegalArgumentException if the field is not part of the entity
*/
public JpaELFilterImpl distinct(String... distinctFields) {
if (distinctFields != null) {
List<Selection> multiSelection = new ArrayList<>();
for (String f : distinctFields) {
multiSelection.add(resultRoot.get(f));
}
if (distinctFields.length == 1) {
critQ.select(multiSelection.get(0)).distinct(true);
} else if (distinctFields.length > 0) {
critQ.multiselect(multiSelection).distinct(true);
}
}
return this;
}
开发者ID:gdjennings,项目名称:elrest-java,代码行数:22,代码来源:JpaELFilterImpl.java
示例6: sum
import javax.persistence.criteria.Selection; //导入依赖的package包/类
@Override
public <S> S sum(Class<S> resultClass, Specification<E> spec, LockModeType lockMode, List<String> properties) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<S> query = builder.createQuery(resultClass);
Root<E> root = query.from(getDomainClass());
List<Selection<?>> selectionList = Lists.newArrayList();
for (String property : properties) {
selectionList.add(builder.sum(getAttributeName(root, property)));
}
return aggregate(builder, query, root, spec, selectionList, lockMode);
}
开发者ID:onsoul,项目名称:ha-db,代码行数:12,代码来源:GenericRepositoryImpl.java
示例7: addSelection
import javax.persistence.criteria.Selection; //导入依赖的package包/类
@Override
public void addSelection(Expression<?> expression, String name) {
Selection<?> selection = criteriaQuery.getSelection();
List<Selection<?>> newSelection = new ArrayList<>();
if (selection != null) {
if (selection.isCompoundSelection()) {
newSelection.addAll(selection.getCompoundSelectionItems());
}
else {
newSelection.add(selection);
}
}
newSelection.add(expression);
criteriaQuery.multiselect(newSelection);
}
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:17,代码来源:JpaCriteriaQueryBackend.java
示例8: findByTupleQuery
import javax.persistence.criteria.Selection; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <T extends BaseEntity> List<Tuple> findByTupleQuery(TupleQueryCriteria<T> criteria) {
EntityManager em = this.emf.createEntityManager();
try {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createTupleQuery();
Root<T> root = cq.from(criteria.getEntity());
return em.createQuery(cq.multiselect(criteria.getSelections()
.stream()
.map(root::get)
.collect(Collectors.toList())
.toArray(new Selection[LEN_ZERO]))
.where(cb.and(JpaUtil.getPredicates(criteria.getCriteriaAttributes(), cb, root))))
.getResultList();
} catch (RuntimeException ex) {
LOGGER.error(ex.getMessage(), ex);
throw new PersistenceException(ex.getMessage(), ex);
} finally {
JpaUtil.closeEntityManager(em);
}
}
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:25,代码来源:EclipseLinkCrudRepository.java
示例9: visit
import javax.persistence.criteria.Selection; //导入依赖的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
示例10: criteria
import javax.persistence.criteria.Selection; //导入依赖的package包/类
@Test
public void criteria() {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<ClientEntityBrowserDto> c = cb.createQuery(ClientEntityBrowserDto.class);
Root<Client> client = c.from(Client.class);
Join<Client, ClientGroup> clientGroup = client.join("group", JoinType.LEFT);
Join<Client, ClientStructure> clientStructure = client.join("structure", JoinType.LEFT);
Join<ClientType, ClientTypeGroup> clientTypeGroup
= client.join("type", JoinType.LEFT).join("clientTypeGroup", JoinType.LEFT);
Selection<ClientEntityBrowserDto> selection
= cb.construct(ClientEntityBrowserDto.class,
client.<Integer>get("id"),
client.<String>get("number"),
client.<String>get("name"),
clientTypeGroup.<String>get("name"),
clientGroup.<String>get("name"),
clientStructure.<String>get("name"));
c.select(selection);
c.distinct(true);
TypedQuery<ClientEntityBrowserDto> query = entityManager.createQuery(c);
assertTrue(query.getResultList().isEmpty());
}
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:26,代码来源:CriteriaBuilderTest.java
示例11: checkMultiselect
import javax.persistence.criteria.Selection; //导入依赖的package包/类
/**
* Package-protected method to centralize checking of criteria query multi-selects as defined by the
* {@link CriteriaQuery#multiselect(List)} method.
*
* @param selections The selection varargs to check
*
* @throws IllegalArgumentException If the selection items are not valid per {@link CriteriaQuery#multiselect}
* documentation.
* <i>"An argument to the multiselect method must not be a tuple-
* or array-valued compound selection item."</i>
*/
void checkMultiselect(List<Selection<?>> selections) {
// final HashSet<String> aliases = new HashSet<String>( CollectionHelper.determineProperSizing( selections.size() ) );
//
// for ( Selection<?> selection : selections ) {
// if ( selection.isCompoundSelection() ) {
// if ( selection.getJavaType().isArray() ) {
// throw new IllegalArgumentException(
// "Selection items in a multi-select cannot contain compound array-valued elements"
// );
// }
// if ( Tuple.class.isAssignableFrom( selection.getJavaType() ) ) {
// throw new IllegalArgumentException(
// "Selection items in a multi-select cannot contain compound tuple-valued elements"
// );
// }
// }
// if ( StringHelper.isNotEmpty( selection.getAlias() ) ) {
// boolean added = aliases.add( selection.getAlias() );
// if ( ! added ) {
// throw new IllegalArgumentException( "Multi-select expressions defined duplicate alias : " + selection.getAlias() );
// }
// }
// }
}
开发者ID:hibernate,项目名称:hibernate-semantic-query,代码行数:36,代码来源:CriteriaBuilderImpl.java
示例12: toExpressions
import javax.persistence.criteria.Selection; //导入依赖的package包/类
private List<JpaExpression<?>> toExpressions(List<Selection<?>> selections) {
if ( selections == null || selections.isEmpty() ) {
return Collections.emptyList();
}
final ArrayList<JpaExpression<?>> expressions = new ArrayList<>();
for ( Selection<?> selection : selections ) {
if ( selection instanceof JpaExpression ) {
expressions.add( (JpaExpression) selection );
}
else {
throw new CriteriaBuilderException(
"Expecting javax.persistence.criteria.Selection to be " +
"JpaExpression, but found " +
selection.toString()
);
}
}
return expressions;
}
开发者ID:hibernate,项目名称:hibernate-semantic-query,代码行数:22,代码来源:CriteriaBuilderImpl.java
示例13: prepareProjectingQuery
import javax.persistence.criteria.Selection; //导入依赖的package包/类
public <E> List<Selection<?>> prepareProjectingQuery(MetaJpaConstructor<E,?,?> projection, From<?,? extends E> selection) {
logger.debug("prepareProjectingQuery({},{})", projection, selection);
List<Selection<?>> ret;
if (projection instanceof IdProjection) {
logger.debug("IdProjection. Replacing selection {} with just Id.", selection);
ret = Collections.<Selection<?>>newList(selection.get(QueryUtils.<E,Object>id(selection.getJavaType(), em.apply())));
} else {
ret = newListOfSize(projection.getParameters().size());
for (Tuple3<Integer, Attribute<?,?>, Class<?>> t: zip(range(0), projection.getParameters(), projection.getConstructorParameterTypes())) {
int index = t._1;
Attribute<?,?> param = t._2;
Class<?> constuctorParameterType = t._3;
ret.add(transformSelectionForQuery(param, isId(constuctorParameterType) || isWrapperOfIds(projection, index), selection, projection));
}
}
logger.debug("prepareProjectingQuery -> {}", ret);
return ret;
}
开发者ID:solita,项目名称:query-utils,代码行数:21,代码来源:ProjectionHelper.java
示例14: getCriteriaQuery
import javax.persistence.criteria.Selection; //导入依赖的package包/类
/**
* Create a TypedQuery from a request page
* @param page request page
* @return new TypedQuery
*/
@SuppressWarnings("unchecked")
private <K> TypedQuery<K> getCriteriaQuery(Page<K> page) {
CriteriaQuery<K> criteria = getCriteria(page);
CriteriaQuery<Long> countCriteria = (CriteriaQuery<Long>) getCriteria(page);
CriteriaBuilder cb = em.getCriteriaBuilder();
Root<?> root = countCriteria.getRoots().iterator().next();
countCriteria.select(cb.count(root));
page.setCount((em.createQuery(countCriteria).getSingleResult())
.intValue());
criteria.orderBy(getOrder(page, criteria));
// Add default select to entity class if none was set.
if (criteria.getSelection() == null) {
criteria.select((Selection<? extends K>) root);
}
return em.createQuery(criteria);
}
开发者ID:chelu,项目名称:jdal,代码行数:29,代码来源:JpaDao.java
示例15: sum
import javax.persistence.criteria.Selection; //导入依赖的package包/类
@Override
public <S> S sum(Class<S> resultClass, Specification<E> spec, LockModeType lockMode, List<SingularAttribute<E, ? extends Number>> properties) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<S> query = builder.createQuery(resultClass);
Root<E> root = query.from(getDomainClass());
List<Selection<?>> selectionList = Lists.newArrayList();
for (SingularAttribute<E, ? extends Number> property : properties) {
selectionList.add(builder.sum(root.get(property)));
}
return aggregate(builder, query, root, spec, selectionList, lockMode);
}
开发者ID:onsoul,项目名称:os,代码行数:12,代码来源:GenericRepositoryImpl.java
示例16: sum
import javax.persistence.criteria.Selection; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public R sum(String expr) {
Expression<Number> path = QueryFormHelper.getExpression(cb, root, expr);
query.select((Selection<? extends R>) cb.toDouble(cb.sum(path)));
TypedQuery<R> typedQuery = em.createQuery(query);
return typedQuery.getSingleResult();
}
开发者ID:szsucok,项目名称:sucok-framework,代码行数:8,代码来源:BaseDao.java
示例17: buscarTodos
import javax.persistence.criteria.Selection; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public List<T> buscarTodos(String... atributos) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery();
Root<T> root = cq.from(entityClass);
Selection[] selections = new Selection[atributos.length];
for (int i = 0; i < atributos.length; i++) {
selections[i] = root.get(atributos[i]);
}
cq.select(cb.construct(entityClass, selections));
cq.orderBy(cb.desc(root.get("id")));
return entityManager.createQuery(cq).getResultList();
}
开发者ID:JDanielT,项目名称:search-doc,代码行数:14,代码来源:DAOGenerico.java
示例18: selectFields
import javax.persistence.criteria.Selection; //导入依赖的package包/类
/**
* @param fields
* @return
* @throws IllegalArgumentException if the field is not part of the entity
*/
public JpaELFilterImpl selectFields(String[] fields) {
List<Selection> multiSelection = new ArrayList<>();
for (String f : fields) {
multiSelection.add(resultRoot.get(f));
}
critQ.multiselect(multiSelection);
return this;
}
开发者ID:gdjennings,项目名称:elrest-java,代码行数:16,代码来源:JpaELFilterImpl.java
示例19: getSelections
import javax.persistence.criteria.Selection; //导入依赖的package包/类
protected List<Selection<?>> getSelections(Root<E> root, CriteriaBuilder builder, String... attributeNames) {
List<Selection<?>> columns = Lists.newArrayList();
for(String attributeName : attributeNames) {
columns.add(builder.sum(this.getAttributeName(root, attributeName)));
}
return columns;
}
开发者ID:onsoul,项目名称:ha-db,代码行数:8,代码来源:GenericTable.java
示例20: getAlias
import javax.persistence.criteria.Selection; //导入依赖的package包/类
private synchronized String getAlias(Selection<?> selection) {
if (selection != null) {
String alias = selection.getAlias();
if (alias == null) {
if (aliasCount >= 1000) {
aliasCount = 0;
}
alias = "shopGeneratedAlias" + aliasCount++;
selection.alias(alias);
}
return alias;
}
return null;
}
开发者ID:justinbaby,项目名称:my-paper,代码行数:15,代码来源:BaseDaoImpl.java
注:本文中的javax.persistence.criteria.Selection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论