Search in sources :

Example 1 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getTemporal.

private void getTemporal(List<Annotation> annotationList, Element element) {
    Element subElement = element != null ? element.element("temporal") : null;
    if (subElement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Temporal.class);
        String temporal = subElement.getTextTrim();
        if ("DATE".equalsIgnoreCase(temporal)) {
            ad.setValue("value", TemporalType.DATE);
        } else if ("TIME".equalsIgnoreCase(temporal)) {
            ad.setValue("value", TemporalType.TIME);
        } else if ("TIMESTAMP".equalsIgnoreCase(temporal)) {
            ad.setValue("value", TemporalType.TIMESTAMP);
        } else if (StringHelper.isNotEmpty(temporal)) {
            throw new AnnotationException("Unknown TemporalType: " + temporal + ". " + SCHEMA_VALIDATION);
        }
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) AnnotationException(org.hibernate.AnnotationException)

Example 2 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getNamedStoredProcedureQueries.

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

Example 3 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getMapKeyColumn.

private void getMapKeyColumn(List<Annotation> annotationList, Element element) {
    Element subelement = element != null ? element.element("map-key-column") : null;
    if (subelement != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyColumn.class);
        copyStringAttribute(ad, subelement, "name", false);
        copyBooleanAttribute(ad, subelement, "unique");
        copyBooleanAttribute(ad, subelement, "nullable");
        copyBooleanAttribute(ad, subelement, "insertable");
        copyBooleanAttribute(ad, subelement, "updatable");
        copyStringAttribute(ad, subelement, "column-definition", false);
        copyStringAttribute(ad, subelement, "table", false);
        copyIntegerAttribute(ad, subelement, "length");
        copyIntegerAttribute(ad, subelement, "precision");
        copyIntegerAttribute(ad, subelement, "scale");
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element)

Example 4 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildUniqueConstraints.

private static void buildUniqueConstraints(AnnotationDescriptor annotation, Element element) {
    List uniqueConstraintElementList = element.elements("unique-constraint");
    UniqueConstraint[] uniqueConstraints = new UniqueConstraint[uniqueConstraintElementList.size()];
    int ucIndex = 0;
    Iterator ucIt = uniqueConstraintElementList.listIterator();
    while (ucIt.hasNext()) {
        Element subelement = (Element) ucIt.next();
        List<Element> columnNamesElements = subelement.elements("column-name");
        String[] columnNames = new String[columnNamesElements.size()];
        int columnNameIndex = 0;
        Iterator it = columnNamesElements.listIterator();
        while (it.hasNext()) {
            Element columnNameElt = (Element) it.next();
            columnNames[columnNameIndex++] = columnNameElt.getTextTrim();
        }
        AnnotationDescriptor ucAnn = new AnnotationDescriptor(UniqueConstraint.class);
        copyStringAttribute(ucAnn, subelement, "name", false);
        ucAnn.setValue("columnNames", columnNames);
        uniqueConstraints[ucIndex++] = AnnotationFactory.create(ucAnn);
    }
    annotation.setValue("uniqueConstraints", uniqueConstraints);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) Iterator(java.util.Iterator) UniqueConstraint(javax.persistence.UniqueConstraint) ArrayList(java.util.ArrayList) List(java.util.List) QueryHint(javax.persistence.QueryHint) UniqueConstraint(javax.persistence.UniqueConstraint)

Example 5 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method getEmbeddedId.

private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (Element element : elementsForProperty) {
        if ("embedded-id".equals(element.getName())) {
            if (isProcessingId(defaults)) {
                Annotation annotation = getAttributeOverrides(element, defaults, false);
                addIfNotNull(annotationList, annotation);
                annotation = getAssociationOverrides(element, defaults, false);
                addIfNotNull(annotationList, annotation);
                AnnotationDescriptor ad = new AnnotationDescriptor(EmbeddedId.class);
                annotationList.add(AnnotationFactory.create(ad));
                getAccessType(annotationList, element);
            }
        }
    }
    if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
        Annotation annotation = getPhysicalAnnotation(EmbeddedId.class);
        if (annotation != null) {
            annotationList.add(annotation);
            annotation = getPhysicalAnnotation(Column.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(Columns.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(GeneratedValue.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(Temporal.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(TableGenerator.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(SequenceGenerator.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(AttributeOverride.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(AttributeOverrides.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(AssociationOverride.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(AssociationOverrides.class);
            addIfNotNull(annotationList, annotation);
        }
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AssociationOverride(javax.persistence.AssociationOverride) SequenceGenerator(javax.persistence.SequenceGenerator) 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) TableGenerator(javax.persistence.TableGenerator) Annotation(java.lang.annotation.Annotation) AttributeOverride(javax.persistence.AttributeOverride) GeneratedValue(javax.persistence.GeneratedValue) AttributeOverrides(javax.persistence.AttributeOverrides) AssociationOverrides(javax.persistence.AssociationOverrides) 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)

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