DefaultCompoundSelection(List<Selection<?>> selections, Class resultClazz) { this.selections = selections; this.resultType = resultClazz; if(isCompoundSelection()) { this.alias = selections.get(0).getAlias(); } }
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() );
@Override protected <T,R> Expression getOrderByExpression(CriteriaQuery<R> query, Class<T> queryType, String orderByListId) { List<Selection<?>> selections = query.getSelection().getCompoundSelectionItems(); Selection orderBySelection = null; if( orderByListId.equals(QueryParameterIdentifiers.TASK_ID_LIST) ) { orderBySelection = selections.get(0); } else if( orderByListId.equals(QueryParameterIdentifiers.TASK_NAME_LIST) ) { orderBySelection = selections.get(1); } else if( orderByListId.equals(QueryParameterIdentifiers.TASK_STATUS_LIST) ) { orderBySelection = selections.get(4); } else if( orderByListId.equals(QueryParameterIdentifiers.CREATED_BY_LIST) ) { orderBySelection = selections.get(8); } else if( orderByListId.equals(QueryParameterIdentifiers.CREATED_ON_LIST) ) { orderBySelection = selections.get(9); } else if( orderByListId.equals(QueryParameterIdentifiers.PROCESS_INSTANCE_ID_LIST) ) { orderBySelection = selections.get(14); } return (Expression<?>) orderBySelection; }
if (s.isCompoundSelection()) { getProjections(exps, s.getCompoundSelectionItems(), projections, aliases, clauses, factory, q, model, exp2Vals); } else { Value val = (exp2Vals != null && exp2Vals.containsKey(s) ? exp2Vals.get(s) : ((ExpressionImpl<?>)s).toValue(factory, q)); String alias = s.getAlias(); val.setAlias(alias); projections.add(val);
if (selection.isCompoundSelection()) { Class<?> selectionType = selection.getJavaType(); for (Selection<?> s : selection.getCompoundSelectionItems()) { renderSelection(cb, context, s, treatedSelections); ((CriteriaBuilder) cb).selectNew(new JpaTupleObjectBuilder(selection.getCompoundSelectionItems()) { @Override protected void renderSelection(SelectBuilder<?> cb, Selection<?> s) { for (Selection<?> s : selection.getCompoundSelectionItems()) { renderSelection(cb, context, s, treatedSelections); for (Selection<?> s : selection.getCompoundSelectionItems()) { if (s instanceof Subquery<?>) { if (s.getAlias() != null) { context.pushSubqueryInitiator(b.withSubquery(s.getAlias())); } else { context.pushSubqueryInitiator(b.withSubquery()); if (s.getAlias() != null && !(s instanceof AbstractFrom<?, ?>)) { b.with(expr, s.getAlias()); } else { b.with(expr); if (s.getAlias() != null) { initiator = b.withSubqueries(expr, s.getAlias()); } else { initiator = b.withSubqueries(expr);
/** * Package-protected method to centralize checking of criteria query * multiselects as defined by the * {@link CriteriaQuery#multiselect(List)} method. * * @param selections The selection varargs to check * * @throws IllegalArgumentException If, as per * {@link CriteriaQuery#multiselect(List)} 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) { for ( Selection<?> selection : selections ) { if ( selection.isCompoundSelection() ) { if ( selection.getJavaType().isArray() ) { throw new IllegalArgumentException( "multiselect selections cannot contain " + "compound array-valued elements" ); } if ( Tuple.class.isAssignableFrom( selection.getJavaType() ) ) { throw new IllegalArgumentException( "multiselect selections cannot contain " + "compound tuple-valued elements" ); } } } }
/** * @param selections * the selections * * @since 2.0.0 */ public void updateResultClass(List<Selection<?>> selections) { if (selections.size() == 1) { final Selection<?> selection = selections.get(0); this.resultType = (Class<T>) selection.getJavaType(); } else { this.resultType = (Class<T>) Object[].class; } }
String alias = select.getAlias(); Class<? extends S> clazzType = select.getJavaType(); builder.appendAlias(from.getAlias() != null ? from.getAlias() : select.getAlias()); String alias = from.getAlias() != null ? from.getAlias() : select.getAlias(); builder.appendMultiOrdering(orderings, alias);
/** * Gets The result alias, if none set a default one and return it * * @param selection * @return root alias or generated one */ public static synchronized <T> String getOrCreateAlias(Selection<T> selection) { // reset alias count if (aliasCount > 1000) aliasCount = 0; String alias = selection.getAlias(); if (alias == null) { alias = "JDAL_generatedAlias" + aliasCount++; selection.alias(alias); } return alias; }
findRootAndParameters(selection); this.selection = (SelectionImpl) selection; if (selection.isCompoundSelection()) { new Object[] { ((CompoundSelectionImpl)this.selection).getDuplicateAliasNames() })); if (selection.getJavaType().equals(Tuple.class)) { this.queryResult = ResultType.TUPLE; this.queryType = Tuple.class; } else if (((InternalSelection) selection).isConstructor()) { Selection[] selectArray = selection.getCompoundSelectionItems().toArray(new Selection[selection.getCompoundSelectionItems().size()]); populateAndSetConstructorSelection((ConstructorSelectionImpl)selection, this.selection.getJavaType(), selectArray); this.queryType = selection.getJavaType(); } else { this.queryResult = ResultType.OBJECT_ARRAY; Class queryType = selection.getJavaType(); if (queryType != null) { this.queryType = queryType;
protected void findRootAndParameters(Selection<?> selection) { if (selection.isCompoundSelection()) { for (Selection subSelection : selection.getCompoundSelectionItems()) { findRootAndParameters(subSelection); } } }
void assertNoCompoundSelection(Selection<?>...args) { if (args == null) return; for (Selection<?> s : args) { if (s.isCompoundSelection() && !(s.getClass() == NewInstance.class)) { throw new IllegalArgumentException("compound selection " + s + " can not be nested in " + this); } } }
selection.alias(criteria.getPropertyAlias());
if (s.isCompoundSelection()) { getProjections(exps, s.getCompoundSelectionItems(), projections, aliases, clauses, factory, q, model, exp2Vals); } else { Value val = (exp2Vals != null && exp2Vals.containsKey(s) ? exp2Vals.get(s) : ((ExpressionImpl<?>)s).toValue(factory, q)); String alias = s.getAlias(); val.setAlias(alias); projections.add(val);
if (selection.isCompoundSelection()) { Class<?> selectionType = selection.getJavaType(); for (Selection<?> s : selection.getCompoundSelectionItems()) { renderSelection(cb, context, s, treatedSelections); ((CriteriaBuilder) cb).selectNew(new JpaTupleObjectBuilder(selection.getCompoundSelectionItems()) { @Override protected void renderSelection(SelectBuilder<?> cb, Selection<?> s) { for (Selection<?> s : selection.getCompoundSelectionItems()) { renderSelection(cb, context, s, treatedSelections); for (Selection<?> s : selection.getCompoundSelectionItems()) { if (s instanceof Subquery<?>) { if (s.getAlias() != null) { context.pushSubqueryInitiator(b.withSubquery(s.getAlias())); } else { context.pushSubqueryInitiator(b.withSubquery()); if (s.getAlias() != null && !(s instanceof AbstractFrom<?, ?>)) { b.with(expr, s.getAlias()); } else { b.with(expr); if (s.getAlias() != null) { initiator = b.withSubqueries(expr, s.getAlias()); } else { initiator = b.withSubqueries(expr);
if (selection.isCompoundSelection()) { if (selection.getJavaType().isArray()) { throw new IllegalArgumentException("Illegal array selection in multiselect selections"); if (Tuple.class.isAssignableFrom(selection.getJavaType())) { throw new IllegalArgumentException("Illegal tuple selection in multiselect selections");
/** * @param selections * the selections * * @since 2.0.0 */ public void updateResultClass(List<Selection<?>> selections) { if (selections.size() == 1) { final Selection<?> selection = selections.get(0); this.resultType = (Class<T>) selection.getJavaType(); } else { this.resultType = (Class<T>) Object[].class; } }
} else { if (((InternalSelection) nested).isFrom()) { reportQuery.addItem(nested.getAlias(), ((SelectionImpl) nested).getCurrentNode(), ((FromImpl) nested).findJoinFetches()); } else if (((InternalExpression) nested).isCompoundExpression() && ((FunctionExpressionImpl) nested).getOperation() == CriteriaBuilderImpl.SIZE) { reportQuery.addAttribute(nested.getAlias(), collectionExpression.getCurrentNode().count(), ClassConstants.INTEGER); reportQuery.addGrouping(fromExpression.getCurrentNode()); } else { reportQuery.addAttribute(nested.getAlias(), ((SelectionImpl) nested).getCurrentNode(), nested.getJavaType());
@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); }