use of com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.JoinCorrelationBuilder in project blaze-persistence by Blazebit.
the class ExpressionCorrelationJoinTupleElementMapper method applyMapping.
@Override
public void applyMapping(SelectBuilder<?> queryBuilder, ParameterHolder<?> parameterHolder, Map<String, Object> optionalParameters, ViewJpqlMacro viewJpqlMacro, EmbeddingViewJpqlMacro embeddingViewJpqlMacro, boolean asString) {
String oldViewPath = viewJpqlMacro.getViewPath();
String oldEmbeddingViewPath = embeddingViewJpqlMacro.getEmbeddingViewPath();
viewJpqlMacro.setViewPath(embeddingViewPath);
embeddingViewJpqlMacro.setEmbeddingViewPath(embeddingViewPath);
FullQueryBuilder<?, ?> fullQueryBuilder;
if (queryBuilder instanceof ConstrainedSelectBuilder) {
fullQueryBuilder = ((ConstrainedSelectBuilder) queryBuilder).getQueryBuilder();
} else {
fullQueryBuilder = (FullQueryBuilder<?, ?>) queryBuilder;
}
int originalFirstResult = -1;
int originalMaxResults = -1;
if (queryBuilder instanceof LimitBuilder<?>) {
originalFirstResult = ((LimitBuilder<?>) queryBuilder).getFirstResult();
originalMaxResults = ((LimitBuilder<?>) queryBuilder).getMaxResults();
}
JoinCorrelationBuilder correlationBuilder = new JoinCorrelationBuilder(parameterHolder, optionalParameters, fullQueryBuilder, joinBase, correlationAlias, correlationExternalAlias, attributePath, JoinType.LEFT, limiter);
provider.applyCorrelation(correlationBuilder, correlationBasis);
if (queryBuilder instanceof LimitBuilder<?>) {
if (originalFirstResult != ((LimitBuilder<?>) queryBuilder).getFirstResult() || originalMaxResults != ((LimitBuilder<?>) queryBuilder).getMaxResults()) {
throw new IllegalArgumentException("Correlation provider '" + provider + "' wrongly uses setFirstResult() or setMaxResults() on the query builder which might lead to wrong results. Use SELECT fetching with batch size 1 or reformulate the correlation provider to use the limit/offset in a subquery!");
}
}
correlationBuilder.finish();
// Basic element has an alias, subviews don't
if (alias != null) {
viewJpqlMacro.setViewPath(null);
queryBuilder.select(correlationResult, alias);
}
viewJpqlMacro.setViewPath(oldViewPath);
embeddingViewJpqlMacro.setEmbeddingViewPath(oldEmbeddingViewPath);
if (fetches.length != 0) {
for (int i = 0; i < fetches.length; i++) {
fullQueryBuilder.fetch(correlationBuilder.getCorrelationAlias() + "." + fetches[i]);
}
}
}
use of com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.JoinCorrelationBuilder in project blaze-persistence by Blazebit.
the class EntityViewRootSecondaryMapper method apply.
@Override
public void apply(FullQueryBuilder<?, ?> fullQueryBuilder, ParameterHolder<?> parameterHolder, Map<String, Object> optionalParameters, ViewJpqlMacro viewJpqlMacro, EmbeddingViewJpqlMacro embeddingViewJpqlMacro) {
String oldViewPath = viewJpqlMacro.getViewPath();
String oldEmbeddingViewPath = embeddingViewJpqlMacro.getEmbeddingViewPath();
viewJpqlMacro.setViewPath(viewPath);
embeddingViewJpqlMacro.setEmbeddingViewPath(embeddingViewPath);
CorrelationProvider correlationProvider = correlationProviderFactory.create(parameterHolder, optionalParameters);
String correlationAlias;
if (limiter == null) {
correlationAlias = entityViewRootName;
} else {
correlationAlias = "_sub_" + entityViewRootName;
}
JoinCorrelationBuilder correlationBuilder = new JoinCorrelationBuilder(parameterHolder, optionalParameters, fullQueryBuilder, viewJpqlMacro.getViewPath(), correlationAlias, entityViewRootName, attributePath, joinType, limiter);
correlationProvider.applyCorrelation(correlationBuilder, viewJpqlMacro.getViewPath());
correlationBuilder.finish();
fullQueryBuilder.fetch(fetches);
embeddingViewJpqlMacro.setEmbeddingViewPath(oldEmbeddingViewPath);
viewJpqlMacro.setViewPath(oldViewPath);
}
use of com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.JoinCorrelationBuilder in project blaze-persistence by Blazebit.
the class ParameterizedExpressionCorrelationJoinTupleElementMapper method applyMapping.
@Override
public void applyMapping(SelectBuilder<?> queryBuilder, ParameterHolder<?> parameterHolder, Map<String, Object> optionalParameters, ViewJpqlMacro viewJpqlMacro, EmbeddingViewJpqlMacro embeddingViewJpqlMacro, boolean asString) {
String oldViewPath = viewJpqlMacro.getViewPath();
String oldEmbeddingViewPath = embeddingViewJpqlMacro.getEmbeddingViewPath();
viewJpqlMacro.setViewPath(embeddingViewPath);
embeddingViewJpqlMacro.setEmbeddingViewPath(embeddingViewPath);
FullQueryBuilder<?, ?> fullQueryBuilder;
if (queryBuilder instanceof ConstrainedSelectBuilder) {
fullQueryBuilder = ((ConstrainedSelectBuilder) queryBuilder).getQueryBuilder();
} else {
fullQueryBuilder = (FullQueryBuilder<?, ?>) queryBuilder;
}
int originalFirstResult = -1;
int originalMaxResults = -1;
if (queryBuilder instanceof LimitBuilder<?>) {
originalFirstResult = ((LimitBuilder<?>) queryBuilder).getFirstResult();
originalMaxResults = ((LimitBuilder<?>) queryBuilder).getMaxResults();
}
JoinCorrelationBuilder correlationBuilder = new JoinCorrelationBuilder(parameterHolder, optionalParameters, fullQueryBuilder, joinBase, correlationAlias, correlationExternalAlias, attributePath, JoinType.LEFT, limiter);
CorrelationProvider provider = providerFactory.create(parameterHolder, optionalParameters);
provider.applyCorrelation(correlationBuilder, correlationBasis);
if (queryBuilder instanceof LimitBuilder<?>) {
if (originalFirstResult != ((LimitBuilder<?>) queryBuilder).getFirstResult() || originalMaxResults != ((LimitBuilder<?>) queryBuilder).getMaxResults()) {
throw new IllegalArgumentException("Correlation provider '" + provider + "' wrongly uses setFirstResult() or setMaxResults() on the query builder which might lead to wrong results. Use SELECT fetching with batch size 1 or reformulate the correlation provider to use the limit/offset in a subquery!");
}
}
correlationBuilder.finish();
// Basic element has an alias, subviews don't
if (alias != null) {
viewJpqlMacro.setViewPath(null);
queryBuilder.select(correlationResult, alias);
}
viewJpqlMacro.setViewPath(oldViewPath);
embeddingViewJpqlMacro.setEmbeddingViewPath(oldEmbeddingViewPath);
if (fetches.length != 0) {
for (int i = 0; i < fetches.length; i++) {
fullQueryBuilder.fetch(correlationBuilder.getCorrelationAlias() + "." + fetches[i]);
}
}
}
use of com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.JoinCorrelationBuilder in project blaze-persistence by Blazebit.
the class ManagedViewTypeImpl method renderSecondaryMappings.
@Override
public void renderSecondaryMappings(String viewPath, BaseQueryBuilder<?, ?> baseQueryBuilder, Map<String, Object> optionalParameters, boolean renderFetches) {
if (baseQueryBuilder instanceof CTEBuilder) {
CTEBuilder<?> cteBuilder = (CTEBuilder<?>) baseQueryBuilder;
for (CTEProvider cteProvider : getCteProviders()) {
cteProvider.applyCtes(cteBuilder, optionalParameters);
}
}
for (ViewRoot viewRoot : viewRoots) {
String entityViewRootName = viewRoot.getName();
CorrelationProvider correlationProvider = viewRoot.getCorrelationProviderFactory().create(baseQueryBuilder, optionalParameters);
ExpressionFactory expressionFactory = baseQueryBuilder.getService(ExpressionFactory.class);
Limiter limiter = createLimiter(expressionFactory, viewPath, viewRoot.getLimitExpression(), viewRoot.getOffsetExpression(), viewRoot.getOrderByItems());
String correlationAlias;
if (limiter == null) {
correlationAlias = entityViewRootName;
} else {
correlationAlias = "_sub_" + entityViewRootName;
}
JoinCorrelationBuilder correlationBuilder = new JoinCorrelationBuilder(baseQueryBuilder, optionalParameters, baseQueryBuilder, viewPath, correlationAlias, entityViewRootName, null, viewRoot.getJoinType(), limiter);
correlationProvider.applyCorrelation(correlationBuilder, viewPath);
correlationBuilder.finish();
if (renderFetches && baseQueryBuilder instanceof FetchBuilder<?>) {
((FetchBuilder<?>) baseQueryBuilder).fetch(viewRoot.getFetches());
}
}
}
Aggregations