use of com.blazebit.persistence.impl.query.QuerySpecification in project blaze-persistence by Blazebit.
the class PaginatedCriteriaBuilderImpl method getObjectQueryById.
@SuppressWarnings("unchecked")
private TypedQuery<T> getObjectQueryById(boolean normalQueryMode, Set<JoinNode> keyRestrictedLeftJoins, List<JoinNode> entityFunctions) {
ResolvedExpression[] identifierExpressionsToUse = getIdentifierExpressionsToUse();
String skippedParameterPrefix = identifierExpressionsToUse.length == 1 ? ID_PARAM_NAME : ID_PARAM_NAME + "_";
if (normalQueryMode && isEmpty(keyRestrictedLeftJoins, OBJECT_QUERY_CLAUSE_EXCLUSIONS)) {
TypedQuery<T> query = (TypedQuery<T>) em.createQuery(getBaseQueryString(null, null), selectManager.getExpectedQueryResultType());
if (isCacheable()) {
mainQuery.jpaProvider.setCacheable(query);
}
parameterManager.parameterizeQuery(query, skippedParameterPrefix);
return applyObjectBuilder(query);
}
TypedQuery<T> baseQuery = (TypedQuery<T>) em.createQuery(getBaseQueryString(null, null), selectManager.getExpectedQueryResultType());
Set<String> parameterListNames = parameterManager.getParameterListNames(baseQuery, ID_PARAM_NAME);
if (identifierExpressionsToUse.length == 1) {
parameterListNames.add(ID_PARAM_NAME);
}
List<String> keyRestrictedLeftJoinAliases = getKeyRestrictedLeftJoinAliases(baseQuery, keyRestrictedLeftJoins, OBJECT_QUERY_CLAUSE_EXCLUSIONS);
List<EntityFunctionNode> entityFunctionNodes = getEntityFunctionNodes(baseQuery, entityFunctions);
boolean shouldRenderCteNodes = renderCteNodes(false);
List<CTENode> ctes = shouldRenderCteNodes ? getCteNodes(false) : Collections.EMPTY_LIST;
Collection<Parameter<?>> parameters;
if (identifierExpressionsToUse.length == 1) {
parameters = new ArrayList<>(parameterManager.getParameters());
parameters.add(baseQuery.getParameter(ID_PARAM_NAME));
} else {
parameters = (Collection<Parameter<?>>) (Collection<?>) parameterManager.getParameterImpls();
}
QuerySpecification querySpecification = new CustomQuerySpecification(this, baseQuery, parameters, parameterListNames, null, null, keyRestrictedLeftJoinAliases, entityFunctionNodes, mainQuery.cteManager.isRecursive(), ctes, shouldRenderCteNodes, mainQuery.getQueryConfiguration().isQueryPlanCacheEnabled(), null);
TypedQuery<T> query = new CustomSQLTypedQuery<T>(querySpecification, baseQuery, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
parameterManager.parameterizeQuery(query, skippedParameterPrefix);
return applyObjectBuilder(query);
}
Aggregations