Search in sources :

Example 26 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method mergeAttributeOverrides.

/**
 * @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 association mapping) merging with
 * annotations is never allowed.
 */
private AttributeOverrides mergeAttributeOverrides(XMLContext.Default defaults, List<AttributeOverride> attributes, boolean mergeWithAnnotations) {
    if (mergeWithAnnotations && defaults.canUseJavaAnnotations()) {
        AttributeOverride annotation = getPhysicalAnnotation(AttributeOverride.class);
        addAttributeOverrideIfNeeded(annotation, attributes);
        AttributeOverrides annotations = getPhysicalAnnotation(AttributeOverrides.class);
        if (annotations != null) {
            for (AttributeOverride current : annotations.value()) {
                addAttributeOverrideIfNeeded(current, attributes);
            }
        }
    }
    if (attributes.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(AttributeOverrides.class);
        ad.setValue("value", attributes.toArray(new AttributeOverride[attributes.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AttributeOverrides(javax.persistence.AttributeOverrides) AttributeOverride(javax.persistence.AttributeOverride)

Example 27 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getDiscriminatorColumn.

private DiscriminatorColumn getDiscriminatorColumn(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element("discriminator-column") : null;
    if (element != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(DiscriminatorColumn.class);
        copyStringAttribute(ad, element, "name", false);
        copyStringAttribute(ad, element, "column-definition", false);
        String value = element.attributeValue("discriminator-type");
        DiscriminatorType type = DiscriminatorType.STRING;
        if (value != null) {
            if ("STRING".equals(value)) {
                type = DiscriminatorType.STRING;
            } else if ("CHAR".equals(value)) {
                type = DiscriminatorType.CHAR;
            } else if ("INTEGER".equals(value)) {
                type = DiscriminatorType.INTEGER;
            } else {
                throw new AnnotationException("Unknown DiscrimiatorType in XML: " + value + " (" + SCHEMA_VALIDATION + ")");
            }
        }
        ad.setValue("discriminatorType", type);
        copyIntegerAttribute(ad, element, "length");
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(DiscriminatorColumn.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) DiscriminatorType(javax.persistence.DiscriminatorType) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) DiscriminatorColumn(javax.persistence.DiscriminatorColumn) AnnotationException(org.hibernate.AnnotationException)

Example 28 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildSequenceGeneratorAnnotation.

public static SequenceGenerator buildSequenceGeneratorAnnotation(Element element) {
    if (element != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(SequenceGenerator.class);
        copyStringAttribute(ad, element, "name", false);
        copyStringAttribute(ad, element, "sequence-name", false);
        copyIntegerAttribute(ad, element, "initial-value");
        copyIntegerAttribute(ad, element, "allocation-size");
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)

Example 29 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getEnumerated.

private void getEnumerated(List<Annotation> annotationList, Element element) {
    Element subElement = element != null ? element.element("enumerated") : null;
    if (subElement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Enumerated.class);
        String enumerated = subElement.getTextTrim();
        if ("ORDINAL".equalsIgnoreCase(enumerated)) {
            ad.setValue("value", EnumType.ORDINAL);
        } else if ("STRING".equalsIgnoreCase(enumerated)) {
            ad.setValue("value", EnumType.STRING);
        } else if (StringHelper.isNotEmpty(enumerated)) {
            throw new AnnotationException("Unknown EnumType: " + enumerated + ". " + SCHEMA_VALIDATION);
        }
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) AnnotationException(org.hibernate.AnnotationException)

Example 30 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getAccessType.

private void getAccessType(List<Annotation> annotationList, Element element) {
    if (element == null) {
        return;
    }
    String access = element.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.");
        }
        if ((AccessType.PROPERTY.equals(type) && this.element instanceof Method) || (AccessType.FIELD.equals(type) && this.element instanceof Field)) {
            return;
        }
        ad.setValue("value", type);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Field(java.lang.reflect.Field) AnnotationException(org.hibernate.AnnotationException) Method(java.lang.reflect.Method) 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