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;
}
Aggregations