use of com.blazebit.persistence.impl.query.SetOperationQuerySpecification in project blaze-persistence by Blazebit.
the class BaseFinalSetOperationBuilderImpl method getTypedQuery.
@Override
@SuppressWarnings("unchecked")
protected TypedQuery<T> getTypedQuery(StringBuilder lateralSb, JoinNode lateralJoinNode) {
if (lateralSb != null) {
throw new IllegalStateException("Lateral join with set operations is not yet supported!");
}
Set<String> parameterListNames = new HashSet<String>();
Query leftMostQuery = setOperationManager.getStartQueryBuilder().getTypedQueryForFinalOperationBuilder();
Query baseQuery;
parameterManager.collectParameterListNames(leftMostQuery, parameterListNames);
Query q = leftMostQuery;
if (leftMostQuery instanceof TypedQueryWrapper<?>) {
q = ((TypedQueryWrapper<?>) leftMostQuery).getDelegate();
}
if (q instanceof AbstractCustomQuery<?>) {
AbstractCustomQuery<?> customQuery = (AbstractCustomQuery<?>) q;
List<Query> customQueryParticipants = customQuery.getParticipatingQueries();
baseQuery = customQueryParticipants.get(0);
} else {
baseQuery = q;
}
List<Query> setOperands = new ArrayList<Query>();
for (AbstractCommonQueryBuilder<?, ?, ?, ?, ?> setOperand : setOperationManager.getSetOperations()) {
q = setOperand.getQuery();
setOperands.add(q);
parameterManager.collectParameterListNames(q, parameterListNames);
}
String limit = null;
String offset = null;
// Main query will get the limit applied by the native mechanism
if (!isMainQuery) {
if (firstResult != 0) {
offset = Integer.toString(firstResult);
}
if (maxResults != Integer.MAX_VALUE) {
limit = Integer.toString(maxResults);
}
}
// Since this builder has no query of it's own, there can be no joins
List<String> keyRestrictedLeftJoinAliases = Collections.emptyList();
List<EntityFunctionNode> entityFunctionNodes = getEntityFunctionNodes(baseQuery);
boolean shouldRenderCteNodes = renderCteNodes(false);
List<CTENode> ctes = shouldRenderCteNodes ? getCteNodes(false) : Collections.EMPTY_LIST;
QuerySpecification querySpecification = new SetOperationQuerySpecification(this, leftMostQuery, baseQuery, setOperands, setOperationManager.getOperator(), getOrderByElements(), setOperationManager.isNested(), parameterManager.getParameterImpls(), parameterListNames, limit, offset, keyRestrictedLeftJoinAliases, entityFunctionNodes, mainQuery.cteManager.isRecursive(), ctes, shouldRenderCteNodes, mainQuery.getQueryConfiguration().isQueryPlanCacheEnabled());
// Unfortunately we need this little adapter here
@SuppressWarnings("rawtypes") TypedQuery<T> query = new CustomSQLTypedQuery<T>(querySpecification, baseQuery, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
// The main query will use the native mechanism for limit/offset
if (isMainQuery) {
if (firstResult != 0) {
query.setFirstResult(firstResult);
}
if (maxResults != Integer.MAX_VALUE) {
query.setMaxResults(maxResults);
}
}
parameterManager.parameterizeQuery(query);
return applyObjectBuilder(query);
}
Aggregations