Search in sources :

Example 6 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getOrderBy.

private void getOrderBy(List<Annotation> annotationList, Element element) {
    Element subelement = element != null ? element.element("order-by") : null;
    if (subelement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(OrderBy.class);
        copyStringElement(subelement, ad, "value");
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element)

Example 7 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildTableGeneratorAnnotation.

public static TableGenerator buildTableGeneratorAnnotation(Element element, XMLContext.Default defaults) {
    AnnotationDescriptor ad = new AnnotationDescriptor(TableGenerator.class);
    copyStringAttribute(ad, element, "name", false);
    copyStringAttribute(ad, element, "table", false);
    copyStringAttribute(ad, element, "catalog", false);
    copyStringAttribute(ad, element, "schema", false);
    copyStringAttribute(ad, element, "pk-column-name", false);
    copyStringAttribute(ad, element, "value-column-name", false);
    copyStringAttribute(ad, element, "pk-column-value", false);
    copyIntegerAttribute(ad, element, "initial-value");
    copyIntegerAttribute(ad, element, "allocation-size");
    buildUniqueConstraints(ad, element);
    if (StringHelper.isEmpty((String) ad.valueOf("schema")) && StringHelper.isNotEmpty(defaults.getSchema())) {
        ad.setValue("schema", defaults.getSchema());
    }
    if (StringHelper.isEmpty((String) ad.valueOf("catalog")) && StringHelper.isNotEmpty(defaults.getCatalog())) {
        ad.setValue("catalog", defaults.getCatalog());
    }
    return AnnotationFactory.create(ad);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)

Example 8 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getMapKey.

private void getMapKey(List<Annotation> annotationList, Element element) {
    Element subelement = element != null ? element.element("map-key") : null;
    if (subelement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(MapKey.class);
        copyStringAttribute(ad, subelement, "name", false);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element)

Example 9 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method processEventAnnotations.

private void processEventAnnotations(List<Annotation> annotationList, XMLContext.Default defaults) {
    boolean eventElement = false;
    for (Element element : elementsForProperty) {
        String elementName = element.getName();
        if ("pre-persist".equals(elementName)) {
            AnnotationDescriptor ad = new AnnotationDescriptor(PrePersist.class);
            annotationList.add(AnnotationFactory.create(ad));
            eventElement = true;
        } else if ("pre-remove".equals(elementName)) {
            AnnotationDescriptor ad = new AnnotationDescriptor(PreRemove.class);
            annotationList.add(AnnotationFactory.create(ad));
            eventElement = true;
        } else if ("pre-update".equals(elementName)) {
            AnnotationDescriptor ad = new AnnotationDescriptor(PreUpdate.class);
            annotationList.add(AnnotationFactory.create(ad));
            eventElement = true;
        } else if ("post-persist".equals(elementName)) {
            AnnotationDescriptor ad = new AnnotationDescriptor(PostPersist.class);
            annotationList.add(AnnotationFactory.create(ad));
            eventElement = true;
        } else if ("post-remove".equals(elementName)) {
            AnnotationDescriptor ad = new AnnotationDescriptor(PostRemove.class);
            annotationList.add(AnnotationFactory.create(ad));
            eventElement = true;
        } else if ("post-update".equals(elementName)) {
            AnnotationDescriptor ad = new AnnotationDescriptor(PostUpdate.class);
            annotationList.add(AnnotationFactory.create(ad));
            eventElement = true;
        } else if ("post-load".equals(elementName)) {
            AnnotationDescriptor ad = new AnnotationDescriptor(PostLoad.class);
            annotationList.add(AnnotationFactory.create(ad));
            eventElement = true;
        }
    }
    if (!eventElement && defaults.canUseJavaAnnotations()) {
        Annotation ann = getPhysicalAnnotation(PrePersist.class);
        addIfNotNull(annotationList, ann);
        ann = getPhysicalAnnotation(PreRemove.class);
        addIfNotNull(annotationList, ann);
        ann = getPhysicalAnnotation(PreUpdate.class);
        addIfNotNull(annotationList, ann);
        ann = getPhysicalAnnotation(PostPersist.class);
        addIfNotNull(annotationList, ann);
        ann = getPhysicalAnnotation(PostRemove.class);
        addIfNotNull(annotationList, ann);
        ann = getPhysicalAnnotation(PostUpdate.class);
        addIfNotNull(annotationList, ann);
        ann = getPhysicalAnnotation(PostLoad.class);
        addIfNotNull(annotationList, ann);
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) PostLoad(javax.persistence.PostLoad) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) PostUpdate(javax.persistence.PostUpdate) PreRemove(javax.persistence.PreRemove) PostPersist(javax.persistence.PostPersist) PostRemove(javax.persistence.PostRemove) Annotation(java.lang.annotation.Annotation) PreUpdate(javax.persistence.PreUpdate)

Example 10 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getOrderColumn.

/**
 * Adds an @OrderColumn annotation to the specified annotationList if the specified element
 * contains an order-column sub-element. This should only be the case for element-collection,
 * many-to-many, or one-to-many associations.
 */
private void getOrderColumn(List<Annotation> annotationList, Element element) {
    Element subelement = element != null ? element.element("order-column") : null;
    if (subelement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(OrderColumn.class);
        copyStringAttribute(ad, subelement, "name", false);
        copyBooleanAttribute(ad, subelement, "nullable");
        copyBooleanAttribute(ad, subelement, "insertable");
        copyBooleanAttribute(ad, subelement, "updatable");
        copyStringAttribute(ad, subelement, "column-definition", false);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element)

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