use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildPrimaryKeyJoinColumns.
private PrimaryKeyJoinColumn[] buildPrimaryKeyJoinColumns(Element element) {
if (element == null) {
return new PrimaryKeyJoinColumn[] {};
}
List pkJoinColumnElementList = element.elements("primary-key-join-column");
PrimaryKeyJoinColumn[] pkJoinColumns = new PrimaryKeyJoinColumn[pkJoinColumnElementList.size()];
int index = 0;
Iterator pkIt = pkJoinColumnElementList.listIterator();
while (pkIt.hasNext()) {
Element subelement = (Element) pkIt.next();
AnnotationDescriptor pkAnn = new AnnotationDescriptor(PrimaryKeyJoinColumn.class);
copyStringAttribute(pkAnn, subelement, "name", false);
copyStringAttribute(pkAnn, subelement, "referenced-column-name", false);
copyStringAttribute(pkAnn, subelement, "column-definition", false);
pkJoinColumns[index++] = AnnotationFactory.create(pkAnn);
}
return pkJoinColumns;
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getSqlResultSetMappings.
private SqlResultSetMappings getSqlResultSetMappings(Element tree, XMLContext.Default defaults) {
List<SqlResultSetMapping> results = buildSqlResultsetMappings(tree, defaults, classLoaderAccess);
if (defaults.canUseJavaAnnotations()) {
SqlResultSetMapping annotation = getPhysicalAnnotation(SqlResultSetMapping.class);
addSqlResultsetMappingIfNeeded(annotation, results);
SqlResultSetMappings annotations = getPhysicalAnnotation(SqlResultSetMappings.class);
if (annotations != null) {
for (SqlResultSetMapping current : annotations.value()) {
addSqlResultsetMappingIfNeeded(current, results);
}
}
}
if (results.size() > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(SqlResultSetMappings.class);
ad.setValue("value", results.toArray(new SqlResultSetMapping[results.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 applyXmlDefinedConverts.
private void applyXmlDefinedConverts(Element containingElement, XMLContext.Default defaults, String attributeNamePrefix, Map<String, Convert> convertAnnotationsMap) {
final List<Element> convertElements = containingElement.elements("convert");
for (Element convertElement : convertElements) {
final AnnotationDescriptor convertAnnotationDescriptor = new AnnotationDescriptor(Convert.class);
copyStringAttribute(convertAnnotationDescriptor, convertElement, "attribute-name", false);
copyBooleanAttribute(convertAnnotationDescriptor, convertElement, "disable-conversion");
final Attribute converterClassAttr = convertElement.attribute("converter");
if (converterClassAttr != null) {
final String converterClassName = XMLContext.buildSafeClassName(converterClassAttr.getValue(), defaults);
try {
final Class converterClass = classLoaderAccess.classForName(converterClassName);
convertAnnotationDescriptor.setValue("converter", converterClass);
} catch (ClassLoadingException e) {
throw new AnnotationException("Unable to find specified converter class id-class: " + converterClassName, e);
}
}
final Convert convertAnnotation = AnnotationFactory.create(convertAnnotationDescriptor);
final String qualifiedAttributeName = qualifyConverterAttributeName(attributeNamePrefix, convertAnnotation.attributeName());
convertAnnotationsMap.put(qualifiedAttributeName, convertAnnotation);
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildQueryHints.
private static void buildQueryHints(List<Element> elements, AnnotationDescriptor ann) {
List<QueryHint> queryHints = new ArrayList<>(elements.size());
for (Element hint : elements) {
AnnotationDescriptor hintDescriptor = new AnnotationDescriptor(QueryHint.class);
String value = hint.attributeValue("name");
if (value == null) {
throw new AnnotationException("<hint> without name. " + SCHEMA_VALIDATION);
}
hintDescriptor.setValue("name", value);
value = hint.attributeValue("value");
if (value == null) {
throw new AnnotationException("<hint> without value. " + SCHEMA_VALIDATION);
}
hintDescriptor.setValue("value", value);
queryHints.add(AnnotationFactory.create(hintDescriptor));
}
ann.setValue("hints", queryHints.toArray(new QueryHint[queryHints.size()]));
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildEntityResult.
private static EntityResult buildEntityResult(Element entityResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
final AnnotationDescriptor entityResultDescriptor = new AnnotationDescriptor(EntityResult.class);
final Class entityClass = resolveClassReference(entityResultElement.attributeValue("entity-class"), defaults, classLoaderAccess);
entityResultDescriptor.setValue("entityClass", entityClass);
copyStringAttribute(entityResultDescriptor, entityResultElement, "discriminator-column", false);
// process the <field-result/> sub-elements
List<FieldResult> fieldResultAnnotations = new ArrayList<>();
for (Element fieldResult : (List<Element>) entityResultElement.elements("field-result")) {
AnnotationDescriptor fieldResultDescriptor = new AnnotationDescriptor(FieldResult.class);
copyStringAttribute(fieldResultDescriptor, fieldResult, "name", true);
copyStringAttribute(fieldResultDescriptor, fieldResult, "column", true);
fieldResultAnnotations.add(AnnotationFactory.create(fieldResultDescriptor));
}
entityResultDescriptor.setValue("fields", fieldResultAnnotations.toArray(new FieldResult[fieldResultAnnotations.size()]));
return AnnotationFactory.create(entityResultDescriptor);
}
Aggregations