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;
}
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;
}
}
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);
}
}
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;
}
Aggregations