Search in sources :

Example 1 with NamedEntityGraph

use of jakarta.persistence.NamedEntityGraph in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method buildNamedEntityGraph.

public static List<NamedEntityGraph> buildNamedEntityGraph(List<JaxbNamedEntityGraph> elements, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    List<NamedEntityGraph> namedEntityGraphList = new ArrayList<>();
    for (JaxbNamedEntityGraph element : elements) {
        AnnotationDescriptor ann = new AnnotationDescriptor(NamedEntityGraph.class);
        copyAttribute(ann, "name", element.getName(), false);
        copyAttribute(ann, "include-all-attributes", element.isIncludeAllAttributes(), false);
        bindNamedAttributeNodes(element.getNamedAttributeNode(), ann);
        bindNamedSubgraph(defaults, ann, "subgraphs", element.getSubgraph(), classLoaderAccess);
        bindNamedSubgraph(defaults, ann, "subclassSubgraphs", element.getSubclassSubgraph(), classLoaderAccess);
        namedEntityGraphList.add(AnnotationFactory.create(ann));
    }
    // TODO
    return namedEntityGraphList;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbNamedEntityGraph(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedEntityGraph) NamedEntityGraph(jakarta.persistence.NamedEntityGraph) JaxbNamedEntityGraph(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedEntityGraph) ArrayList(java.util.ArrayList)

Example 2 with NamedEntityGraph

use of jakarta.persistence.NamedEntityGraph in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getNamedEntityGraphs.

private NamedEntityGraphs getNamedEntityGraphs(ManagedType root, XMLContext.Default defaults) {
    List<NamedEntityGraph> queries = root instanceof JaxbEntity ? buildNamedEntityGraph(((JaxbEntity) root).getNamedEntityGraph(), defaults, classLoaderAccess) : new ArrayList<>();
    if (defaults.canUseJavaAnnotations()) {
        NamedEntityGraph annotation = getPhysicalAnnotation(NamedEntityGraph.class);
        addNamedEntityGraphIfNeeded(annotation, queries);
        NamedEntityGraphs annotations = getPhysicalAnnotation(NamedEntityGraphs.class);
        if (annotations != null) {
            for (NamedEntityGraph current : annotations.value()) {
                addNamedEntityGraphIfNeeded(current, queries);
            }
        }
    }
    if (queries.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(NamedEntityGraphs.class);
        ad.setValue("value", queries.toArray(new NamedEntityGraph[queries.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedEntityGraphs(jakarta.persistence.NamedEntityGraphs) NamedEntityGraph(jakarta.persistence.NamedEntityGraph) JaxbNamedEntityGraph(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedEntityGraph) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Example 3 with NamedEntityGraph

use of jakarta.persistence.NamedEntityGraph in project hibernate-orm by hibernate.

the class JpaMetamodelImpl method applyNamedEntityGraphs.

@SuppressWarnings("unchecked")
private void applyNamedEntityGraphs(Collection<NamedEntityGraphDefinition> namedEntityGraphs) {
    for (NamedEntityGraphDefinition definition : namedEntityGraphs) {
        log.debugf("Applying named entity graph [name=%s, entity-name=%s, jpa-entity-name=%s]", definition.getRegisteredName(), definition.getEntityName(), definition.getJpaEntityName());
        final EntityDomainType<Object> entityType = entity(definition.getEntityName());
        if (entityType == null) {
            throw new IllegalArgumentException("Attempted to register named entity graph [" + definition.getRegisteredName() + "] for unknown entity [" + definition.getEntityName() + "]");
        }
        final RootGraphImpl<Object> entityGraph = new RootGraphImpl<>(definition.getRegisteredName(), entityType, this);
        final NamedEntityGraph namedEntityGraph = definition.getAnnotation();
        if (namedEntityGraph.includeAllAttributes()) {
            for (Attribute<? super Object, ?> attribute : entityType.getAttributes()) {
                entityGraph.addAttributeNodes(attribute);
            }
        }
        if (namedEntityGraph.attributeNodes() != null) {
            applyNamedAttributeNodes(namedEntityGraph.attributeNodes(), namedEntityGraph, entityGraph);
        }
        entityGraphMap.put(definition.getRegisteredName(), entityGraph);
    }
}
Also used : NamedEntityGraphDefinition(org.hibernate.cfg.annotations.NamedEntityGraphDefinition) NamedEntityGraph(jakarta.persistence.NamedEntityGraph) RootGraphImpl(org.hibernate.graph.internal.RootGraphImpl)

Example 4 with NamedEntityGraph

use of jakarta.persistence.NamedEntityGraph in project hibernate-orm by hibernate.

the class EntityBinder method processNamedEntityGraphs.

private void processNamedEntityGraphs() {
    processNamedEntityGraph(annotatedClass.getAnnotation(NamedEntityGraph.class));
    final NamedEntityGraphs graphs = annotatedClass.getAnnotation(NamedEntityGraphs.class);
    if (graphs != null) {
        for (NamedEntityGraph graph : graphs.value()) {
            processNamedEntityGraph(graph);
        }
    }
}
Also used : NamedEntityGraphs(jakarta.persistence.NamedEntityGraphs) NamedEntityGraph(jakarta.persistence.NamedEntityGraph)

Example 5 with NamedEntityGraph

use of jakarta.persistence.NamedEntityGraph in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method addNamedEntityGraphIfNeeded.

private void addNamedEntityGraphIfNeeded(NamedEntityGraph annotation, List<NamedEntityGraph> queries) {
    if (annotation != null) {
        String queryName = annotation.name();
        boolean present = false;
        for (NamedEntityGraph current : queries) {
            if (current.name().equals(queryName)) {
                present = true;
                break;
            }
        }
        if (!present) {
            queries.add(annotation);
        }
    }
}
Also used : NamedEntityGraph(jakarta.persistence.NamedEntityGraph) JaxbNamedEntityGraph(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedEntityGraph)

Aggregations

NamedEntityGraph (jakarta.persistence.NamedEntityGraph)5 JaxbNamedEntityGraph (org.hibernate.boot.jaxb.mapping.spi.JaxbNamedEntityGraph)3 NamedEntityGraphs (jakarta.persistence.NamedEntityGraphs)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 ArrayList (java.util.ArrayList)1 JaxbEntity (org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)1 NamedEntityGraphDefinition (org.hibernate.cfg.annotations.NamedEntityGraphDefinition)1 RootGraphImpl (org.hibernate.graph.internal.RootGraphImpl)1