Search in sources :

Example 1 with SubGraphImplementor

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

the class EntityGraphParserTest method testLinkSubtypeParsing.

@Test
public void testLinkSubtypeParsing() {
    RootGraphImplementor<GraphParsingTestEntity> graph = parseGraph("linkToOne(name, description), linkToOne(GraphParsingTestSubEntity: sub)");
    assertNotNull(graph);
    List<AttributeNodeImplementor<?>> attrs = graph.getAttributeNodeImplementors();
    assertNotNull(attrs);
    assertEquals(1, attrs.size());
    AttributeNodeImplementor<?> linkToOneNode = attrs.get(0);
    assertNotNull(linkToOneNode);
    assertEquals("linkToOne", linkToOneNode.getAttributeName());
    assertNullOrEmpty(linkToOneNode.getKeySubgraphs());
    final SubGraphImplementor subGraph = linkToOneNode.getSubGraphMap().get(GraphParsingTestSubEntity.class);
    assertNotNull(subGraph);
    assertBasicAttributes(subGraph, "sub");
}
Also used : AttributeNodeImplementor(org.hibernate.graph.spi.AttributeNodeImplementor) SubGraphImplementor(org.hibernate.graph.spi.SubGraphImplementor) Test(org.junit.Test)

Example 2 with SubGraphImplementor

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

the class AttributeNodeImpl method merge.

@Override
@SuppressWarnings("unchecked")
public void merge(AttributeNodeImplementor<?> attributeNode) {
    attributeNode.visitSubGraphs((incomingSubType, incomingGraph) -> {
        SubGraphImplementor existing = null;
        if (subGraphMap == null) {
            subGraphMap = new HashMap<>();
        } else {
            existing = subGraphMap.get(incomingSubType);
        }
        if (existing != null) {
            existing.merge(incomingGraph);
        } else {
            internalAddSubGraph((Class) incomingSubType, (SubGraphImplementor) incomingGraph.makeCopy(true));
        }
    });
    attributeNode.visitKeySubGraphs((incomingSubType, incomingGraph) -> {
        SubGraphImplementor existing = null;
        if (keySubGraphMap == null) {
            keySubGraphMap = new HashMap<>();
        } else {
            existing = keySubGraphMap.get(incomingSubType);
        }
        if (existing != null) {
            existing.merge(incomingGraph);
        } else {
            internalAddKeySubGraph((Class) incomingSubType, (SubGraphImplementor) incomingGraph.makeCopy(true));
        }
    });
}
Also used : SubGraphImplementor(org.hibernate.graph.spi.SubGraphImplementor)

Example 3 with SubGraphImplementor

use of org.hibernate.graph.spi.SubGraphImplementor 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

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