use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getConvertsForAttribute.
private Annotation getConvertsForAttribute(List<Element> elementsForProperty, XMLContext.Default defaults) {
// NOTE : we use a map here to make sure that an xml and annotation referring to the same attribute
// properly overrides. Very sparse map, yes, but easy setup.
// todo : revisit this
// although bear in mind that this code is no longer used in 5.0...
final Map<String, Convert> convertAnnotationsMap = new HashMap<>();
for (Element element : elementsForProperty) {
final boolean isBasic = "basic".equals(element.getName());
final boolean isEmbedded = "embedded".equals(element.getName());
final boolean isElementCollection = "element-collection".equals(element.getName());
final boolean canHaveConverts = isBasic || isEmbedded || isElementCollection;
if (!canHaveConverts) {
continue;
}
final String attributeNamePrefix = isBasic ? null : propertyName;
applyXmlDefinedConverts(element, defaults, attributeNamePrefix, convertAnnotationsMap);
}
if (defaults.canUseJavaAnnotations()) {
// todo : note sure how to best handle attributeNamePrefix here
applyPhysicalConvertAnnotations(propertyName, convertAnnotationsMap);
}
if (!convertAnnotationsMap.isEmpty()) {
final AnnotationDescriptor groupingDescriptor = new AnnotationDescriptor(Converts.class);
groupingDescriptor.setValue("value", convertAnnotationsMap.values().toArray(new Convert[convertAnnotationsMap.size()]));
return AnnotationFactory.create(groupingDescriptor);
}
return null;
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getMapKeyJoinColumns.
private MapKeyJoinColumn[] getMapKeyJoinColumns(Element element) {
List<Element> subelements = element != null ? element.elements("map-key-join-column") : null;
List<MapKeyJoinColumn> joinColumns = new ArrayList<>();
if (subelements != null) {
for (Element subelement : subelements) {
AnnotationDescriptor column = new AnnotationDescriptor(MapKeyJoinColumn.class);
copyStringAttribute(column, subelement, "name", false);
copyStringAttribute(column, subelement, "referenced-column-name", false);
copyBooleanAttribute(column, subelement, "unique");
copyBooleanAttribute(column, subelement, "nullable");
copyBooleanAttribute(column, subelement, "insertable");
copyBooleanAttribute(column, subelement, "updatable");
copyStringAttribute(column, subelement, "column-definition", false);
copyStringAttribute(column, subelement, "table", false);
joinColumns.add(AnnotationFactory.create(column));
}
}
return joinColumns.toArray(new MapKeyJoinColumn[joinColumns.size()]);
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildJoinTable.
/*
* no partial overriding possible
*/
private JoinTable buildJoinTable(Element tree, XMLContext.Default defaults) {
Element subelement = tree == null ? null : tree.element("join-table");
final Class<JoinTable> annotationType = JoinTable.class;
if (subelement == null) {
return null;
}
// ignore java annotation, an element is defined
AnnotationDescriptor annotation = new AnnotationDescriptor(annotationType);
copyStringAttribute(annotation, subelement, "name", false);
copyStringAttribute(annotation, subelement, "catalog", false);
if (StringHelper.isNotEmpty(defaults.getCatalog()) && StringHelper.isEmpty((String) annotation.valueOf("catalog"))) {
annotation.setValue("catalog", defaults.getCatalog());
}
copyStringAttribute(annotation, subelement, "schema", false);
if (StringHelper.isNotEmpty(defaults.getSchema()) && StringHelper.isEmpty((String) annotation.valueOf("schema"))) {
annotation.setValue("schema", defaults.getSchema());
}
buildUniqueConstraints(annotation, subelement);
buildIndex(annotation, subelement);
annotation.setValue("joinColumns", getJoinColumns(subelement, false));
annotation.setValue("inverseJoinColumns", getJoinColumns(subelement, true));
return AnnotationFactory.create(annotation);
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getBasic.
private void getBasic(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("basic".equals(element.getName())) {
Annotation annotation = buildColumns(element);
addIfNotNull(annotationList, annotation);
getAccessType(annotationList, element);
getTemporal(annotationList, element);
getLob(annotationList, element);
getEnumerated(annotationList, element);
AnnotationDescriptor basic = new AnnotationDescriptor(Basic.class);
getFetchType(basic, element);
copyBooleanAttribute(basic, element, "optional");
annotationList.add(AnnotationFactory.create(basic));
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
// no annotation presence constraint, basic is the default
Annotation annotation = getPhysicalAnnotation(Basic.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Lob.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Enumerated.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AttributeOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AttributeOverrides.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AssociationOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AssociationOverrides.class);
addIfNotNull(annotationList, annotation);
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getConverts.
private Converts getConverts(Element tree, XMLContext.Default defaults) {
// NOTE : we use a map here to make sure that an xml and annotation referring to the same attribute
// properly overrides. Bit sparse, but easy...
final Map<String, Convert> convertAnnotationsMap = new HashMap<>();
if (tree != null) {
applyXmlDefinedConverts(tree, defaults, null, convertAnnotationsMap);
}
if (defaults.canUseJavaAnnotations()) {
applyPhysicalConvertAnnotations(null, convertAnnotationsMap);
}
if (!convertAnnotationsMap.isEmpty()) {
final AnnotationDescriptor groupingDescriptor = new AnnotationDescriptor(Converts.class);
groupingDescriptor.setValue("value", convertAnnotationsMap.values().toArray(new Convert[convertAnnotationsMap.size()]));
return AnnotationFactory.create(groupingDescriptor);
}
return null;
}
Aggregations