use of com.blazebit.persistence.view.impl.objectbuilder.transformer.NullTupleTransformer in project blaze-persistence by Blazebit.
the class CorrelatedSubviewJoinTupleTransformerFactory method create.
@Override
public TupleTransformer create(ParameterHolder<?> parameterHolder, Map<String, Object> optionalParameters, EntityViewConfiguration entityViewConfiguration) {
if (!entityViewConfiguration.hasSubFetches(attributePath)) {
return new NullTupleTransformer(template);
}
// For now it's ok, but at some point we will want to support correlated attributes somehow and need to think of a fallback solution here
if (parameterHolder instanceof FullQueryBuilder<?, ?>) {
FullQueryBuilder<?, ?> queryBuilder = (FullQueryBuilder<?, ?>) parameterHolder;
CorrelationProvider provider = correlationProviderFactory.create(parameterHolder, optionalParameters);
JoinCorrelationBuilder correlationBuilder = new JoinCorrelationBuilder(parameterHolder, optionalParameters, queryBuilder, joinBase, correlationAlias, correlationExternalAlias, attributePath, JoinType.LEFT, limiter);
int originalFirstResult = -1;
int originalMaxResults = -1;
if (queryBuilder instanceof LimitBuilder<?>) {
originalFirstResult = ((LimitBuilder<?>) queryBuilder).getFirstResult();
originalMaxResults = ((LimitBuilder<?>) queryBuilder).getMaxResults();
}
ViewJpqlMacro viewJpqlMacro = entityViewConfiguration.getViewJpqlMacro();
EmbeddingViewJpqlMacro embeddingViewJpqlMacro = entityViewConfiguration.getEmbeddingViewJpqlMacro();
String oldViewPath = viewJpqlMacro.getViewPath();
String oldEmbeddingViewPath = embeddingViewJpqlMacro.getEmbeddingViewPath();
// If this uses a static path, we need to avoid setting the embedding view path etc.
if (!(provider instanceof StaticPathCorrelationProvider)) {
viewJpqlMacro.setViewPath(correlationBuilder.getCorrelationAlias());
embeddingViewJpqlMacro.setEmbeddingViewPath(embeddingViewPath);
}
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();
if (!(provider instanceof StaticPathCorrelationProvider)) {
viewJpqlMacro.setViewPath(oldViewPath);
embeddingViewJpqlMacro.setEmbeddingViewPath(oldEmbeddingViewPath);
}
if (fetches.length != 0) {
for (int i = 0; i < fetches.length; i++) {
queryBuilder.fetch(correlationBuilder.getCorrelationAlias() + "." + fetches[i]);
}
}
ObjectBuilder<Object[]> objectBuilder = template.createObjectBuilder(parameterHolder, optionalParameters, entityViewConfiguration, 0, true, false);
return new CorrelatedSubviewJoinTupleTransformer(template, objectBuilder);
} else {
throw new UnsupportedOperationException("Converting views with correlated attributes isn't supported!");
}
}
Aggregations