Search in sources :

Example 51 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method overridesDefaultInSecondaryTable.

private void overridesDefaultInSecondaryTable(SecondaryTable secTableAnn, XMLContext.Default defaults, List<SecondaryTable> secondaryTables) {
    if (secTableAnn != null) {
        // handle default values
        if (StringHelper.isNotEmpty(defaults.getCatalog()) || StringHelper.isNotEmpty(defaults.getSchema())) {
            AnnotationDescriptor annotation = new AnnotationDescriptor(SecondaryTable.class);
            annotation.setValue("name", secTableAnn.name());
            annotation.setValue("schema", secTableAnn.schema());
            annotation.setValue("catalog", secTableAnn.catalog());
            annotation.setValue("uniqueConstraints", secTableAnn.uniqueConstraints());
            annotation.setValue("pkJoinColumns", secTableAnn.pkJoinColumns());
            if (StringHelper.isEmpty((String) annotation.valueOf("schema")) && StringHelper.isNotEmpty(defaults.getSchema())) {
                annotation.setValue("schema", defaults.getSchema());
            }
            if (StringHelper.isEmpty((String) annotation.valueOf("catalog")) && StringHelper.isNotEmpty(defaults.getCatalog())) {
                annotation.setValue("catalog", defaults.getCatalog());
            }
            secondaryTables.add(AnnotationFactory.create(annotation));
        } else {
            secondaryTables.add(secTableAnn);
        }
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)

Example 52 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildNamedEntityGraph.

public static List<NamedEntityGraph> buildNamedEntityGraph(Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    if (element == null) {
        return new ArrayList<>();
    }
    List<NamedEntityGraph> namedEntityGraphList = new ArrayList<>();
    List<Element> namedEntityGraphElements = element.elements("named-entity-graph");
    for (Element subElement : namedEntityGraphElements) {
        AnnotationDescriptor ann = new AnnotationDescriptor(NamedEntityGraph.class);
        copyStringAttribute(ann, subElement, "name", false);
        copyBooleanAttribute(ann, subElement, "include-all-attributes");
        bindNamedAttributeNodes(subElement, ann);
        List<Element> subgraphNodes = subElement.elements("subgraph");
        List<Element> subclassSubgraphNodes = subElement.elements("subclass-subgraph");
        if (!subclassSubgraphNodes.isEmpty()) {
            subgraphNodes.addAll(subclassSubgraphNodes);
        }
        bindNamedSubgraph(defaults, ann, subgraphNodes, classLoaderAccess);
        namedEntityGraphList.add(AnnotationFactory.create(ann));
    }
    // TODO
    return namedEntityGraphList;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) NamedEntityGraph(javax.persistence.NamedEntityGraph) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Example 53 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method overridesDefaultCascadePersist.

private Annotation overridesDefaultCascadePersist(Annotation annotation, XMLContext.Default defaults) {
    if (Boolean.TRUE.equals(defaults.getCascadePersist())) {
        final Class<? extends Annotation> annotationType = annotation.annotationType();
        if (annotationType == ManyToOne.class) {
            ManyToOne manyToOne = (ManyToOne) annotation;
            List<CascadeType> cascades = new ArrayList<>(Arrays.asList(manyToOne.cascade()));
            if (!cascades.contains(CascadeType.ALL) && !cascades.contains(CascadeType.PERSIST)) {
                cascades.add(CascadeType.PERSIST);
            } else {
                return annotation;
            }
            AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
            ad.setValue("cascade", cascades.toArray(new CascadeType[] {}));
            ad.setValue("targetEntity", manyToOne.targetEntity());
            ad.setValue("fetch", manyToOne.fetch());
            ad.setValue("optional", manyToOne.optional());
            return AnnotationFactory.create(ad);
        } else if (annotationType == OneToOne.class) {
            OneToOne oneToOne = (OneToOne) annotation;
            List<CascadeType> cascades = new ArrayList<>(Arrays.asList(oneToOne.cascade()));
            if (!cascades.contains(CascadeType.ALL) && !cascades.contains(CascadeType.PERSIST)) {
                cascades.add(CascadeType.PERSIST);
            } else {
                return annotation;
            }
            AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
            ad.setValue("cascade", cascades.toArray(new CascadeType[] {}));
            ad.setValue("targetEntity", oneToOne.targetEntity());
            ad.setValue("fetch", oneToOne.fetch());
            ad.setValue("optional", oneToOne.optional());
            ad.setValue("mappedBy", oneToOne.mappedBy());
            ad.setValue("orphanRemoval", oneToOne.orphanRemoval());
            return AnnotationFactory.create(ad);
        }
    }
    return annotation;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) OneToOne(javax.persistence.OneToOne) CascadeType(javax.persistence.CascadeType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ManyToOne(javax.persistence.ManyToOne)

Example 54 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method bindNamedSubgraph.

private static void bindNamedSubgraph(XMLContext.Default defaults, AnnotationDescriptor ann, List<Element> subgraphNodes, ClassLoaderAccess classLoaderAccess) {
    List<NamedSubgraph> annSubgraphNodes = new ArrayList<>();
    for (Element subgraphNode : subgraphNodes) {
        AnnotationDescriptor annSubgraphNode = new AnnotationDescriptor(NamedSubgraph.class);
        copyStringAttribute(annSubgraphNode, subgraphNode, "name", true);
        String clazzName = subgraphNode.attributeValue("class");
        Class clazz;
        try {
            clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
        } catch (ClassLoadingException e) {
            throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
        }
        annSubgraphNode.setValue("type", clazz);
        bindNamedAttributeNodes(subgraphNode, annSubgraphNode);
        annSubgraphNodes.add(AnnotationFactory.create(annSubgraphNode));
    }
    ann.setValue("subgraphs", annSubgraphNodes.toArray(new NamedSubgraph[annSubgraphNodes.size()]));
}
Also used : NamedSubgraph(javax.persistence.NamedSubgraph) AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) AnnotationException(org.hibernate.AnnotationException) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass)

Example 55 with AnnotationDescriptor

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

the class JPAOverriddenAnnotationReader method buildColumnResult.

private static ColumnResult buildColumnResult(Element columnResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    // AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor( ColumnResult.class );
    // copyStringAttribute( columnResultDescriptor, columnResultElement, "name", true );
    // return AnnotationFactory.create( columnResultDescriptor );
    AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor(ColumnResult.class);
    copyStringAttribute(columnResultDescriptor, columnResultElement, "name", true);
    final String columnTypeName = columnResultElement.attributeValue("class");
    if (StringHelper.isNotEmpty(columnTypeName)) {
        columnResultDescriptor.setValue("type", resolveClassReference(columnTypeName, defaults, classLoaderAccess));
    }
    return AnnotationFactory.create(columnResultDescriptor);
}
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