Search in sources :

Example 1 with GraphImplementor

use of org.hibernate.graph.spi.GraphImplementor in project hibernate-orm by hibernate.

the class StandardEntityGraphTraversalStateImpl method traverse.

@Override
public TraversalResult traverse(FetchParent fetchParent, Fetchable fetchable, boolean exploreKeySubgraph) {
    assert !(fetchable instanceof CollectionPart);
    final GraphImplementor previousContextRoot = currentGraphContext;
    AttributeNodeImplementor attributeNode = null;
    if (appliesTo(fetchParent)) {
        attributeNode = currentGraphContext.findAttributeNode(fetchable.getFetchableName());
    }
    currentGraphContext = null;
    FetchTiming fetchTiming = null;
    boolean joined = false;
    if (attributeNode != null) {
        fetchTiming = FetchTiming.IMMEDIATE;
        joined = true;
        final Map<Class<?>, SubGraphImplementor> subgraphMap;
        final Class<?> subgraphMapKey;
        if (fetchable instanceof PluralAttributeMapping) {
            PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
            assert exploreKeySubgraph && isJpaMapCollectionType(pluralAttributeMapping) || !exploreKeySubgraph && !isJpaMapCollectionType(pluralAttributeMapping);
            if (exploreKeySubgraph) {
                subgraphMap = attributeNode.getKeySubGraphMap();
                subgraphMapKey = getEntityCollectionPartJavaClass(pluralAttributeMapping.getIndexDescriptor());
            } else {
                subgraphMap = attributeNode.getSubGraphMap();
                subgraphMapKey = getEntityCollectionPartJavaClass(pluralAttributeMapping.getElementDescriptor());
            }
        } else {
            assert !exploreKeySubgraph;
            subgraphMap = attributeNode.getSubGraphMap();
            subgraphMapKey = fetchable.getJavaType().getJavaTypeClass();
        }
        if (subgraphMap != null && subgraphMapKey != null) {
            currentGraphContext = subgraphMap.get(subgraphMapKey);
        }
    }
    if (fetchTiming == null) {
        if (graphSemantic == GraphSemantic.FETCH) {
            fetchTiming = FetchTiming.DELAYED;
            joined = false;
        } else {
            fetchTiming = fetchable.getMappedFetchOptions().getTiming();
            joined = fetchable.getMappedFetchOptions().getStyle() == FetchStyle.JOIN;
        }
    }
    return new TraversalResult(previousContextRoot, fetchTiming, joined);
}
Also used : AttributeNodeImplementor(org.hibernate.graph.spi.AttributeNodeImplementor) FetchTiming(org.hibernate.engine.FetchTiming) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EntityCollectionPart(org.hibernate.metamodel.mapping.internal.EntityCollectionPart) CollectionPart(org.hibernate.metamodel.mapping.CollectionPart) RootGraphImplementor(org.hibernate.graph.spi.RootGraphImplementor) GraphImplementor(org.hibernate.graph.spi.GraphImplementor) SubGraphImplementor(org.hibernate.graph.spi.SubGraphImplementor) SubGraphImplementor(org.hibernate.graph.spi.SubGraphImplementor)

Aggregations

FetchTiming (org.hibernate.engine.FetchTiming)1 AttributeNodeImplementor (org.hibernate.graph.spi.AttributeNodeImplementor)1 GraphImplementor (org.hibernate.graph.spi.GraphImplementor)1 RootGraphImplementor (org.hibernate.graph.spi.RootGraphImplementor)1 SubGraphImplementor (org.hibernate.graph.spi.SubGraphImplementor)1 CollectionPart (org.hibernate.metamodel.mapping.CollectionPart)1 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)1 EntityCollectionPart (org.hibernate.metamodel.mapping.internal.EntityCollectionPart)1