Search in sources :

Example 16 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getMapKeyEnumerated.

/**
 * Adds a @MapKeyEnumerated annotation to the specified annotationList if the specified element
 * contains a map-key-enumerated sub-element. This should only be the case for
 * element-collection, many-to-many, or one-to-many associations.
 */
private void getMapKeyEnumerated(List<Annotation> annotationList, Element element) {
    Element subelement = element != null ? element.element("map-key-enumerated") : null;
    if (subelement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyEnumerated.class);
        EnumType value = EnumType.valueOf(subelement.getTextTrim());
        ad.setValue("value", value);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) EnumType(javax.persistence.EnumType) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element)

Example 17 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getId.

private void getId(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (Element element : elementsForProperty) {
        if ("id".equals(element.getName())) {
            boolean processId = isProcessingId(defaults);
            if (processId) {
                Annotation annotation = buildColumns(element);
                addIfNotNull(annotationList, annotation);
                annotation = buildGeneratedValue(element);
                addIfNotNull(annotationList, annotation);
                getTemporal(annotationList, element);
                // FIXME: fix the priority of xml over java for generator names
                annotation = getTableGenerator(element, defaults);
                addIfNotNull(annotationList, annotation);
                annotation = getSequenceGenerator(element, defaults);
                addIfNotNull(annotationList, annotation);
                AnnotationDescriptor id = new AnnotationDescriptor(Id.class);
                annotationList.add(AnnotationFactory.create(id));
                getAccessType(annotationList, element);
            }
        }
    }
    if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
        Annotation annotation = getPhysicalAnnotation(Id.class);
        if (annotation != null) {
            annotationList.add(annotation);
            annotation = getPhysicalAnnotation(Column.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(Columns.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(GeneratedValue.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(Temporal.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(TableGenerator.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(SequenceGenerator.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) AssociationOverride(javax.persistence.AssociationOverride) SequenceGenerator(javax.persistence.SequenceGenerator) 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) TableGenerator(javax.persistence.TableGenerator) Annotation(java.lang.annotation.Annotation) AttributeOverride(javax.persistence.AttributeOverride) GeneratedValue(javax.persistence.GeneratedValue) AttributeOverrides(javax.persistence.AttributeOverrides) AssociationOverrides(javax.persistence.AssociationOverrides) 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)

Example 18 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getMapsId.

/**
 * Adds a @MapsId annotation to the specified annotationList if the specified element has the
 * maps-id attribute set. This should only be the case for many-to-one or one-to-one
 * associations.
 */
private void getMapsId(List<Annotation> annotationList, Element element) {
    String attrVal = element.attributeValue("maps-id");
    if (attrVal != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(MapsId.class);
        ad.setValue("value", attrVal);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)

Example 19 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getEntity.

private Entity getEntity(Element tree, XMLContext.Default defaults) {
    if (tree == null) {
        return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation(Entity.class) : null;
    } else {
        if ("entity".equals(tree.getName())) {
            AnnotationDescriptor entity = new AnnotationDescriptor(Entity.class);
            copyStringAttribute(entity, tree, "name", false);
            if (defaults.canUseJavaAnnotations() && StringHelper.isEmpty((String) entity.valueOf("name"))) {
                Entity javaAnn = getPhysicalAnnotation(Entity.class);
                if (javaAnn != null) {
                    entity.setValue("name", javaAnn.name());
                }
            }
            return AnnotationFactory.create(entity);
        } else {
            // this is not an entity
            return null;
        }
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Entity(javax.persistence.Entity)

Example 20 with AnnotationDescriptor

use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getAssociationOverrides.

/**
 * @param mergeWithAnnotations Whether to use Java annotations for this
 * element, if present and not disabled by the XMLContext defaults.
 * In some contexts (such as an element-collection mapping) merging
 * with annotations is never allowed.
 */
private AssociationOverrides getAssociationOverrides(Element tree, XMLContext.Default defaults, boolean mergeWithAnnotations) {
    List<AssociationOverride> attributes = buildAssociationOverrides(tree, defaults);
    if (mergeWithAnnotations && defaults.canUseJavaAnnotations()) {
        AssociationOverride annotation = getPhysicalAnnotation(AssociationOverride.class);
        addAssociationOverrideIfNeeded(annotation, attributes);
        AssociationOverrides annotations = getPhysicalAnnotation(AssociationOverrides.class);
        if (annotations != null) {
            for (AssociationOverride current : annotations.value()) {
                addAssociationOverrideIfNeeded(current, attributes);
            }
        }
    }
    if (attributes.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(AssociationOverrides.class);
        ad.setValue("value", attributes.toArray(new AssociationOverride[attributes.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AssociationOverrides(javax.persistence.AssociationOverrides) AssociationOverride(javax.persistence.AssociationOverride)

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