Search in sources :

Example 1 with TupleElementMapper

use of com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper in project blaze-persistence by Blazebit.

the class ViewTypeObjectBuilderTemplate method applyCollectionFunctionMapping.

private void applyCollectionFunctionMapping(BasicUserTypeStringSupport<?> basicUserTypeStringSupport, MappingAttribute<? super T, ?> mappingAttribute, String attributePath, TupleElementMapperBuilder mapperBuilder, String[] fetches, EmbeddingViewJpqlMacro embeddingViewJpqlMacro) {
    String expression = "VALUE(" + mapperBuilder.getMapping(mappingAttribute) + ")";
    String alias = mapperBuilder.getAlias(mappingAttribute, false);
    TupleElementMapper mapper = createMapper(basicUserTypeStringSupport, expression, alias, attributePath, mapperBuilder.getMapping(), embeddingViewJpqlMacro.getEmbeddingViewPath(), fetches);
    mapperBuilder.addMapper(mapper);
}
Also used : ParameterizedSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedSubqueryTupleElementMapper) TupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper) ParameterizedExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionSubqueryTupleElementMapper) MultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.MultisetTupleElementMapper) AliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionSubqueryTupleElementMapper) ParameterizedExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionCorrelationJoinTupleElementMapper) ParameterizedAliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper) ParameterizedAliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasSubqueryTupleElementMapper) ExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionSubqueryTupleElementMapper) ExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionTupleElementMapper) CorrelationMultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.CorrelationMultisetTupleElementMapper) SimpleSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.SimpleSubqueryTupleElementMapper) ExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionCorrelationJoinTupleElementMapper) AliasExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionTupleElementMapper) AliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasSubqueryTupleElementMapper) ConstrainedTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ConstrainedTupleElementMapper)

Example 2 with TupleElementMapper

use of com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper in project blaze-persistence by Blazebit.

the class ViewTypeObjectBuilderTemplate method applySubqueryMapping.

private void applySubqueryMapping(SubqueryAttribute<?, ?> attribute, String attributePath, TupleElementMapperBuilder mapperBuilder, EmbeddingViewJpqlMacro embeddingViewJpqlMacro) {
    SubqueryProviderFactory factory = attribute.getSubqueryProviderFactory();
    String alias = mapperBuilder.getAlias(attribute, false);
    String subqueryAlias = attribute.getSubqueryAlias();
    String viewPath = mapperBuilder.getMapping();
    String subqueryExpression = attribute.getSubqueryExpression();
    TupleElementMapper mapper;
    if (subqueryExpression.isEmpty()) {
        if (alias != null) {
            if (factory.isParameterized()) {
                mapper = new ParameterizedAliasSubqueryTupleElementMapper(attribute.getType(), factory, attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath(), alias);
            } else {
                mapper = new AliasSubqueryTupleElementMapper(attribute.getType(), factory.create(null, null), attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath(), alias);
            }
        } else {
            if (factory.isParameterized()) {
                mapper = new ParameterizedSubqueryTupleElementMapper(attribute.getType(), factory, attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath());
            } else {
                mapper = new SimpleSubqueryTupleElementMapper(attribute.getType(), factory.create(null, null), attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath());
            }
        }
    } else {
        subqueryExpression = mapperBuilder.getMapping(attribute);
        if (alias != null) {
            if (factory.isParameterized()) {
                mapper = new ParameterizedAliasExpressionSubqueryTupleElementMapper(attribute.getType(), factory, subqueryExpression, subqueryAlias, attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath(), alias);
            } else {
                mapper = new AliasExpressionSubqueryTupleElementMapper(attribute.getType(), factory.create(null, null), subqueryExpression, subqueryAlias, attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath(), alias);
            }
        } else {
            if (factory.isParameterized()) {
                mapper = new ParameterizedExpressionSubqueryTupleElementMapper(attribute.getType(), factory, subqueryExpression, subqueryAlias, attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath());
            } else {
                mapper = new ExpressionSubqueryTupleElementMapper(attribute.getType(), factory.create(null, null), subqueryExpression, subqueryAlias, attributePath, viewPath, embeddingViewJpqlMacro.getEmbeddingViewPath());
            }
        }
    }
    mapperBuilder.addMapper(mapper);
}
Also used : ParameterizedExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionSubqueryTupleElementMapper) AliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionSubqueryTupleElementMapper) ParameterizedAliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper) ExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionSubqueryTupleElementMapper) SubqueryProviderFactory(com.blazebit.persistence.view.SubqueryProviderFactory) ParameterizedAliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasSubqueryTupleElementMapper) ParameterizedAliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasSubqueryTupleElementMapper) AliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasSubqueryTupleElementMapper) ParameterizedSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedSubqueryTupleElementMapper) TupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper) ParameterizedExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionSubqueryTupleElementMapper) MultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.MultisetTupleElementMapper) AliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionSubqueryTupleElementMapper) ParameterizedExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionCorrelationJoinTupleElementMapper) ParameterizedAliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper) ParameterizedAliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasSubqueryTupleElementMapper) ExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionSubqueryTupleElementMapper) ExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionTupleElementMapper) CorrelationMultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.CorrelationMultisetTupleElementMapper) SimpleSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.SimpleSubqueryTupleElementMapper) ExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionCorrelationJoinTupleElementMapper) AliasExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionTupleElementMapper) AliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasSubqueryTupleElementMapper) ConstrainedTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ConstrainedTupleElementMapper) SimpleSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.SimpleSubqueryTupleElementMapper) ParameterizedAliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper) ParameterizedExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionSubqueryTupleElementMapper) AliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionSubqueryTupleElementMapper) ParameterizedAliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper) ParameterizedSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedSubqueryTupleElementMapper)

Example 3 with TupleElementMapper

use of com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper in project blaze-persistence by Blazebit.

the class ViewTypeObjectBuilderTemplate method applyIndexCollectionFunctionMapping.

private void applyIndexCollectionFunctionMapping(BasicUserTypeStringSupport<?> basicUserTypeStringSupport, MappingAttribute<? super T, ?> mappingAttribute, String attributePath, TupleElementMapperBuilder mapperBuilder, EmbeddingViewJpqlMacro embeddingViewJpqlMacro) {
    String expression;
    String[] fetches = EMPTY;
    if (mappingAttribute instanceof MapAttribute<?, ?, ?>) {
        expression = mapperBuilder.getKeyMapping((MapAttribute<?, ?, ?>) mappingAttribute);
        fetches = ((MapAttribute<?, ?, ?>) mappingAttribute).getKeyFetches();
    } else {
        expression = mapperBuilder.getIndexMapping((ListAttribute<?, ?>) mappingAttribute);
    }
    String alias = mapperBuilder.getAlias(mappingAttribute, true);
    TupleElementMapper mapper = createMapper(basicUserTypeStringSupport, expression, alias, attributePath, mapperBuilder.getMapping(), embeddingViewJpqlMacro.getEmbeddingViewPath(), fetches);
    mapperBuilder.addMapper(mapper);
}
Also used : MapAttribute(com.blazebit.persistence.view.metamodel.MapAttribute) ParameterizedSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedSubqueryTupleElementMapper) TupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper) ParameterizedExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionSubqueryTupleElementMapper) MultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.MultisetTupleElementMapper) AliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionSubqueryTupleElementMapper) ParameterizedExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionCorrelationJoinTupleElementMapper) ParameterizedAliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper) ParameterizedAliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasSubqueryTupleElementMapper) ExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionSubqueryTupleElementMapper) ExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionTupleElementMapper) CorrelationMultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.CorrelationMultisetTupleElementMapper) SimpleSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.SimpleSubqueryTupleElementMapper) ExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionCorrelationJoinTupleElementMapper) AliasExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionTupleElementMapper) AliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasSubqueryTupleElementMapper) ConstrainedTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ConstrainedTupleElementMapper) ListAttribute(com.blazebit.persistence.view.metamodel.ListAttribute)

Example 4 with TupleElementMapper

use of com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper in project blaze-persistence by Blazebit.

the class ViewTypeObjectBuilderTemplate method applyBasicCorrelatedMapping.

private void applyBasicCorrelatedMapping(AbstractAttribute<?, ?> attribute, String attributePath, TupleElementMapperBuilder mapperBuilder, Set<Feature> features, ExpressionFactory ef, int batchSize, boolean dirtyTracking, EmbeddingViewJpqlMacro embeddingViewJpqlMacro) {
    Expression correlationResult = attribute.getCorrelationResultExpression();
    CorrelationProviderFactory factory = attribute.getCorrelationProviderFactory();
    String correlationBasis = attribute.getCorrelationBasis();
    String correlationAlias = CorrelationProviderHelper.getDefaultCorrelationAlias(attributePath);
    if (attribute.getFetchStrategy() == FetchStrategy.JOIN) {
        String alias = mapperBuilder.getAlias(attribute, false);
        correlationBasis = mapperBuilder.getMapping(attribute.getCorrelationBasisExpression());
        TupleElementMapper mapper;
        String joinBase = mapperBuilder.getMapping();
        String joinCorrelationAttributePath = mapperBuilder.getJoinCorrelationAttributePath(attributePath);
        String embeddingViewPath = joinBase;
        if (factory.isParameterized()) {
            mapper = new ParameterizedExpressionCorrelationJoinTupleElementMapper(factory, ef, joinBase, correlationBasis, attribute.getCorrelationResultExpression(), alias, joinCorrelationAttributePath, embeddingViewPath, attribute.getFetches(), createLimiter(mapperBuilder, correlationAlias, attribute), viewRoot.getEntityViewRootTypes().keySet());
        } else {
            mapper = new ExpressionCorrelationJoinTupleElementMapper(factory.create(null, null), ef, joinBase, correlationBasis, attribute.getCorrelationResultExpression(), alias, joinCorrelationAttributePath, embeddingViewPath, attribute.getFetches(), createLimiter(mapperBuilder, correlationAlias, attribute), viewRoot.getEntityViewRootTypes().keySet());
        }
        mapperBuilder.addMapper(mapper);
    } else if (attribute.getFetchStrategy() == FetchStrategy.SELECT) {
        String subviewAliasPrefix = mapperBuilder.getAlias(attribute, false);
        int viewRootIndex = viewRoot.hasSubtypes() ? 1 : 0;
        int embeddingViewIndex = tupleOffset;
        int startIndex = tupleOffset + mapperBuilder.mapperIndex();
        Class<?> correlationBasisType = getCorrelationBasisType(attribute.getCorrelationBasisExpression(), AbstractAttribute.stripThisFromMapping(correlationBasis), attribute.getDeclaringType().getEntityViewRootTypes());
        Class<?> correlationBasisEntity = getCorrelationBasisEntityType(correlationBasisType);
        String correlationBasisExpression = AbstractAttribute.stripThisFromMapping(correlationBasis);
        String correlationKeyExpression = mapperBuilder.getMapping(attribute.getCorrelationBasisExpression(), correlationBasisEntity);
        String embeddingViewPath = mapperBuilder.getMapping();
        boolean correlatesThis = correlatesThis(evm, ef, managedTypeClass, attribute.getCorrelated(), correlationBasisExpression, attribute.getCorrelationPredicate(), attribute.getCorrelationKeyAlias());
        BasicUserTypeStringSupport<Object> correlationKeyExpressionBasicTypeType = getCorrelationKeyExpressionBasicTypeSupport(correlationBasisType, correlationBasisEntity);
        mapperBuilder.addMapper(createMapper(correlationKeyExpressionBasicTypeType, correlationKeyExpression, subviewAliasPrefix, attributePath, embeddingViewPath, embeddingViewJpqlMacro.getEmbeddingViewPath(), attribute.getFetches()));
        // We need a special mapping for the VIEW_ROOT/EMBEDDING_VIEW macro in certain cases
        viewRootIndex = addViewRootMappingIfNeeded(mapperBuilder, features, subviewAliasPrefix, attributePath, viewRootIndex);
        embeddingViewIndex = addEmbeddingViewMappingIfNeeded(mapperBuilder, features, subviewAliasPrefix, attributePath, embeddingViewIndex);
        if (batchSize == -1) {
            batchSize = 1;
        }
        if (attribute.isCollection()) {
            PluralAttribute<?, ?, ?> pluralAttribute = (PluralAttribute<?, ?, ?>) attribute;
            String[] indexFetches = EMPTY;
            Expression indexExpression = null;
            Correlator indexCorrelator = null;
            switch(pluralAttribute.getCollectionType()) {
                case COLLECTION:
                    if (pluralAttribute.isSorted()) {
                        throw new IllegalArgumentException("The collection attribute '" + pluralAttribute + "' can not be sorted!");
                    }
                    break;
                case LIST:
                    if (pluralAttribute.isSorted()) {
                        throw new IllegalArgumentException("The list attribute '" + pluralAttribute + "' can not be sorted!");
                    }
                    indexExpression = attribute.getMappingIndexExpression();
                    indexCorrelator = indexExpression == null ? null : new BasicCorrelator();
                    break;
                case SET:
                    break;
                case MAP:
                    MapAttribute<?, ?, ?> mapAttribute = (MapAttribute<?, ?, ?>) attribute;
                    indexExpression = attribute.getKeyMappingExpression();
                    indexFetches = mapAttribute.getKeyFetches();
                    if (mapAttribute.isKeySubview()) {
                        indexCorrelator = new SubviewCorrelator((ManagedViewTypeImplementor<?>) mapAttribute.getKeyType(), null, evm, subviewAliasPrefix, attributePath);
                    } else {
                        indexCorrelator = new BasicCorrelator();
                    }
                    mapperBuilder.addTupleListTransformerFactory(new CorrelatedMapBatchTupleListTransformerFactory(new BasicCorrelator(), viewRoot, viewType, correlationResult, factory, attributePath, attribute.getFetches(), correlatesThis, viewRootIndex, embeddingViewIndex, startIndex, batchSize, correlationBasisType, correlationBasisEntity, createLimiter(mapperBuilder, correlationAlias, attribute), indexFetches, indexExpression, indexCorrelator, attribute.getContainerAccumulator(), dirtyTracking));
                    return;
                default:
                    throw new IllegalArgumentException("Unknown collection type: " + pluralAttribute.getCollectionType());
            }
            mapperBuilder.addTupleListTransformerFactory(new CorrelatedCollectionBatchTupleListTransformerFactory(new BasicCorrelator(), viewRoot, viewType, correlationResult, factory, attributePath, attribute.getFetches(), correlatesThis, viewRootIndex, embeddingViewIndex, startIndex, batchSize, correlationBasisType, correlationBasisEntity, createLimiter(mapperBuilder, correlationAlias, attribute), indexFetches, indexExpression, indexCorrelator, attribute.getContainerAccumulator(), dirtyTracking));
        } else {
            mapperBuilder.addTupleListTransformerFactory(new CorrelatedSingularBatchTupleListTransformerFactory(new BasicCorrelator(), viewRoot, viewType, correlationResult, factory, attributePath, attribute.getFetches(), correlatesThis, viewRootIndex, embeddingViewIndex, startIndex, batchSize, correlationBasisType, correlationBasisEntity, createLimiter(mapperBuilder, correlationAlias, attribute)));
        }
    } else if (attribute.getFetchStrategy() == FetchStrategy.SUBSELECT) {
        String subviewAliasPrefix = mapperBuilder.getAlias(attribute, false);
        int viewRootIndex = viewRoot.hasSubtypes() ? 1 : 0;
        int embeddingViewIndex = tupleOffset;
        int startIndex = tupleOffset + mapperBuilder.mapperIndex();
        Class<?> correlationBasisType = getCorrelationBasisType(attribute.getCorrelationBasisExpression(), AbstractAttribute.stripThisFromMapping(correlationBasis), attribute.getDeclaringType().getEntityViewRootTypes());
        Class<?> correlationBasisEntity = getCorrelationBasisEntityType(correlationBasisType);
        String correlationBasisExpression = mapperBuilder.getMapping(attribute.getCorrelationBasisExpression());
        String correlationKeyExpression = mapperBuilder.getMapping(attribute.getCorrelationBasisExpression(), correlationBasisEntity);
        BasicUserTypeStringSupport<Object> correlationKeyExpressionBasicTypeType = getCorrelationKeyExpressionBasicTypeSupport(correlationBasisType, correlationBasisEntity);
        String embeddingViewPath = mapperBuilder.getMapping();
        mapperBuilder.addMapper(createMapper(correlationKeyExpressionBasicTypeType, correlationKeyExpression, subviewAliasPrefix, attributePath, embeddingViewPath, embeddingViewJpqlMacro.getEmbeddingViewPath(), attribute.getFetches()));
        if (attribute.isCollection()) {
            PluralAttribute<?, ?, ?> pluralAttribute = (PluralAttribute<?, ?, ?>) attribute;
            String[] indexFetches = EMPTY;
            Expression indexExpression = null;
            Correlator indexCorrelator = null;
            switch(pluralAttribute.getCollectionType()) {
                case COLLECTION:
                    if (pluralAttribute.isSorted()) {
                        throw new IllegalArgumentException("The collection attribute '" + pluralAttribute + "' can not be sorted!");
                    }
                    break;
                case LIST:
                    if (pluralAttribute.isSorted()) {
                        throw new IllegalArgumentException("The list attribute '" + pluralAttribute + "' can not be sorted!");
                    }
                    indexExpression = attribute.getMappingIndexExpression();
                    indexCorrelator = indexExpression == null ? null : new BasicCorrelator();
                    break;
                case SET:
                    break;
                case MAP:
                    MapAttribute<?, ?, ?> mapAttribute = (MapAttribute<?, ?, ?>) attribute;
                    indexExpression = attribute.getKeyMappingExpression();
                    indexFetches = mapAttribute.getKeyFetches();
                    if (mapAttribute.isKeySubview()) {
                        indexCorrelator = new SubviewCorrelator((ManagedViewTypeImplementor<?>) mapAttribute.getKeyType(), null, evm, subviewAliasPrefix, attributePath);
                    } else {
                        indexCorrelator = new BasicCorrelator();
                    }
                    mapperBuilder.addTupleTransformerFactory(new CorrelatedMapSubselectTupleTransformerFactory(new BasicCorrelator(), evm, viewRoot, viewRootAlias, viewType, embeddingViewPath, correlationResult, correlationBasisExpression, correlationKeyExpression, factory, attributePath, attribute.getFetches(), viewRootIndex, embeddingViewIndex, startIndex, correlationBasisType, correlationBasisEntity, createLimiter(mapperBuilder, correlationAlias, attribute), indexFetches, indexExpression, indexCorrelator, attribute.getContainerAccumulator(), dirtyTracking));
                    return;
                default:
                    throw new IllegalArgumentException("Unknown collection type: " + pluralAttribute.getCollectionType());
            }
            mapperBuilder.addTupleTransformerFactory(new CorrelatedCollectionSubselectTupleTransformerFactory(new BasicCorrelator(), evm, viewRoot, viewRootAlias, viewType, embeddingViewPath, correlationResult, correlationBasisExpression, correlationKeyExpression, factory, attributePath, attribute.getFetches(), viewRootIndex, embeddingViewIndex, startIndex, correlationBasisType, correlationBasisEntity, createLimiter(mapperBuilder, correlationAlias, attribute), indexFetches, indexExpression, indexCorrelator, attribute.getContainerAccumulator(), dirtyTracking));
        } else {
            mapperBuilder.addTupleTransformerFactory(new CorrelatedSingularSubselectTupleTransformerFactory(new BasicCorrelator(), evm, viewRoot, viewRootAlias, viewType, embeddingViewPath, correlationResult, correlationBasisExpression, correlationKeyExpression, factory, attributePath, attribute.getFetches(), viewRootIndex, embeddingViewIndex, startIndex, correlationBasisType, correlationBasisEntity, createLimiter(mapperBuilder, correlationAlias, attribute)));
        }
    } else {
        throw new UnsupportedOperationException("Unknown fetch strategy: " + attribute.getFetchStrategy());
    }
}
Also used : ParameterizedExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionCorrelationJoinTupleElementMapper) ExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionCorrelationJoinTupleElementMapper) CorrelatedMapBatchTupleListTransformerFactory(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.CorrelatedMapBatchTupleListTransformerFactory) SubviewCorrelator(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.SubviewCorrelator) CorrelatedSingularSubselectTupleTransformerFactory(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.CorrelatedSingularSubselectTupleTransformerFactory) CorrelationProviderFactory(com.blazebit.persistence.view.CorrelationProviderFactory) ParameterizedExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionCorrelationJoinTupleElementMapper) Correlator(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.Correlator) SubviewCorrelator(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.SubviewCorrelator) BasicCorrelator(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.BasicCorrelator) PluralAttribute(com.blazebit.persistence.view.metamodel.PluralAttribute) CorrelatedSingularBatchTupleListTransformerFactory(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.CorrelatedSingularBatchTupleListTransformerFactory) BasicUserTypeStringSupport(com.blazebit.persistence.view.spi.type.BasicUserTypeStringSupport) CorrelatedCollectionBatchTupleListTransformerFactory(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.CorrelatedCollectionBatchTupleListTransformerFactory) ManagedViewTypeImplementor(com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImplementor) MapAttribute(com.blazebit.persistence.view.metamodel.MapAttribute) Expression(com.blazebit.persistence.parser.expression.Expression) CorrelatedMapSubselectTupleTransformerFactory(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.CorrelatedMapSubselectTupleTransformerFactory) CorrelatedCollectionSubselectTupleTransformerFactory(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.CorrelatedCollectionSubselectTupleTransformerFactory) BasicCorrelator(com.blazebit.persistence.view.impl.objectbuilder.transformer.correlation.BasicCorrelator) ParameterizedSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedSubqueryTupleElementMapper) TupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper) ParameterizedExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionSubqueryTupleElementMapper) MultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.MultisetTupleElementMapper) AliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionSubqueryTupleElementMapper) ParameterizedExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionCorrelationJoinTupleElementMapper) ParameterizedAliasExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper) ParameterizedAliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasSubqueryTupleElementMapper) ExpressionSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionSubqueryTupleElementMapper) ExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionTupleElementMapper) CorrelationMultisetTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.CorrelationMultisetTupleElementMapper) SimpleSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.SimpleSubqueryTupleElementMapper) ExpressionCorrelationJoinTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionCorrelationJoinTupleElementMapper) AliasExpressionTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionTupleElementMapper) AliasSubqueryTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasSubqueryTupleElementMapper) ConstrainedTupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.ConstrainedTupleElementMapper)

Example 5 with TupleElementMapper

use of com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper in project blaze-persistence by Blazebit.

the class ViewTypeObjectBuilder method applySelects.

@Override
public <X extends SelectBuilder<X>> void applySelects(X queryBuilder) {
    if (fetches.isEmpty()) {
        if (secondaryMappers.length != 0) {
            FullQueryBuilder<?, ?> fullQueryBuilder = (FullQueryBuilder<?, ?>) queryBuilder;
            for (SecondaryMapper viewRoot : secondaryMappers) {
                viewRoot.apply(fullQueryBuilder, parameterHolder, optionalParameters, viewJpqlMacro, embeddingViewJpqlMacro);
            }
        }
        for (int i = 0; i < mappers.length; i++) {
            mappers[i].applyMapping(queryBuilder, parameterHolder, optionalParameters, viewJpqlMacro, embeddingViewJpqlMacro, false);
        }
    } else {
        if (secondaryMappers.length != 0) {
            FullQueryBuilder<?, ?> fullQueryBuilder = (FullQueryBuilder<?, ?>) queryBuilder;
            for (SecondaryMapper viewRoot : secondaryMappers) {
                if (fetches.contains(viewRoot.getAttributePath())) {
                    viewRoot.apply(fullQueryBuilder, parameterHolder, optionalParameters, viewJpqlMacro, embeddingViewJpqlMacro);
                }
            }
        }
        for (int i = 0; i < mappers.length; i++) {
            TupleElementMapper mapper = mappers[i];
            String attributePath = mapper.getAttributePath();
            if (attributePath != null && fetches.contains(attributePath)) {
                mapper.applyMapping(queryBuilder, parameterHolder, optionalParameters, viewJpqlMacro, embeddingViewJpqlMacro, false);
            } else {
                queryBuilder.select("NULL");
            }
        }
    }
}
Also used : FullQueryBuilder(com.blazebit.persistence.FullQueryBuilder) TupleElementMapper(com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper)

Aggregations

TupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.TupleElementMapper)5 AliasExpressionSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionSubqueryTupleElementMapper)4 AliasExpressionTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasExpressionTupleElementMapper)4 AliasSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.AliasSubqueryTupleElementMapper)4 ConstrainedTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ConstrainedTupleElementMapper)4 CorrelationMultisetTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.CorrelationMultisetTupleElementMapper)4 ExpressionCorrelationJoinTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionCorrelationJoinTupleElementMapper)4 ExpressionSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionSubqueryTupleElementMapper)4 ExpressionTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ExpressionTupleElementMapper)4 MultisetTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.MultisetTupleElementMapper)4 ParameterizedAliasExpressionSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasExpressionSubqueryTupleElementMapper)4 ParameterizedAliasSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedAliasSubqueryTupleElementMapper)4 ParameterizedExpressionCorrelationJoinTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionCorrelationJoinTupleElementMapper)4 ParameterizedExpressionSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedExpressionSubqueryTupleElementMapper)4 ParameterizedSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.ParameterizedSubqueryTupleElementMapper)4 SimpleSubqueryTupleElementMapper (com.blazebit.persistence.view.impl.objectbuilder.mapper.SimpleSubqueryTupleElementMapper)4 MapAttribute (com.blazebit.persistence.view.metamodel.MapAttribute)2 FullQueryBuilder (com.blazebit.persistence.FullQueryBuilder)1 Expression (com.blazebit.persistence.parser.expression.Expression)1 CorrelationProviderFactory (com.blazebit.persistence.view.CorrelationProviderFactory)1