Search in sources :

Example 1 with JaxbBasic

use of org.hibernate.boot.jaxb.mapping.spi.JaxbBasic in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getConvertsForAttribute.

private Annotation getConvertsForAttribute(PropertyMappingElementCollector 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 (JaxbBasic element : elementsForProperty.getBasic()) {
        JaxbConvert convert = element.getConvert();
        if (convert != null) {
            applyXmlDefinedConverts(Collections.singletonList(convert), defaults, null, convertAnnotationsMap);
        }
    }
    for (JaxbEmbedded element : elementsForProperty.getEmbedded()) {
        applyXmlDefinedConverts(element.getConvert(), defaults, propertyName, convertAnnotationsMap);
    }
    for (JaxbElementCollection element : elementsForProperty.getElementCollection()) {
        applyXmlDefinedConverts(element.getConvert(), defaults, propertyName, 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;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Convert(jakarta.persistence.Convert) JaxbConvert(org.hibernate.boot.jaxb.mapping.spi.JaxbConvert) HashMap(java.util.HashMap) JaxbConvert(org.hibernate.boot.jaxb.mapping.spi.JaxbConvert) JaxbEmbedded(org.hibernate.boot.jaxb.mapping.spi.JaxbEmbedded) JaxbElementCollection(org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollection) JaxbBasic(org.hibernate.boot.jaxb.mapping.spi.JaxbBasic)

Example 2 with JaxbBasic

use of org.hibernate.boot.jaxb.mapping.spi.JaxbBasic in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getBasic.

private void getBasic(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (JaxbBasic element : elementsForProperty.getBasic()) {
        Annotation annotation = buildColumns(element.getColumn(), "basic");
        addIfNotNull(annotationList, annotation);
        getAccessType(annotationList, element.getAccess());
        getTemporal(annotationList, element.getTemporal());
        getLob(annotationList, element.getLob());
        getEnumerated(annotationList, element.getEnumerated());
        AnnotationDescriptor basic = new AnnotationDescriptor(Basic.class);
        getFetchType(basic, element.getFetch());
        copyAttribute(basic, "optional", element.isOptional(), false);
        annotationList.add(AnnotationFactory.create(basic));
    }
    if (elementsForProperty.isEmpty() && 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);
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) MapKeyEnumerated(jakarta.persistence.MapKeyEnumerated) Enumerated(jakarta.persistence.Enumerated) AttributeOverrides(jakarta.persistence.AttributeOverrides) AssociationOverrides(jakarta.persistence.AssociationOverrides) AssociationOverride(jakarta.persistence.AssociationOverride) JaxbAssociationOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverride) Temporal(jakarta.persistence.Temporal) MapKeyTemporal(jakarta.persistence.MapKeyTemporal) JaxbPrimaryKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumn) JaxbMapKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyJoinColumn) PrimaryKeyJoinColumn(jakarta.persistence.PrimaryKeyJoinColumn) JaxbMapKeyColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyColumn) JaxbDiscriminatorColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbDiscriminatorColumn) MapKeyColumn(jakarta.persistence.MapKeyColumn) JaxbColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbColumn) MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn) JoinColumn(jakarta.persistence.JoinColumn) OrderColumn(jakarta.persistence.OrderColumn) DiscriminatorColumn(jakarta.persistence.DiscriminatorColumn) JaxbOrderColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbOrderColumn) Column(jakarta.persistence.Column) JaxbJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbJoinColumn) PrimaryKeyJoinColumns(jakarta.persistence.PrimaryKeyJoinColumns) Columns(org.hibernate.annotations.Columns) MapKeyJoinColumns(jakarta.persistence.MapKeyJoinColumns) JoinColumns(jakarta.persistence.JoinColumns) JaxbBasic(org.hibernate.boot.jaxb.mapping.spi.JaxbBasic) Annotation(java.lang.annotation.Annotation) Lob(jakarta.persistence.Lob) JaxbLob(org.hibernate.boot.jaxb.mapping.spi.JaxbLob) JaxbAttributeOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAttributeOverride) AttributeOverride(jakarta.persistence.AttributeOverride)

Aggregations

AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbBasic (org.hibernate.boot.jaxb.mapping.spi.JaxbBasic)2 AssociationOverride (jakarta.persistence.AssociationOverride)1 AssociationOverrides (jakarta.persistence.AssociationOverrides)1 AttributeOverride (jakarta.persistence.AttributeOverride)1 AttributeOverrides (jakarta.persistence.AttributeOverrides)1 Column (jakarta.persistence.Column)1 Convert (jakarta.persistence.Convert)1 DiscriminatorColumn (jakarta.persistence.DiscriminatorColumn)1 Enumerated (jakarta.persistence.Enumerated)1 JoinColumn (jakarta.persistence.JoinColumn)1 JoinColumns (jakarta.persistence.JoinColumns)1 Lob (jakarta.persistence.Lob)1 MapKeyColumn (jakarta.persistence.MapKeyColumn)1 MapKeyEnumerated (jakarta.persistence.MapKeyEnumerated)1 MapKeyJoinColumn (jakarta.persistence.MapKeyJoinColumn)1 MapKeyJoinColumns (jakarta.persistence.MapKeyJoinColumns)1 MapKeyTemporal (jakarta.persistence.MapKeyTemporal)1 OrderColumn (jakarta.persistence.OrderColumn)1 PrimaryKeyJoinColumn (jakarta.persistence.PrimaryKeyJoinColumn)1