Search in sources :

Example 41 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getMapKeyClass.

private void getMapKeyClass(List<Annotation> annotationList, Element element, XMLContext.Default defaults) {
    String nodeName = "map-key-class";
    Element subelement = element != null ? element.element(nodeName) : null;
    if (subelement != null) {
        String mapKeyClassName = subelement.attributeValue("class");
        AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyClass.class);
        if (StringHelper.isNotEmpty(mapKeyClassName)) {
            Class clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(mapKeyClassName, defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find " + element.getPath() + " " + nodeName + ": " + mapKeyClassName, e);
            }
            ad.setValue("value", clazz);
        }
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) AnnotationException(org.hibernate.AnnotationException) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass)

Example 42 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildGeneratedValue.

private GeneratedValue buildGeneratedValue(Element element) {
    Element subElement = element != null ? element.element("generated-value") : null;
    if (subElement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(GeneratedValue.class);
        String strategy = subElement.attributeValue("strategy");
        if ("TABLE".equalsIgnoreCase(strategy)) {
            ad.setValue("strategy", GenerationType.TABLE);
        } else if ("SEQUENCE".equalsIgnoreCase(strategy)) {
            ad.setValue("strategy", GenerationType.SEQUENCE);
        } else if ("IDENTITY".equalsIgnoreCase(strategy)) {
            ad.setValue("strategy", GenerationType.IDENTITY);
        } else if ("AUTO".equalsIgnoreCase(strategy)) {
            ad.setValue("strategy", GenerationType.AUTO);
        } else if (StringHelper.isNotEmpty(strategy)) {
            throw new AnnotationException("Unknown GenerationType: " + strategy + ". " + SCHEMA_VALIDATION);
        }
        copyStringAttribute(ad, subElement, "generator", false);
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) AnnotationException(org.hibernate.AnnotationException)

Example 43 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getDiscriminatorValue.

private DiscriminatorValue getDiscriminatorValue(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element("discriminator-value") : null;
    if (element != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(DiscriminatorValue.class);
        copyStringElement(element, ad, "value");
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(DiscriminatorValue.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) DiscriminatorValue(javax.persistence.DiscriminatorValue)

Example 44 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getEmbedded.

private void getEmbedded(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (Element element : elementsForProperty) {
        if ("embedded".equals(element.getName())) {
            AnnotationDescriptor ad = new AnnotationDescriptor(Embedded.class);
            annotationList.add(AnnotationFactory.create(ad));
            Annotation annotation = getAttributeOverrides(element, defaults, false);
            addIfNotNull(annotationList, annotation);
            annotation = getAssociationOverrides(element, defaults, false);
            addIfNotNull(annotationList, annotation);
            getAccessType(annotationList, element);
        }
    }
    if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
        Annotation annotation = getPhysicalAnnotation(Embedded.class);
        if (annotation != null) {
            annotationList.add(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) AttributeOverrides(javax.persistence.AttributeOverrides) AssociationOverrides(javax.persistence.AssociationOverrides) AssociationOverride(javax.persistence.AssociationOverride) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) Annotation(java.lang.annotation.Annotation) AttributeOverride(javax.persistence.AttributeOverride)

Example 45 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getAccessType.

private Access getAccessType(Element tree, XMLContext.Default defaults) {
    String access = tree == null ? null : tree.attributeValue("access");
    if (access != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
        AccessType type;
        try {
            type = AccessType.valueOf(access);
        } catch (IllegalArgumentException e) {
            throw new AnnotationException(access + " is not a valid access type. Check you xml confguration.");
        }
        ad.setValue("value", type);
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations() && isPhysicalAnnotationPresent(Access.class)) {
        return getPhysicalAnnotation(Access.class);
    } else if (defaults.getAccess() != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
        ad.setValue("value", defaults.getAccess());
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ClassLoaderAccess(org.hibernate.boot.spi.ClassLoaderAccess) Access(javax.persistence.Access) AnnotationException(org.hibernate.AnnotationException) AccessType(javax.persistence.AccessType)

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