Search in sources :

Example 21 with QuerySpecification

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);
}
Also used : CustomSQLTypedQuery(com.blazebit.persistence.impl.query.CustomSQLTypedQuery) ObjectBuilderTypedQuery(com.blazebit.persistence.impl.query.ObjectBuilderTypedQuery) TypedQuery(javax.persistence.TypedQuery) QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) CustomQuerySpecification(com.blazebit.persistence.impl.query.CustomQuerySpecification) CustomSQLTypedQuery(com.blazebit.persistence.impl.query.CustomSQLTypedQuery) Parameter(javax.persistence.Parameter) Collection(java.util.Collection) EntityFunctionNode(com.blazebit.persistence.impl.query.EntityFunctionNode) CustomQuerySpecification(com.blazebit.persistence.impl.query.CustomQuerySpecification) CTENode(com.blazebit.persistence.impl.query.CTENode)

Aggregations

QuerySpecification (com.blazebit.persistence.impl.query.QuerySpecification)21 CustomReturningSQLTypedQuery (com.blazebit.persistence.impl.query.CustomReturningSQLTypedQuery)12 TypedQuery (javax.persistence.TypedQuery)11 CTENode (com.blazebit.persistence.impl.query.CTENode)10 Query (javax.persistence.Query)10 EntityFunctionNode (com.blazebit.persistence.impl.query.EntityFunctionNode)9 CustomSQLQuery (com.blazebit.persistence.impl.query.CustomSQLQuery)8 CustomSQLTypedQuery (com.blazebit.persistence.impl.query.CustomSQLTypedQuery)7 CustomQuerySpecification (com.blazebit.persistence.impl.query.CustomQuerySpecification)6 Collection (java.util.Collection)4 Parameter (javax.persistence.Parameter)4 ModificationQuerySpecification (com.blazebit.persistence.impl.query.ModificationQuerySpecification)3 ObjectBuilderTypedQuery (com.blazebit.persistence.impl.query.ObjectBuilderTypedQuery)3 ReturningBuilder (com.blazebit.persistence.ReturningBuilder)2 CollectionDeleteModificationQuerySpecification (com.blazebit.persistence.impl.query.CollectionDeleteModificationQuerySpecification)2 CollectionInsertModificationQuerySpecification (com.blazebit.persistence.impl.query.CollectionInsertModificationQuerySpecification)2 CollectionUpdateModificationQuerySpecification (com.blazebit.persistence.impl.query.CollectionUpdateModificationQuerySpecification)2 DeleteModificationQuerySpecification (com.blazebit.persistence.impl.query.DeleteModificationQuerySpecification)2 QueryWrapper (com.blazebit.persistence.impl.query.QueryWrapper)2 TypedQueryWrapper (com.blazebit.persistence.impl.query.TypedQueryWrapper)2