Search in sources :

Example 11 with AnnotationDescriptor

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;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Convert(javax.persistence.Convert) HashMap(java.util.HashMap) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element)

Example 12 with AnnotationDescriptor

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()]);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Example 13 with AnnotationDescriptor

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);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) JoinTable(javax.persistence.JoinTable)

Example 14 with AnnotationDescriptor

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);
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Enumerated(javax.persistence.Enumerated) MapKeyEnumerated(javax.persistence.MapKeyEnumerated) AttributeOverrides(javax.persistence.AttributeOverrides) AssociationOverrides(javax.persistence.AssociationOverrides) AssociationOverride(javax.persistence.AssociationOverride) MapKeyTemporal(javax.persistence.MapKeyTemporal) Temporal(javax.persistence.Temporal) MapKeyColumn(javax.persistence.MapKeyColumn) OrderColumn(javax.persistence.OrderColumn) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) Column(javax.persistence.Column) DiscriminatorColumn(javax.persistence.DiscriminatorColumn) JoinColumn(javax.persistence.JoinColumn) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) MapKeyJoinColumns(javax.persistence.MapKeyJoinColumns) Columns(org.hibernate.annotations.Columns) JoinColumns(javax.persistence.JoinColumns) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns) Annotation(java.lang.annotation.Annotation) Lob(javax.persistence.Lob) AttributeOverride(javax.persistence.AttributeOverride)

Example 15 with AnnotationDescriptor

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;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Convert(javax.persistence.Convert) HashMap(java.util.HashMap)

Aggregations

AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)70 AnnotatedElement (java.lang.reflect.AnnotatedElement)46 Element (org.dom4j.Element)46 ArrayList (java.util.ArrayList)23 AnnotationException (org.hibernate.AnnotationException)15 MapKeyJoinColumn (javax.persistence.MapKeyJoinColumn)13 PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)13 List (java.util.List)11 JoinColumn (javax.persistence.JoinColumn)11 MapKeyClass (javax.persistence.MapKeyClass)10 IdClass (javax.persistence.IdClass)9 Annotation (java.lang.annotation.Annotation)8 AttributeOverride (javax.persistence.AttributeOverride)8 DiscriminatorColumn (javax.persistence.DiscriminatorColumn)8 AssociationOverride (javax.persistence.AssociationOverride)7 Column (javax.persistence.Column)7 MapKeyColumn (javax.persistence.MapKeyColumn)7 OrderColumn (javax.persistence.OrderColumn)7 PrimaryKeyJoinColumns (javax.persistence.PrimaryKeyJoinColumns)7 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)7