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");
}
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));
}
});
}
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);
}
Aggregations