Search in sources :

Example 1 with CTEQuerySpecification

use of com.blazebit.persistence.impl.query.CTEQuerySpecification in project blaze-persistence by Blazebit.

the class AbstractCTECriteriaBuilder method getQuery.

protected Query getQuery(String baseQueryString) {
    Set<JoinNode> keyRestrictedLeftJoins = getKeyRestrictedLeftJoins();
    Query query;
    if (hasLimit() || joinManager.hasEntityFunctions() || !keyRestrictedLeftJoins.isEmpty()) {
        // We need to change the underlying sql when doing a limit
        query = em.createQuery(baseQueryString);
        Set<String> parameterListNames = parameterManager.getParameterListNames(query);
        String limit = null;
        String offset = null;
        // The main query will handle that separately
        if (!isMainQuery) {
            if (firstResult != 0) {
                query.setFirstResult(firstResult);
                offset = Integer.toString(firstResult);
            }
            if (maxResults != Integer.MAX_VALUE) {
                query.setMaxResults(maxResults);
                limit = Integer.toString(maxResults);
            }
        }
        List<String> keyRestrictedLeftJoinAliases = getKeyRestrictedLeftJoinAliases(query, keyRestrictedLeftJoins, Collections.<ClauseType>emptySet());
        List<EntityFunctionNode> entityFunctionNodes = getEntityFunctionNodes(query);
        QuerySpecification querySpecification = new CTEQuerySpecification(this, query, parameterManager.getParameterImpls(), parameterListNames, limit, offset, keyRestrictedLeftJoinAliases, entityFunctionNodes);
        query = new CustomSQLQuery(querySpecification, query, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
    } else {
        query = em.createQuery(baseQueryString);
        if (parameterManager.getCriteriaNameMapping() != null) {
            query = new QueryWrapper(query, parameterManager.getCriteriaNameMapping());
        }
    }
    parameterManager.parameterizeQuery(query);
    return query;
}
Also used : CTEQuerySpecification(com.blazebit.persistence.impl.query.CTEQuerySpecification) QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) Query(javax.persistence.Query) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) QueryWrapper(com.blazebit.persistence.impl.query.QueryWrapper) CTEQuerySpecification(com.blazebit.persistence.impl.query.CTEQuerySpecification) EntityFunctionNode(com.blazebit.persistence.impl.query.EntityFunctionNode)

Aggregations

CTEQuerySpecification (com.blazebit.persistence.impl.query.CTEQuerySpecification)1 CustomSQLQuery (com.blazebit.persistence.impl.query.CustomSQLQuery)1 EntityFunctionNode (com.blazebit.persistence.impl.query.EntityFunctionNode)1 QuerySpecification (com.blazebit.persistence.impl.query.QuerySpecification)1 QueryWrapper (com.blazebit.persistence.impl.query.QueryWrapper)1 Query (javax.persistence.Query)1