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