Search in sources :

Example 6 with CustomSQLQuery

use of com.blazebit.persistence.impl.query.CustomSQLQuery 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 7 with CustomSQLQuery

use of com.blazebit.persistence.impl.query.CustomSQLQuery 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 8 with CustomSQLQuery

use of com.blazebit.persistence.impl.query.CustomSQLQuery 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)

Example 9 with CustomSQLQuery

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

the class AbstractInsertCollectionCriteriaBuilder method getQuery.

@Override
protected Query getQuery(Map<DbmsModificationState, String> 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);
    baseQuery.setFirstResult(firstResult);
    baseQuery.setMaxResults(maxResults);
    return query;
}
Also used : QuerySpecification(com.blazebit.persistence.impl.query.QuerySpecification) CollectionInsertModificationQuerySpecification(com.blazebit.persistence.impl.query.CollectionInsertModificationQuerySpecification) 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)

Aggregations

CustomSQLQuery (com.blazebit.persistence.impl.query.CustomSQLQuery)9 Query (javax.persistence.Query)9 QuerySpecification (com.blazebit.persistence.impl.query.QuerySpecification)8 TypedQuery (javax.persistence.TypedQuery)7 CustomReturningSQLTypedQuery (com.blazebit.persistence.impl.query.CustomReturningSQLTypedQuery)6 CTENode (com.blazebit.persistence.impl.query.CTENode)3 ReturningBuilder (com.blazebit.persistence.ReturningBuilder)2 EntityFunctionNode (com.blazebit.persistence.impl.query.EntityFunctionNode)2 ModificationQuerySpecification (com.blazebit.persistence.impl.query.ModificationQuerySpecification)2 QueryWrapper (com.blazebit.persistence.impl.query.QueryWrapper)2 SimpleReturningBuilder (com.blazebit.persistence.SimpleReturningBuilder)1 AbstractCustomQuery (com.blazebit.persistence.impl.query.AbstractCustomQuery)1 CTEQuerySpecification (com.blazebit.persistence.impl.query.CTEQuerySpecification)1 CollectionDeleteModificationQuerySpecification (com.blazebit.persistence.impl.query.CollectionDeleteModificationQuerySpecification)1 CollectionInsertModificationQuerySpecification (com.blazebit.persistence.impl.query.CollectionInsertModificationQuerySpecification)1 CollectionUpdateModificationQuerySpecification (com.blazebit.persistence.impl.query.CollectionUpdateModificationQuerySpecification)1 CustomSQLTypedQuery (com.blazebit.persistence.impl.query.CustomSQLTypedQuery)1 DeleteModificationQuerySpecification (com.blazebit.persistence.impl.query.DeleteModificationQuerySpecification)1 ObjectBuilderTypedQuery (com.blazebit.persistence.impl.query.ObjectBuilderTypedQuery)1 UpdateModificationQuerySpecification (com.blazebit.persistence.impl.query.UpdateModificationQuerySpecification)1