Search in sources :

Example 56 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildColumns.

private Columns buildColumns(Element element) {
    List<Element> subelements = element.elements("column");
    List<Column> columns = new ArrayList<>(subelements.size());
    for (Element subelement : subelements) {
        columns.add(getColumn(subelement, false, element));
    }
    if (columns.size() > 0) {
        AnnotationDescriptor columnsDescr = new AnnotationDescriptor(Columns.class);
        columnsDescr.setValue("columns", columns.toArray(new Column[columns.size()]));
        return AnnotationFactory.create(columnsDescr);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) MapKeyColumn(javax.persistence.MapKeyColumn) OrderColumn(javax.persistence.OrderColumn) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) Column(javax.persistence.Column) DiscriminatorColumn(javax.persistence.DiscriminatorColumn) JoinColumn(javax.persistence.JoinColumn) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Example 57 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getElementCollection.

/**
 * As per sections 12.2.3.23.9, 12.2.4.8.9 and 12.2.5.3.6 of the JPA 2.0
 * specification, the element-collection subelement completely overrides the
 * mapping for the specified field or property.  Thus, any methods which
 * might in some contexts merge with annotations must not do so in this
 * context.
 */
private void getElementCollection(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (Element element : elementsForProperty) {
        if ("element-collection".equals(element.getName())) {
            AnnotationDescriptor ad = new AnnotationDescriptor(ElementCollection.class);
            addTargetClass(element, ad, "target-class", defaults);
            getFetchType(ad, element);
            getOrderBy(annotationList, element);
            getOrderColumn(annotationList, element);
            getMapKey(annotationList, element);
            getMapKeyClass(annotationList, element, defaults);
            getMapKeyTemporal(annotationList, element);
            getMapKeyEnumerated(annotationList, element);
            getMapKeyColumn(annotationList, element);
            buildMapKeyJoinColumns(annotationList, element);
            Annotation annotation = getColumn(element.element("column"), false, element);
            addIfNotNull(annotationList, annotation);
            getTemporal(annotationList, element);
            getEnumerated(annotationList, element);
            getLob(annotationList, element);
            // Both map-key-attribute-overrides and attribute-overrides
            // translate into AttributeOverride annotations, which need
            // need to be wrapped in the same AttributeOverrides annotation.
            List<AttributeOverride> attributes = new ArrayList<>();
            attributes.addAll(buildAttributeOverrides(element, "map-key-attribute-override"));
            attributes.addAll(buildAttributeOverrides(element, "attribute-override"));
            annotation = mergeAttributeOverrides(defaults, attributes, false);
            addIfNotNull(annotationList, annotation);
            annotation = getAssociationOverrides(element, defaults, false);
            addIfNotNull(annotationList, annotation);
            getCollectionTable(annotationList, element, defaults);
            annotationList.add(AnnotationFactory.create(ad));
            getAccessType(annotationList, element);
        }
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) AttributeOverride(javax.persistence.AttributeOverride)

Example 58 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getSecondaryTables.

private SecondaryTables getSecondaryTables(Element tree, XMLContext.Default defaults) {
    List<Element> elements = tree == null ? new ArrayList<>() : (List<Element>) tree.elements("secondary-table");
    List<SecondaryTable> secondaryTables = new ArrayList<>(3);
    for (Element element : elements) {
        AnnotationDescriptor annotation = new AnnotationDescriptor(SecondaryTable.class);
        copyStringAttribute(annotation, element, "name", false);
        copyStringAttribute(annotation, element, "catalog", false);
        if (StringHelper.isNotEmpty(defaults.getCatalog()) && StringHelper.isEmpty((String) annotation.valueOf("catalog"))) {
            annotation.setValue("catalog", defaults.getCatalog());
        }
        copyStringAttribute(annotation, element, "schema", false);
        if (StringHelper.isNotEmpty(defaults.getSchema()) && StringHelper.isEmpty((String) annotation.valueOf("schema"))) {
            annotation.setValue("schema", defaults.getSchema());
        }
        buildUniqueConstraints(annotation, element);
        buildIndex(annotation, element);
        annotation.setValue("pkJoinColumns", buildPrimaryKeyJoinColumns(element));
        secondaryTables.add(AnnotationFactory.create(annotation));
    }
    /*
		 * You can't have both secondary table in XML and Java,
		 * since there would be no way to "remove" a secondary table
		 */
    if (secondaryTables.size() == 0 && defaults.canUseJavaAnnotations()) {
        SecondaryTable secTableAnn = getPhysicalAnnotation(SecondaryTable.class);
        overridesDefaultInSecondaryTable(secTableAnn, defaults, secondaryTables);
        SecondaryTables secTablesAnn = getPhysicalAnnotation(SecondaryTables.class);
        if (secTablesAnn != null) {
            for (SecondaryTable table : secTablesAnn.value()) {
                overridesDefaultInSecondaryTable(table, defaults, secondaryTables);
            }
        }
    }
    if (secondaryTables.size() > 0) {
        AnnotationDescriptor descriptor = new AnnotationDescriptor(SecondaryTables.class);
        descriptor.setValue("value", secondaryTables.toArray(new SecondaryTable[secondaryTables.size()]));
        return AnnotationFactory.create(descriptor);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) SecondaryTables(javax.persistence.SecondaryTables) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) SecondaryTable(javax.persistence.SecondaryTable)

Example 59 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getJoinColumns.

private JoinColumn[] getJoinColumns(Element element, boolean isInverse) {
    List<Element> subelements = element != null ? element.elements(isInverse ? "inverse-join-column" : "join-column") : null;
    List<JoinColumn> joinColumns = new ArrayList<>();
    if (subelements != null) {
        for (Element subelement : subelements) {
            AnnotationDescriptor column = new AnnotationDescriptor(JoinColumn.class);
            copyStringAttribute(column, subelement, "name", false);
            copyStringAttribute(column, subelement, "referenced-column-name", false);
            copyBooleanAttribute(column, subelement, "unique");
            copyBooleanAttribute(column, subelement, "nullable");
            copyBooleanAttribute(column, subelement, "insertable");
            copyBooleanAttribute(column, subelement, "updatable");
            copyStringAttribute(column, subelement, "column-definition", false);
            copyStringAttribute(column, subelement, "table", false);
            joinColumns.add(AnnotationFactory.create(column));
        }
    }
    return joinColumns.toArray(new JoinColumn[joinColumns.size()]);
}
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) ArrayList(java.util.ArrayList)

Example 60 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildAssociationOverrides.

private List<AssociationOverride> buildAssociationOverrides(Element element, XMLContext.Default defaults) {
    List<Element> subelements = element == null ? null : element.elements("association-override");
    List<AssociationOverride> overrides = new ArrayList<>();
    if (subelements != null && subelements.size() > 0) {
        for (Element current : subelements) {
            AnnotationDescriptor override = new AnnotationDescriptor(AssociationOverride.class);
            copyStringAttribute(override, current, "name", true);
            override.setValue("joinColumns", getJoinColumns(current, false));
            JoinTable joinTable = buildJoinTable(current, defaults);
            if (joinTable != null) {
                override.setValue("joinTable", joinTable);
            }
            overrides.add(AnnotationFactory.create(override));
        }
    }
    return overrides;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AssociationOverride(javax.persistence.AssociationOverride) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) JoinTable(javax.persistence.JoinTable)

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