Search in sources :

Example 11 with QuerySpecification

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

the class BaseUpdateCriteriaBuilderImpl method getExecuteWithReturningQuery.

@Override
protected <R> TypedQuery<ReturningResult<R>> getExecuteWithReturningQuery(TypedQuery<Object[]> exampleQuery, Query baseQuery, String[] returningColumns, ReturningObjectBuilder<R> objectBuilder) {
    QuerySpecification querySpecification = getQuerySpecification(baseQuery, exampleQuery, returningColumns, objectBuilder, null);
    CustomReturningSQLTypedQuery<R> query = new CustomReturningSQLTypedQuery<R>(querySpecification, exampleQuery, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
    query.setFirstResult(firstResult);
    query.setMaxResults(maxResults);
    parameterManager.parameterizeQuery(query);
    return query;
}
Also used : QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) UpdateModificationQuerySpecification(com.blazebit.persistence.impl.query.UpdateModificationQuerySpecification) CustomReturningSQLTypedQuery(com.blazebit.persistence.impl.query.CustomReturningSQLTypedQuery)

Example 12 with QuerySpecification

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

the class AbstractModificationCriteriaBuilder method getQuery.

@Override
protected Query getQuery(Map<DbmsModificationState, String> includedModificationStates) {
    Query query;
    // We use this to make these features only available to Hibernate as it is the only provider that supports sql replace yet
    if (hasLimit() || mainQuery.cteManager.hasCtes() || returningAttributeBindingMap.size() > 0) {
        // We need to change the underlying sql when doing a limit with hibernate since it does not support limiting insert ... select statements
        // For CTEs we will also need to change the underlying sql
        query = em.createQuery(getBaseQueryStringWithCheck(null, null));
        Set<String> parameterListNames = parameterManager.getParameterListNames(query);
        boolean isEmbedded = this instanceof ReturningBuilder;
        String[] returningColumns = getReturningColumns();
        boolean shouldRenderCteNodes = renderCteNodes(isEmbedded);
        List<CTENode> ctes = shouldRenderCteNodes ? getCteNodes(isEmbedded) : Collections.EMPTY_LIST;
        QuerySpecification querySpecification = new ModificationQuerySpecification(this, query, getCountExampleQuery(), parameterManager.getParameterImpls(), parameterListNames, mainQuery.cteManager.isRecursive(), ctes, shouldRenderCteNodes, isEmbedded, returningColumns, null, includedModificationStates, returningAttributeBindingMap, mainQuery.getQueryConfiguration().isQueryPlanCacheEnabled());
        query = new CustomSQLQuery(querySpecification, query, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
    } else {
        query = em.createQuery(getBaseQueryStringWithCheck(null, null));
        if (parameterManager.getCriteriaNameMapping() != null) {
            query = new QueryWrapper(query, parameterManager.getCriteriaNameMapping());
        }
    }
    parameterManager.parameterizeQuery(query);
    return query;
}
Also used : ReturningBuilder(com.blazebit.persistence.ReturningBuilder) SimpleReturningBuilder(com.blazebit.persistence.SimpleReturningBuilder) QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) ModificationQuerySpecification(com.blazebit.persistence.impl.query.ModificationQuerySpecification) TypedQuery(javax.persistence.TypedQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) Query(javax.persistence.Query) CustomReturningSQLTypedQuery(com.blazebit.persistence.impl.query.CustomReturningSQLTypedQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) QueryWrapper(com.blazebit.persistence.impl.query.QueryWrapper) CTENode(com.blazebit.persistence.impl.query.CTENode) ModificationQuerySpecification(com.blazebit.persistence.impl.query.ModificationQuerySpecification)

Example 13 with QuerySpecification

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

the class BaseInsertCriteriaBuilderImpl method getQuery.

@Override
protected Query getQuery(Map<DbmsModificationState, String> includedModificationStates) {
    // We need to change the underlying sql when doing a limit with hibernate since it does not support limiting insert ... select statements
    Query baseQuery = em.createQuery(getBaseQueryStringWithCheck(null, null));
    Set<String> parameterListNames = parameterManager.getParameterListNames(baseQuery);
    Set<JoinNode> keyRestrictedLeftJoins = getKeyRestrictedLeftJoins();
    List<String> keyRestrictedLeftJoinAliases = getKeyRestrictedLeftJoinAliases(baseQuery, keyRestrictedLeftJoins, Collections.EMPTY_SET);
    List<EntityFunctionNode> entityFunctionNodes = getEntityFunctionNodes(baseQuery);
    boolean isEmbedded = this instanceof ReturningBuilder;
    String[] returningColumns = getReturningColumns();
    boolean shouldRenderCteNodes = renderCteNodes(isEmbedded);
    List<CTENode> ctes = shouldRenderCteNodes ? getCteNodes(isEmbedded) : Collections.EMPTY_LIST;
    QuerySpecification querySpecification = new ModificationQuerySpecification(this, baseQuery, getCountExampleQuery(), parameterManager.getParameterImpls(), parameterListNames, keyRestrictedLeftJoinAliases, entityFunctionNodes, mainQuery.cteManager.isRecursive(), ctes, shouldRenderCteNodes, isEmbedded, returningColumns, null, includedModificationStates, returningAttributeBindingMap, mainQuery.getQueryConfiguration().isQueryPlanCacheEnabled());
    CustomSQLQuery query = new CustomSQLQuery(querySpecification, baseQuery, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
    parameterManager.parameterizeQuery(query);
    query.setFirstResult(firstResult);
    query.setMaxResults(maxResults);
    return query;
}
Also used : ReturningBuilder(com.blazebit.persistence.ReturningBuilder) Query(javax.persistence.Query) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) ModificationQuerySpecification(com.blazebit.persistence.impl.query.ModificationQuerySpecification) EntityFunctionNode(com.blazebit.persistence.impl.query.EntityFunctionNode) CTENode(com.blazebit.persistence.impl.query.CTENode) ModificationQuerySpecification(com.blazebit.persistence.impl.query.ModificationQuerySpecification)

Example 14 with QuerySpecification

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

the class AbstractUpdateCollectionCriteriaBuilder method getQuery.

@Override
protected Query getQuery(Map<DbmsModificationState, String> includedModificationStates) {
    if (collectionAttribute.getJoinTable() == null) {
        return super.getQuery(includedModificationStates);
    } else {
        Query baseQuery = em.createQuery(getBaseQueryStringWithCheck(null, null));
        QuerySpecification querySpecification = getQuerySpecification(baseQuery, getCountExampleQuery(), getReturningColumns(), null, includedModificationStates);
        CustomSQLQuery query = new CustomSQLQuery(querySpecification, baseQuery, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
        parameterManager.parameterizeQuery(query);
        return query;
    }
}
Also used : QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) CollectionUpdateModificationQuerySpecification(com.blazebit.persistence.impl.query.CollectionUpdateModificationQuerySpecification) TypedQuery(javax.persistence.TypedQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) Query(javax.persistence.Query) CustomReturningSQLTypedQuery(com.blazebit.persistence.impl.query.CustomReturningSQLTypedQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery)

Example 15 with QuerySpecification

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

the class BaseDeleteCriteriaBuilderImpl method getQuery.

@Override
protected Query getQuery(Map<DbmsModificationState, String> includedModificationStates) {
    prepareAndCheck();
    JoinNode rootNode = joinManager.getRoots().get(0);
    if (joinManager.getRoots().size() > 1 || rootNode.hasChildNodes()) {
        // Prefer an exists subquery instead of MERGE
        if (!mainQuery.supportsAdvancedSql() || mainQuery.dbmsDialect.getDeleteJoinStyle() == DeleteJoinStyle.NONE || mainQuery.dbmsDialect.getDeleteJoinStyle() == DeleteJoinStyle.MERGE) {
            return super.getQuery(includedModificationStates);
        }
        Query baseQuery = em.createQuery(getBaseQueryStringWithCheck(null, null));
        QuerySpecification querySpecification = getQuerySpecification(baseQuery, getCountExampleQuery(), getReturningColumns(), null, includedModificationStates);
        CustomSQLQuery query = new CustomSQLQuery(querySpecification, baseQuery, parameterManager.getCriteriaNameMapping(), parameterManager.getTransformers(), parameterManager.getValuesParameters(), parameterManager.getValuesBinders());
        parameterManager.parameterizeQuery(query);
        return query;
    } else {
        return super.getQuery(includedModificationStates);
    }
}
Also used : QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) DeleteModificationQuerySpecification(com.blazebit.persistence.impl.query.DeleteModificationQuerySpecification) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) CustomReturningSQLTypedQuery(com.blazebit.persistence.impl.query.CustomReturningSQLTypedQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery) CustomSQLQuery(com.blazebit.persistence.impl.query.CustomSQLQuery)

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