Search in sources :

Example 31 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method buildNamedQueries.

public static List buildNamedQueries(Element element, boolean isNative, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    if (element == null) {
        return new ArrayList();
    }
    List namedQueryElementList = isNative ? element.elements("named-native-query") : element.elements("named-query");
    List namedQueries = new ArrayList();
    for (Object aNamedQueryElementList : namedQueryElementList) {
        Element subelement = (Element) aNamedQueryElementList;
        AnnotationDescriptor ann = new AnnotationDescriptor(isNative ? NamedNativeQuery.class : NamedQuery.class);
        copyStringAttribute(ann, subelement, "name", false);
        Element queryElt = subelement.element("query");
        if (queryElt == null) {
            throw new AnnotationException("No <query> element found." + SCHEMA_VALIDATION);
        }
        copyStringElement(queryElt, ann, "query");
        List<Element> elements = subelement.elements("hint");
        buildQueryHints(elements, ann);
        String clazzName = subelement.attributeValue("result-class");
        if (StringHelper.isNotEmpty(clazzName)) {
            Class clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
            }
            ann.setValue("resultClass", clazz);
        }
        copyStringAttribute(ann, subelement, "result-set-mapping", false);
        namedQueries.add(AnnotationFactory.create(ann));
    }
    return namedQueries;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedNativeQuery(javax.persistence.NamedNativeQuery) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) AnnotationException(org.hibernate.AnnotationException) ArrayList(java.util.ArrayList) List(java.util.List) AccessibleObject(java.lang.reflect.AccessibleObject) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass) NamedQuery(javax.persistence.NamedQuery)

Example 32 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method buildMapKeyJoinColumns.

private void buildMapKeyJoinColumns(List<Annotation> annotationList, Element element) {
    MapKeyJoinColumn[] joinColumns = getMapKeyJoinColumns(element);
    if (joinColumns.length > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyJoinColumns.class);
        ad.setValue("value", joinColumns);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn)

Example 33 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getNamedNativeQueries.

private NamedNativeQueries getNamedNativeQueries(Element tree, XMLContext.Default defaults) {
    List<NamedNativeQuery> queries = (List<NamedNativeQuery>) buildNamedQueries(tree, true, defaults, classLoaderAccess);
    if (defaults.canUseJavaAnnotations()) {
        NamedNativeQuery annotation = getPhysicalAnnotation(NamedNativeQuery.class);
        addNamedNativeQueryIfNeeded(annotation, queries);
        NamedNativeQueries annotations = getPhysicalAnnotation(NamedNativeQueries.class);
        if (annotations != null) {
            for (NamedNativeQuery current : annotations.value()) {
                addNamedNativeQueryIfNeeded(current, queries);
            }
        }
    }
    if (queries.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(NamedNativeQueries.class);
        ad.setValue("value", queries.toArray(new NamedNativeQuery[queries.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedNativeQuery(javax.persistence.NamedNativeQuery) NamedNativeQueries(javax.persistence.NamedNativeQueries) ArrayList(java.util.ArrayList) List(java.util.List)

Example 34 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor 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 35 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getIdClass.

private IdClass getIdClass(Element tree, XMLContext.Default defaults) {
    Element element = tree == null ? null : tree.element("id-class");
    if (element != null) {
        Attribute attr = element.attribute("class");
        if (attr != null) {
            AnnotationDescriptor ad = new AnnotationDescriptor(IdClass.class);
            Class clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(attr.getValue(), defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find id-class: " + attr.getValue(), e);
            }
            ad.setValue("value", clazz);
            return AnnotationFactory.create(ad);
        } else {
            throw new AnnotationException("id-class without class. " + SCHEMA_VALIDATION);
        }
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(IdClass.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) IdClass(javax.persistence.IdClass) Attribute(org.dom4j.Attribute) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) AnnotationException(org.hibernate.AnnotationException) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass)

Aggregations

AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)70 AnnotatedElement (java.lang.reflect.AnnotatedElement)46 Element (org.dom4j.Element)46 ArrayList (java.util.ArrayList)23 AnnotationException (org.hibernate.AnnotationException)15 MapKeyJoinColumn (javax.persistence.MapKeyJoinColumn)13 PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)13 List (java.util.List)11 JoinColumn (javax.persistence.JoinColumn)11 MapKeyClass (javax.persistence.MapKeyClass)10 IdClass (javax.persistence.IdClass)9 Annotation (java.lang.annotation.Annotation)8 AttributeOverride (javax.persistence.AttributeOverride)8 DiscriminatorColumn (javax.persistence.DiscriminatorColumn)8 AssociationOverride (javax.persistence.AssociationOverride)7 Column (javax.persistence.Column)7 MapKeyColumn (javax.persistence.MapKeyColumn)7 OrderColumn (javax.persistence.OrderColumn)7 PrimaryKeyJoinColumns (javax.persistence.PrimaryKeyJoinColumns)7 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)7