Search in sources :

Example 66 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getColumn.

private Column getColumn(Element element, boolean isMandatory, Element current) {
    // Element subelement = element != null ? element.element( "column" ) : null;
    if (element != null) {
        AnnotationDescriptor column = new AnnotationDescriptor(Column.class);
        copyStringAttribute(column, element, "name", false);
        copyBooleanAttribute(column, element, "unique");
        copyBooleanAttribute(column, element, "nullable");
        copyBooleanAttribute(column, element, "insertable");
        copyBooleanAttribute(column, element, "updatable");
        copyStringAttribute(column, element, "column-definition", false);
        copyStringAttribute(column, element, "table", false);
        copyIntegerAttribute(column, element, "length");
        copyIntegerAttribute(column, element, "precision");
        copyIntegerAttribute(column, element, "scale");
        return (Column) AnnotationFactory.create(column);
    } else {
        if (isMandatory) {
            throw new AnnotationException(current.getPath() + ".column is mandatory. " + SCHEMA_VALIDATION);
        }
        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) AnnotationException(org.hibernate.AnnotationException)

Example 67 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getMapKeyTemporal.

/**
 * Adds a @MapKeyTemporal annotation to the specified annotationList if the specified element
 * contains a map-key-temporal sub-element. This should only be the case for element-collection,
 * many-to-many, or one-to-many associations.
 */
private void getMapKeyTemporal(List<Annotation> annotationList, Element element) {
    Element subelement = element != null ? element.element("map-key-temporal") : null;
    if (subelement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyTemporal.class);
        TemporalType value = TemporalType.valueOf(subelement.getTextTrim());
        ad.setValue("value", value);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) TemporalType(javax.persistence.TemporalType)

Example 68 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getVersion.

private void getVersion(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (Element element : elementsForProperty) {
        if ("version".equals(element.getName())) {
            Annotation annotation = buildColumns(element);
            addIfNotNull(annotationList, annotation);
            getTemporal(annotationList, element);
            AnnotationDescriptor basic = new AnnotationDescriptor(Version.class);
            annotationList.add(AnnotationFactory.create(basic));
            getAccessType(annotationList, element);
        }
    }
    if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
        // we have nothing, so Java annotations might occurs
        Annotation annotation = getPhysicalAnnotation(Version.class);
        if (annotation != null) {
            annotationList.add(annotation);
            annotation = getPhysicalAnnotation(Column.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(Columns.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(Temporal.class);
            addIfNotNull(annotationList, annotation);
        }
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) MapKeyTemporal(javax.persistence.MapKeyTemporal) Temporal(javax.persistence.Temporal) 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) MapKeyJoinColumns(javax.persistence.MapKeyJoinColumns) Columns(org.hibernate.annotations.Columns) JoinColumns(javax.persistence.JoinColumns) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns) Annotation(java.lang.annotation.Annotation)

Example 69 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method overridesDefaultsInJoinTable.

private JoinTable overridesDefaultsInJoinTable(Annotation annotation, XMLContext.Default defaults) {
    // no element but might have some default or some annotation
    boolean defaultToJoinTable = !(isPhysicalAnnotationPresent(JoinColumn.class) || isPhysicalAnnotationPresent(JoinColumns.class));
    final Class<? extends Annotation> annotationClass = annotation.annotationType();
    defaultToJoinTable = defaultToJoinTable && ((annotationClass == ManyToMany.class && StringHelper.isEmpty(((ManyToMany) annotation).mappedBy())) || (annotationClass == OneToMany.class && StringHelper.isEmpty(((OneToMany) annotation).mappedBy())) || (annotationClass == ElementCollection.class));
    final Class<JoinTable> annotationType = JoinTable.class;
    if (defaultToJoinTable && (StringHelper.isNotEmpty(defaults.getCatalog()) || StringHelper.isNotEmpty(defaults.getSchema()))) {
        AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
        if (defaults.canUseJavaAnnotations()) {
            JoinTable table = getPhysicalAnnotation(annotationType);
            if (table != null) {
                ad.setValue("name", table.name());
                ad.setValue("schema", table.schema());
                ad.setValue("catalog", table.catalog());
                ad.setValue("uniqueConstraints", table.uniqueConstraints());
                ad.setValue("joinColumns", table.joinColumns());
                ad.setValue("inverseJoinColumns", table.inverseJoinColumns());
            }
        }
        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);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(annotationType);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) JoinColumn(javax.persistence.JoinColumn) MapKeyJoinColumns(javax.persistence.MapKeyJoinColumns) JoinColumns(javax.persistence.JoinColumns) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns) ManyToMany(javax.persistence.ManyToMany) ElementCollection(javax.persistence.ElementCollection) OneToMany(javax.persistence.OneToMany) JoinTable(javax.persistence.JoinTable)

Example 70 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method bindNamedAttributeNodes.

private static void bindNamedAttributeNodes(Element subElement, AnnotationDescriptor ann) {
    List<Element> namedAttributeNodes = subElement.elements("named-attribute-node");
    List<NamedAttributeNode> annNamedAttributeNodes = new ArrayList<>();
    for (Element namedAttributeNode : namedAttributeNodes) {
        AnnotationDescriptor annNamedAttributeNode = new AnnotationDescriptor(NamedAttributeNode.class);
        copyStringAttribute(annNamedAttributeNode, namedAttributeNode, "value", "name", true);
        copyStringAttribute(annNamedAttributeNode, namedAttributeNode, "subgraph", false);
        copyStringAttribute(annNamedAttributeNode, namedAttributeNode, "key-subgraph", false);
        annNamedAttributeNodes.add(AnnotationFactory.create(annNamedAttributeNode));
    }
    ann.setValue("attributeNodes", annNamedAttributeNodes.toArray(new NamedAttributeNode[annNamedAttributeNodes.size()]));
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) NamedAttributeNode(javax.persistence.NamedAttributeNode)

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