Search in sources :

Example 1 with StoredProcedureParameter

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

the class JPAOverriddenAnnotationReader method buildNamedStoreProcedureQueries.

public static List<NamedStoredProcedureQuery> buildNamedStoreProcedureQueries(Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    if (element == null) {
        return new ArrayList<>();
    }
    List namedStoredProcedureElements = element.elements("named-stored-procedure-query");
    List<NamedStoredProcedureQuery> namedStoredProcedureQueries = new ArrayList<>();
    for (Object obj : namedStoredProcedureElements) {
        Element subElement = (Element) obj;
        AnnotationDescriptor ann = new AnnotationDescriptor(NamedStoredProcedureQuery.class);
        copyStringAttribute(ann, subElement, "name", true);
        copyStringAttribute(ann, subElement, "procedure-name", true);
        List<Element> elements = subElement.elements("parameter");
        List<StoredProcedureParameter> storedProcedureParameters = new ArrayList<>();
        for (Element parameterElement : elements) {
            AnnotationDescriptor parameterDescriptor = new AnnotationDescriptor(StoredProcedureParameter.class);
            copyStringAttribute(parameterDescriptor, parameterElement, "name", false);
            String modeValue = parameterElement.attributeValue("mode");
            if (modeValue == null) {
                parameterDescriptor.setValue("mode", ParameterMode.IN);
            } else {
                parameterDescriptor.setValue("mode", ParameterMode.valueOf(modeValue.toUpperCase(Locale.ROOT)));
            }
            String clazzName = parameterElement.attributeValue("class");
            Class clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
            }
            parameterDescriptor.setValue("type", clazz);
            storedProcedureParameters.add(AnnotationFactory.create(parameterDescriptor));
        }
        ann.setValue("parameters", storedProcedureParameters.toArray(new StoredProcedureParameter[storedProcedureParameters.size()]));
        elements = subElement.elements("result-class");
        List<Class> returnClasses = new ArrayList<>();
        for (Element classElement : elements) {
            String clazzName = classElement.getTextTrim();
            Class clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
            }
            returnClasses.add(clazz);
        }
        ann.setValue("resultClasses", returnClasses.toArray(new Class[returnClasses.size()]));
        elements = subElement.elements("result-set-mapping");
        List<String> resultSetMappings = new ArrayList<>();
        for (Element resultSetMappingElement : elements) {
            resultSetMappings.add(resultSetMappingElement.getTextTrim());
        }
        ann.setValue("resultSetMappings", resultSetMappings.toArray(new String[resultSetMappings.size()]));
        elements = subElement.elements("hint");
        buildQueryHints(elements, ann);
        namedStoredProcedureQueries.add(AnnotationFactory.create(ann));
    }
    return namedStoredProcedureQueries;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) StoredProcedureParameter(javax.persistence.StoredProcedureParameter) 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) NamedStoredProcedureQuery(javax.persistence.NamedStoredProcedureQuery)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IdClass (javax.persistence.IdClass)1 MapKeyClass (javax.persistence.MapKeyClass)1 NamedStoredProcedureQuery (javax.persistence.NamedStoredProcedureQuery)1 StoredProcedureParameter (javax.persistence.StoredProcedureParameter)1 Element (org.dom4j.Element)1 AnnotationException (org.hibernate.AnnotationException)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1