Search in sources :

Example 36 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildIndex.

private static void buildIndex(AnnotationDescriptor annotation, Element element) {
    List indexElementList = element.elements("index");
    Index[] indexes = new Index[indexElementList.size()];
    for (int i = 0; i < indexElementList.size(); i++) {
        Element subelement = (Element) indexElementList.get(i);
        AnnotationDescriptor indexAnn = new AnnotationDescriptor(Index.class);
        copyStringAttribute(indexAnn, subelement, "name", false);
        copyStringAttribute(indexAnn, subelement, "column-list", true);
        copyBooleanAttribute(indexAnn, subelement, "unique");
        indexes[i] = AnnotationFactory.create(indexAnn);
    }
    annotation.setValue("indexes", indexes);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List) Index(javax.persistence.Index) QueryHint(javax.persistence.QueryHint) UniqueConstraint(javax.persistence.UniqueConstraint)

Example 37 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getInheritance.

private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element("inheritance") : null;
    if (element != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Inheritance.class);
        Attribute attr = element.attribute("strategy");
        InheritanceType strategy = InheritanceType.SINGLE_TABLE;
        if (attr != null) {
            String value = attr.getValue();
            if ("SINGLE_TABLE".equals(value)) {
                strategy = InheritanceType.SINGLE_TABLE;
            } else if ("JOINED".equals(value)) {
                strategy = InheritanceType.JOINED;
            } else if ("TABLE_PER_CLASS".equals(value)) {
                strategy = InheritanceType.TABLE_PER_CLASS;
            } else {
                throw new AnnotationException("Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")");
            }
        }
        ad.setValue("strategy", strategy);
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(Inheritance.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Attribute(org.dom4j.Attribute) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) Inheritance(javax.persistence.Inheritance) AnnotationException(org.hibernate.AnnotationException) InheritanceType(javax.persistence.InheritanceType)

Example 38 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getCollectionTable.

private void getCollectionTable(List<Annotation> annotationList, Element element, XMLContext.Default defaults) {
    Element subelement = element != null ? element.element("collection-table") : null;
    if (subelement != null) {
        AnnotationDescriptor annotation = new AnnotationDescriptor(CollectionTable.class);
        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());
        }
        JoinColumn[] joinColumns = getJoinColumns(subelement, false);
        if (joinColumns.length > 0) {
            annotation.setValue("joinColumns", joinColumns);
        }
        buildUniqueConstraints(annotation, subelement);
        buildIndex(annotation, subelement);
        annotationList.add(AnnotationFactory.create(annotation));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) JoinColumn(javax.persistence.JoinColumn) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element)

Example 39 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildJoinColumns.

private void buildJoinColumns(List<Annotation> annotationList, Element element) {
    JoinColumn[] joinColumns = getJoinColumns(element, false);
    if (joinColumns.length > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(JoinColumns.class);
        ad.setValue("value", joinColumns);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) JoinColumn(javax.persistence.JoinColumn)

Example 40 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getCacheable.

private Cacheable getCacheable(Element element, XMLContext.Default defaults) {
    if (element != null) {
        String attValue = element.attributeValue("cacheable");
        if (attValue != null) {
            AnnotationDescriptor ad = new AnnotationDescriptor(Cacheable.class);
            ad.setValue("value", Boolean.valueOf(attValue));
            return AnnotationFactory.create(ad);
        }
    }
    if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(Cacheable.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)

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