Search in sources :

Example 1 with NamedQueries

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

the class JPAXMLOverriddenAnnotationReader method getNamedQueries.

private NamedQueries getNamedQueries(ManagedType root, XMLContext.Default defaults) {
    // TODO avoid the Proxy Creation (@NamedQueries) when possible
    List<NamedQuery> queries = root instanceof JaxbEntity ? buildNamedQueries(((JaxbEntity) root).getNamedQuery(), defaults, classLoaderAccess) : new ArrayList<>();
    if (defaults.canUseJavaAnnotations()) {
        NamedQuery annotation = getPhysicalAnnotation(NamedQuery.class);
        addNamedQueryIfNeeded(annotation, queries);
        NamedQueries annotations = getPhysicalAnnotation(NamedQueries.class);
        if (annotations != null) {
            for (NamedQuery current : annotations.value()) {
                addNamedQueryIfNeeded(current, queries);
            }
        }
    }
    if (queries.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(NamedQueries.class);
        ad.setValue("value", queries.toArray(new NamedQuery[queries.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedQueries(jakarta.persistence.NamedQueries) NamedQuery(jakarta.persistence.NamedQuery) JaxbNamedQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQuery) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Example 2 with NamedQueries

use of jakarta.persistence.NamedQueries in project eclipselink by eclipse-ee4j.

the class JavaEntity method buildQueries.

protected Map<String, IQuery> buildQueries() {
    Map<String, IQuery> queries = new HashMap<>();
    try {
        Class<?> type = getType().getType();
        Annotation[] annotations = type.getAnnotations();
        NamedQueries namedQueries = getAnnotation(annotations, NamedQueries.class);
        if (namedQueries != null) {
            for (NamedQuery namedQuery : namedQueries.value()) {
                IQuery query = buildQuery(namedQuery);
                queries.put(namedQuery.name(), query);
            }
        } else {
            NamedQuery namedQuery = getAnnotation(annotations, NamedQuery.class);
            if (namedQuery != null) {
                IQuery query = buildQuery(namedQuery);
                queries.put(namedQuery.name(), query);
            }
        }
    } catch (Exception e) {
    // Ignore
    }
    return queries;
}
Also used : IQuery(org.eclipse.persistence.jpa.jpql.tools.spi.IQuery) HashMap(java.util.HashMap) NamedQueries(jakarta.persistence.NamedQueries) NamedQuery(jakarta.persistence.NamedQuery) Annotation(java.lang.annotation.Annotation)

Aggregations

NamedQueries (jakarta.persistence.NamedQueries)2 NamedQuery (jakarta.persistence.NamedQuery)2 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 IQuery (org.eclipse.persistence.jpa.jpql.tools.spi.IQuery)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 JaxbEntity (org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)1 JaxbNamedQuery (org.hibernate.boot.jaxb.mapping.spi.JaxbNamedQuery)1