Search in sources :

Example 46 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildPrimaryKeyJoinColumns.

private PrimaryKeyJoinColumn[] buildPrimaryKeyJoinColumns(Element element) {
    if (element == null) {
        return new PrimaryKeyJoinColumn[] {};
    }
    List pkJoinColumnElementList = element.elements("primary-key-join-column");
    PrimaryKeyJoinColumn[] pkJoinColumns = new PrimaryKeyJoinColumn[pkJoinColumnElementList.size()];
    int index = 0;
    Iterator pkIt = pkJoinColumnElementList.listIterator();
    while (pkIt.hasNext()) {
        Element subelement = (Element) pkIt.next();
        AnnotationDescriptor pkAnn = new AnnotationDescriptor(PrimaryKeyJoinColumn.class);
        copyStringAttribute(pkAnn, subelement, "name", false);
        copyStringAttribute(pkAnn, subelement, "referenced-column-name", false);
        copyStringAttribute(pkAnn, subelement, "column-definition", false);
        pkJoinColumns[index++] = AnnotationFactory.create(pkAnn);
    }
    return pkJoinColumns;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) QueryHint(javax.persistence.QueryHint) UniqueConstraint(javax.persistence.UniqueConstraint)

Example 47 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getSqlResultSetMappings.

private SqlResultSetMappings getSqlResultSetMappings(Element tree, XMLContext.Default defaults) {
    List<SqlResultSetMapping> results = buildSqlResultsetMappings(tree, defaults, classLoaderAccess);
    if (defaults.canUseJavaAnnotations()) {
        SqlResultSetMapping annotation = getPhysicalAnnotation(SqlResultSetMapping.class);
        addSqlResultsetMappingIfNeeded(annotation, results);
        SqlResultSetMappings annotations = getPhysicalAnnotation(SqlResultSetMappings.class);
        if (annotations != null) {
            for (SqlResultSetMapping current : annotations.value()) {
                addSqlResultsetMappingIfNeeded(current, results);
            }
        }
    }
    if (results.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(SqlResultSetMappings.class);
        ad.setValue("value", results.toArray(new SqlResultSetMapping[results.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) SqlResultSetMappings(javax.persistence.SqlResultSetMappings) SqlResultSetMapping(javax.persistence.SqlResultSetMapping)

Example 48 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method applyXmlDefinedConverts.

private void applyXmlDefinedConverts(Element containingElement, XMLContext.Default defaults, String attributeNamePrefix, Map<String, Convert> convertAnnotationsMap) {
    final List<Element> convertElements = containingElement.elements("convert");
    for (Element convertElement : convertElements) {
        final AnnotationDescriptor convertAnnotationDescriptor = new AnnotationDescriptor(Convert.class);
        copyStringAttribute(convertAnnotationDescriptor, convertElement, "attribute-name", false);
        copyBooleanAttribute(convertAnnotationDescriptor, convertElement, "disable-conversion");
        final Attribute converterClassAttr = convertElement.attribute("converter");
        if (converterClassAttr != null) {
            final String converterClassName = XMLContext.buildSafeClassName(converterClassAttr.getValue(), defaults);
            try {
                final Class converterClass = classLoaderAccess.classForName(converterClassName);
                convertAnnotationDescriptor.setValue("converter", converterClass);
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find specified converter class id-class: " + converterClassName, e);
            }
        }
        final Convert convertAnnotation = AnnotationFactory.create(convertAnnotationDescriptor);
        final String qualifiedAttributeName = qualifyConverterAttributeName(attributeNamePrefix, convertAnnotation.attributeName());
        convertAnnotationsMap.put(qualifiedAttributeName, convertAnnotation);
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Convert(javax.persistence.Convert) Attribute(org.dom4j.Attribute) 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 49 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildQueryHints.

private static void buildQueryHints(List<Element> elements, AnnotationDescriptor ann) {
    List<QueryHint> queryHints = new ArrayList<>(elements.size());
    for (Element hint : elements) {
        AnnotationDescriptor hintDescriptor = new AnnotationDescriptor(QueryHint.class);
        String value = hint.attributeValue("name");
        if (value == null) {
            throw new AnnotationException("<hint> without name. " + SCHEMA_VALIDATION);
        }
        hintDescriptor.setValue("name", value);
        value = hint.attributeValue("value");
        if (value == null) {
            throw new AnnotationException("<hint> without value. " + SCHEMA_VALIDATION);
        }
        hintDescriptor.setValue("value", value);
        queryHints.add(AnnotationFactory.create(hintDescriptor));
    }
    ann.setValue("hints", queryHints.toArray(new QueryHint[queryHints.size()]));
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) QueryHint(javax.persistence.QueryHint) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) AnnotationException(org.hibernate.AnnotationException)

Example 50 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildEntityResult.

private static EntityResult buildEntityResult(Element entityResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    final AnnotationDescriptor entityResultDescriptor = new AnnotationDescriptor(EntityResult.class);
    final Class entityClass = resolveClassReference(entityResultElement.attributeValue("entity-class"), defaults, classLoaderAccess);
    entityResultDescriptor.setValue("entityClass", entityClass);
    copyStringAttribute(entityResultDescriptor, entityResultElement, "discriminator-column", false);
    // process the <field-result/> sub-elements
    List<FieldResult> fieldResultAnnotations = new ArrayList<>();
    for (Element fieldResult : (List<Element>) entityResultElement.elements("field-result")) {
        AnnotationDescriptor fieldResultDescriptor = new AnnotationDescriptor(FieldResult.class);
        copyStringAttribute(fieldResultDescriptor, fieldResult, "name", true);
        copyStringAttribute(fieldResultDescriptor, fieldResult, "column", true);
        fieldResultAnnotations.add(AnnotationFactory.create(fieldResultDescriptor));
    }
    entityResultDescriptor.setValue("fields", fieldResultAnnotations.toArray(new FieldResult[fieldResultAnnotations.size()]));
    return AnnotationFactory.create(entityResultDescriptor);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass) ArrayList(java.util.ArrayList) List(java.util.List) FieldResult(javax.persistence.FieldResult)

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