use of com.blazebit.persistence.impl.query.UpdateModificationQuerySpecification in project blaze-persistence by Blazebit.
the class BaseUpdateCriteriaBuilderImpl method getQuerySpecification.
private <R> QuerySpecification getQuerySpecification(Query baseQuery, Query exampleQuery, String[] returningColumns, ReturningObjectBuilder<R> objectBuilder, Map<DbmsModificationState, String> includedModificationStates) {
Set<String> parameterListNames = parameterManager.getParameterListNames(baseQuery);
boolean isEmbedded = this instanceof ReturningBuilder;
boolean shouldRenderCteNodes = renderCteNodes(isEmbedded);
List<CTENode> ctes = shouldRenderCteNodes ? getCteNodes(isEmbedded) : Collections.EMPTY_LIST;
List<String> setColumns = getSetColumns();
ExtendedQuerySupport extendedQuerySupport = getService(ExtendedQuerySupport.class);
Map<String, String> aliasMapping = new TreeMap<>();
JoinNode rootNode = joinManager.getRoots().get(0);
String[] idColumns = null;
String tableToUpdate = null;
String tableAlias = null;
if ((joinManager.getRoots().size() > 1 || rootNode.hasChildNodes()) && mainQuery.dbmsDialect.getUpdateJoinStyle() != UpdateJoinStyle.NONE) {
String sql = getService(ExtendedQuerySupport.class).getSql(em, baseQuery);
if (SqlUtils.indexOfSelect(sql) != -1) {
idColumns = getIdColumns(getMetamodel().getManagedType(ExtendedManagedType.class, entityType));
int fromIndex = SqlUtils.indexOfFrom(sql);
int tableStartIndex = fromIndex + SqlUtils.FROM.length();
int tableEndIndex = sql.indexOf(" ", tableStartIndex);
tableToUpdate = sql.substring(tableStartIndex, tableEndIndex);
tableAlias = extendedQuerySupport.getSqlAlias(em, baseQuery, entityAlias);
for (String idColumn : idColumns) {
aliasMapping.put(tableAlias + "." + idColumn, "tmp.c" + aliasMapping.size());
}
SqlUtils.buildAliasMappingForTopLevelSelects(extendedQuerySupport.getSql(em, baseQuery), "tmp", aliasMapping);
}
}
return new UpdateModificationQuerySpecification(this, baseQuery, exampleQuery, parameterManager.getParameterImpls(), parameterListNames, mainQuery.cteManager.isRecursive(), ctes, shouldRenderCteNodes, isEmbedded, returningColumns, objectBuilder, includedModificationStates, returningAttributeBindingMap, mainQuery.getQueryConfiguration().isQueryPlanCacheEnabled(), tableToUpdate, tableAlias, idColumns, setColumns, getForeignKeyParticipatingQueries(), aliasMapping, getUpdateExampleQuery());
}
Aggregations