Search in sources :

Example 1 with NamedEntityGraph

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

the class JPAOverriddenAnnotationReader 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(javax.persistence.NamedEntityGraph)

Example 2 with NamedEntityGraph

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

the class JPAOverriddenAnnotationReader method getNamedEntityGraphs.

private NamedEntityGraphs getNamedEntityGraphs(Element tree, XMLContext.Default defaults) {
    List<NamedEntityGraph> queries = buildNamedEntityGraph(tree, defaults, classLoaderAccess);
    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(javax.persistence.NamedEntityGraphs) NamedEntityGraph(javax.persistence.NamedEntityGraph)

Example 3 with NamedEntityGraph

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

the class MetamodelImpl method applyNamedEntityGraphs.

@SuppressWarnings("unchecked")
private void applyNamedEntityGraphs(java.util.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 EntityType entityType = entity(definition.getEntityName());
        if (entityType == null) {
            throw new IllegalArgumentException("Attempted to register named entity graph [" + definition.getRegisteredName() + "] for unknown entity [" + definition.getEntityName() + "]");
        }
        final EntityGraphImpl entityGraph = new EntityGraphImpl(definition.getRegisteredName(), entityType, this.getSessionFactory());
        final NamedEntityGraph namedEntityGraph = definition.getAnnotation();
        if (namedEntityGraph.includeAllAttributes()) {
            for (Object attributeObject : entityType.getAttributes()) {
                entityGraph.addAttributeNodes((Attribute) attributeObject);
            }
        }
        if (namedEntityGraph.attributeNodes() != null) {
            applyNamedAttributeNodes(namedEntityGraph.attributeNodes(), namedEntityGraph, entityGraph);
        }
        entityGraphMap.put(definition.getRegisteredName(), entityGraph);
    }
}
Also used : NamedEntityGraphDefinition(org.hibernate.cfg.annotations.NamedEntityGraphDefinition) EntityType(javax.persistence.metamodel.EntityType) EntityGraphImpl(org.hibernate.jpa.graph.internal.EntityGraphImpl) NamedEntityGraph(javax.persistence.NamedEntityGraph)

Example 4 with NamedEntityGraph

use of javax.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(javax.persistence.NamedEntityGraphs) NamedEntityGraph(javax.persistence.NamedEntityGraph)

Example 5 with NamedEntityGraph

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

the class JPAOverriddenAnnotationReader method buildNamedEntityGraph.

public static List<NamedEntityGraph> buildNamedEntityGraph(Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    if (element == null) {
        return new ArrayList<>();
    }
    List<NamedEntityGraph> namedEntityGraphList = new ArrayList<>();
    List<Element> namedEntityGraphElements = element.elements("named-entity-graph");
    for (Element subElement : namedEntityGraphElements) {
        AnnotationDescriptor ann = new AnnotationDescriptor(NamedEntityGraph.class);
        copyStringAttribute(ann, subElement, "name", false);
        copyBooleanAttribute(ann, subElement, "include-all-attributes");
        bindNamedAttributeNodes(subElement, ann);
        List<Element> subgraphNodes = subElement.elements("subgraph");
        List<Element> subclassSubgraphNodes = subElement.elements("subclass-subgraph");
        if (!subclassSubgraphNodes.isEmpty()) {
            subgraphNodes.addAll(subclassSubgraphNodes);
        }
        bindNamedSubgraph(defaults, ann, subgraphNodes, classLoaderAccess);
        namedEntityGraphList.add(AnnotationFactory.create(ann));
    }
    // TODO
    return namedEntityGraphList;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedEntityGraph(javax.persistence.NamedEntityGraph) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Aggregations

NamedEntityGraph (javax.persistence.NamedEntityGraph)5 NamedEntityGraphs (javax.persistence.NamedEntityGraphs)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 ArrayList (java.util.ArrayList)1 EntityType (javax.persistence.metamodel.EntityType)1 Element (org.dom4j.Element)1 NamedEntityGraphDefinition (org.hibernate.cfg.annotations.NamedEntityGraphDefinition)1 EntityGraphImpl (org.hibernate.jpa.graph.internal.EntityGraphImpl)1