use of org.hibernate.graph.spi.GraphNodeImplementor in project hibernate-orm by hibernate.
the class AbstractEntityGraphVisitationStrategy method startingCollectionIndex.
@Override
public void startingCollectionIndex(final CollectionIndexDefinition indexDefinition) {
AttributeNodeImplementor attributeNode = attributeStack.peekLast();
GraphNodeImplementor subGraphNode = NON_EXIST_SUBGRAPH_NODE;
Map<Class, Subgraph> subGraphs = attributeNode.getKeySubgraphs();
Class javaType = indexDefinition.getType().getReturnedClass();
if (!subGraphs.isEmpty() && subGraphs.containsKey(javaType)) {
subGraphNode = (GraphNodeImplementor) subGraphs.get(javaType);
}
graphStack.addLast(subGraphNode);
super.startingCollectionIndex(indexDefinition);
}
use of org.hibernate.graph.spi.GraphNodeImplementor in project hibernate-orm by hibernate.
the class AbstractEntityGraphVisitationStrategy method foundCircularAssociation.
@Override
public void foundCircularAssociation(AssociationAttributeDefinition attributeDefinition) {
final FetchStrategy fetchStrategy = determineFetchStrategy(attributeDefinition);
if (fetchStrategy.getStyle() != FetchStyle.JOIN) {
// nothing to do
return;
}
// Bi-directional association & the owning side was already visited. If the current attribute node refers
// to it, fetch.
// ENTITY nature handled by super.
final GraphNodeImplementor graphNode = graphStack.peekLast();
if (attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.COLLECTION && !graphNode.equals(NON_EXIST_SUBGRAPH_NODE) && graphNode.containsAttribute(attributeDefinition.getName())) {
currentSource().buildCollectionAttributeFetch(attributeDefinition, fetchStrategy);
}
super.foundCircularAssociation(attributeDefinition);
}
use of org.hibernate.graph.spi.GraphNodeImplementor in project hibernate-orm by hibernate.
the class AbstractEntityGraphVisitationStrategy method startingCollectionElements.
@Override
public void startingCollectionElements(final CollectionElementDefinition elementDefinition) {
AttributeNodeImplementor attributeNode = attributeStack.peekLast();
GraphNodeImplementor subGraphNode = NON_EXIST_SUBGRAPH_NODE;
Map<Class, Subgraph> subGraphs = attributeNode.getSubgraphs();
Class javaType = elementDefinition.getType().getReturnedClass();
if (!subGraphs.isEmpty() && subGraphs.containsKey(javaType)) {
subGraphNode = (GraphNodeImplementor) subGraphs.get(javaType);
}
graphStack.addLast(subGraphNode);
super.startingCollectionElements(elementDefinition);
}
use of org.hibernate.graph.spi.GraphNodeImplementor in project hibernate-orm by hibernate.
the class AbstractEntityGraphVisitationStrategy method buildAttributeNodeMap.
/**
* Build "name" -- "attribute node" map from the current entity graph we're visiting.
*/
protected Map<String, AttributeNodeImplementor> buildAttributeNodeMap() {
GraphNodeImplementor graphNode = graphStack.peekLast();
List<AttributeNodeImplementor<?>> attributeNodeImplementors = graphNode.attributeImplementorNodes();
Map<String, AttributeNodeImplementor> attributeNodeImplementorMap = attributeNodeImplementors.isEmpty() ? Collections.<String, AttributeNodeImplementor>emptyMap() : new HashMap<String, AttributeNodeImplementor>(attributeNodeImplementors.size());
for (AttributeNodeImplementor attribute : attributeNodeImplementors) {
attributeNodeImplementorMap.put(attribute.getAttributeName(), attribute);
}
return attributeNodeImplementorMap;
}
use of org.hibernate.graph.spi.GraphNodeImplementor in project hibernate-orm by hibernate.
the class AbstractEntityGraphVisitationStrategy method startingAttribute.
/**
* I'm using the NULL-OBJECT pattern here.
* For attributes that don't exist in the EntityGraph,
* a predefined NULL-ATTRIBUTE-NODE is pushed to the stack.
*
* And for a nonexistent subgraph, a predefined NULL-SUBGRAPH is pushed to the stack.
*
* So, whenever we start visiting an attribute, there will be an attribute node pushed to the attribute stack,
* and a subgraph node pushed to the graph stack.
*
* when we finish visiting an attribute, these two will be popped from each stack.
*/
@Override
public boolean startingAttribute(AttributeDefinition attributeDefinition) {
Map<String, AttributeNodeImplementor> attributeMap = attributeMapStack.peekLast();
final String attrName = attributeDefinition.getName();
AttributeNodeImplementor attributeNode = NON_EXIST_ATTRIBUTE_NODE;
GraphNodeImplementor subGraphNode = NON_EXIST_SUBGRAPH_NODE;
// the attribute is in the EntityGraph, so, let's continue
if (attributeMap.containsKey(attrName)) {
attributeNode = attributeMap.get(attrName);
// here we need to check if there is a subgraph (or sub key graph if it is an indexed attribute )
Map<Class, Subgraph> subGraphs = attributeNode.getSubgraphs();
Class javaType = attributeDefinition.getType().getReturnedClass();
if (!subGraphs.isEmpty() && subGraphs.containsKey(javaType)) {
subGraphNode = (GraphNodeImplementor) subGraphs.get(javaType);
}
}
attributeStack.addLast(attributeNode);
graphStack.addLast(subGraphNode);
return super.startingAttribute(attributeDefinition);
}
Aggregations