// Check for an existing entity graph and throw an exception if there is one.
if (getProject().hasEntityGraph(entityGraphName)) {
throw new IllegalStateException(ExceptionLocalization.buildMessage("named_entity_graph_exists", new Object[]{ entityGraphName, entityAccessor.getJavaClassName()}));
} else {
AttributeGroup entityGraph = new AttributeGroup(entityGraphName, entityAccessor.getJavaClassName(), true);
Map<String, Map<String, AttributeGroup>> attributeGraphs = new HashMap<String, Map<String, AttributeGroup>>();
// Process the subgraph metadata (build attribute graphs for each).
for (NamedSubgraphMetadata subgraph : getSubgraphs()) {
subgraph.process(attributeGraphs);
}
// Process the include all attributes flag.
if (includeAllAttributes()) {
for (MappingAccessor accessor : entityAccessor.getDescriptor().getMappingAccessors()) {
entityGraph.addAttribute(accessor.getAttributeName());
}
}
// Process the attribute nodes.
for (NamedAttributeNodeMetadata attributeNode : getNamedAttributeNodes()) {
attributeNode.process(attributeGraphs, entityGraph, entityGraph);
}
// Process the subgraphs attribute nodes (into the groups built previously).
for (NamedSubgraphMetadata subgraph : getSubgraphs()) {
subgraph.processAttributeNodes(attributeGraphs, attributeGraphs.get(subgraph.getName()).get(subgraph.getTypeClassName()), entityGraph);
}
for (NamedSubgraphMetadata subclassSubgraph : getSubclassSubgraphs()){
AttributeGroup group = new AttributeGroup(subclassSubgraph.getName(), subclassSubgraph.getTypeClassName(), true);
subclassSubgraph.processAttributeNodes(attributeGraphs, group, entityGraph);
entityGraph.getSubClassGroups().put(group.getTypeName(), group);
}
// Finally, add the entity graph to the project.
getProject().addEntityGraph(entityGraph);
}