Search in sources :

Example 1 with ParameterMode

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

the class JPAXMLOverriddenAnnotationReader method buildNamedStoreProcedureQueries.

public static List<NamedStoredProcedureQuery> buildNamedStoreProcedureQueries(List<JaxbNamedStoredProcedureQuery> elements, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    List<NamedStoredProcedureQuery> namedStoredProcedureQueries = new ArrayList<>();
    for (JaxbNamedStoredProcedureQuery element : elements) {
        AnnotationDescriptor ann = new AnnotationDescriptor(NamedStoredProcedureQuery.class);
        copyAttribute(ann, "name", element.getName(), true);
        copyAttribute(ann, "procedure-name", element.getProcedureName(), true);
        List<StoredProcedureParameter> storedProcedureParameters = new ArrayList<>();
        for (JaxbStoredProcedureParameter parameterElement : element.getParameter()) {
            AnnotationDescriptor parameterDescriptor = new AnnotationDescriptor(StoredProcedureParameter.class);
            copyAttribute(parameterDescriptor, "name", parameterElement.getName(), false);
            ParameterMode modeValue = parameterElement.getMode();
            if (modeValue == null) {
                parameterDescriptor.setValue("mode", ParameterMode.IN);
            } else {
                parameterDescriptor.setValue("mode", modeValue);
            }
            String clazzName = parameterElement.getClazz();
            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()]));
        List<Class<?>> returnClasses = new ArrayList<>();
        for (String clazzName : element.getResultClass()) {
            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()]));
        ann.setValue("resultSetMappings", element.getResultSetMapping().toArray(new String[0]));
        buildQueryHints(element.getHint(), 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) ArrayList(java.util.ArrayList) JaxbStoredProcedureParameter(org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameter) JaxbStoredProcedureParameter(org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameter) StoredProcedureParameter(jakarta.persistence.StoredProcedureParameter) ParameterMode(jakarta.persistence.ParameterMode) AnnotationException(org.hibernate.AnnotationException) IdClass(jakarta.persistence.IdClass) MapKeyClass(jakarta.persistence.MapKeyClass) JaxbIdClass(org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass) JaxbMapKeyClass(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyClass) JaxbNamedStoredProcedureQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery) JaxbNamedStoredProcedureQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery)

Aggregations

IdClass (jakarta.persistence.IdClass)1 MapKeyClass (jakarta.persistence.MapKeyClass)1 NamedStoredProcedureQuery (jakarta.persistence.NamedStoredProcedureQuery)1 ParameterMode (jakarta.persistence.ParameterMode)1 StoredProcedureParameter (jakarta.persistence.StoredProcedureParameter)1 ArrayList (java.util.ArrayList)1 AnnotationException (org.hibernate.AnnotationException)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 JaxbIdClass (org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass)1 JaxbMapKeyClass (org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyClass)1 JaxbNamedStoredProcedureQuery (org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery)1 JaxbStoredProcedureParameter (org.hibernate.boot.jaxb.mapping.spi.JaxbStoredProcedureParameter)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1