Search in sources :

Example 1 with SqmMapEntryResult

use of org.hibernate.query.sqm.sql.internal.SqmMapEntryResult in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method visitMapEntryFunction.

@Override
public Object visitMapEntryFunction(SqmMapEntryReference<?, ?> entryRef) {
    final SqmPath<?> mapPath = entryRef.getMapPath();
    prepareReusablePath(mapPath, () -> null);
    final NavigablePath mapNavigablePath = mapPath.getNavigablePath();
    final TableGroup tableGroup = getFromClauseAccess().resolveTableGroup(mapNavigablePath, (navigablePath) -> {
        final TableGroup parentTableGroup = getFromClauseAccess().getTableGroup(mapNavigablePath.getParent());
        final PluralAttributeMapping mapAttribute = (PluralAttributeMapping) parentTableGroup.getModelPart().findSubPart(mapNavigablePath.getLocalName(), null);
        final TableGroupJoin tableGroupJoin = mapAttribute.createTableGroupJoin(mapNavigablePath, parentTableGroup, null, SqlAstJoinType.INNER, false, false, sqlAliasBaseManager, getSqlExpressionResolver(), this, creationContext);
        parentTableGroup.addTableGroupJoin(tableGroupJoin);
        return tableGroupJoin.getJoinedGroup();
    });
    final PluralAttributeMapping mapDescriptor = (PluralAttributeMapping) tableGroup.getModelPart();
    final CollectionPart indexDescriptor = mapDescriptor.getIndexDescriptor();
    final NavigablePath indexNavigablePath = mapNavigablePath.append(indexDescriptor.getPartName());
    final DomainResult<Object> indexResult = indexDescriptor.createDomainResult(indexNavigablePath, tableGroup, null, this);
    final CollectionPart valueDescriptor = mapDescriptor.getElementDescriptor();
    final NavigablePath valueNavigablePath = mapNavigablePath.append(valueDescriptor.getPartName());
    final DomainResult<Object> valueResult = valueDescriptor.createDomainResult(valueNavigablePath, tableGroup, null, this);
    return new DomainResultProducer<Map.Entry<Object, Object>>() {

        @Override
        public DomainResult<Map.Entry<Object, Object>> createDomainResult(String resultVariable, DomainResultCreationState creationState) {
            final JavaType<Map.Entry<Object, Object>> mapEntryDescriptor = getTypeConfiguration().getJavaTypeRegistry().resolveDescriptor(Map.Entry.class);
            return new SqmMapEntryResult<>(indexResult, valueResult, resultVariable, mapEntryDescriptor);
        }

        @Override
        public void applySqlSelections(DomainResultCreationState creationState) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) CorrelatedTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedTableGroup) CorrelatedPluralTableGroup(org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup) PluralTableGroup(org.hibernate.sql.ast.tree.from.PluralTableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) DomainResultProducer(org.hibernate.query.sqm.sql.internal.DomainResultProducer) SqmMapEntryResult(org.hibernate.query.sqm.sql.internal.SqmMapEntryResult) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) EmbeddedCollectionPart(org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap)

Aggregations

AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CollectionPart (org.hibernate.metamodel.mapping.CollectionPart)1 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)1 EmbeddedCollectionPart (org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart)1 EntityCollectionPart (org.hibernate.metamodel.mapping.internal.EntityCollectionPart)1 NavigablePath (org.hibernate.query.spi.NavigablePath)1 DomainResultProducer (org.hibernate.query.sqm.sql.internal.DomainResultProducer)1 SqmMapEntryResult (org.hibernate.query.sqm.sql.internal.SqmMapEntryResult)1 CorrelatedPluralTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup)1 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)1 LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)1 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)1 QueryPartTableGroup (org.hibernate.sql.ast.tree.from.QueryPartTableGroup)1 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)1 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)1 VirtualTableGroup (org.hibernate.sql.ast.tree.from.VirtualTableGroup)1