Search in sources :

Example 6 with JaxbEntity

use of org.hibernate.boot.jaxb.mapping.spi.JaxbEntity in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getNamedStoredProcedureQueries.

private NamedStoredProcedureQueries getNamedStoredProcedureQueries(ManagedType root, XMLContext.Default defaults) {
    List<NamedStoredProcedureQuery> queries = root instanceof JaxbEntity ? buildNamedStoreProcedureQueries(((JaxbEntity) root).getNamedStoredProcedureQuery(), defaults, classLoaderAccess) : new ArrayList<>();
    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(jakarta.persistence.NamedStoredProcedureQueries) JaxbNamedStoredProcedureQuery(org.hibernate.boot.jaxb.mapping.spi.JaxbNamedStoredProcedureQuery) NamedStoredProcedureQuery(jakarta.persistence.NamedStoredProcedureQuery) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Example 7 with JaxbEntity

use of org.hibernate.boot.jaxb.mapping.spi.JaxbEntity in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getTable.

private Table getTable(ManagedType root, XMLContext.Default defaults) {
    JaxbTable element = root instanceof JaxbEntity ? ((JaxbEntity) root).getTable() : null;
    if (element == null) {
        // no element but might have some default or some annotation
        if (StringHelper.isNotEmpty(defaults.getCatalog()) || StringHelper.isNotEmpty(defaults.getSchema())) {
            AnnotationDescriptor annotation = new AnnotationDescriptor(Table.class);
            if (defaults.canUseJavaAnnotations()) {
                Table table = getPhysicalAnnotation(Table.class);
                if (table != null) {
                    annotation.setValue("name", table.name());
                    annotation.setValue("schema", table.schema());
                    annotation.setValue("catalog", table.catalog());
                    annotation.setValue("uniqueConstraints", table.uniqueConstraints());
                    annotation.setValue("indexes", table.indexes());
                }
            }
            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());
            }
            return AnnotationFactory.create(annotation);
        } else if (defaults.canUseJavaAnnotations()) {
            return getPhysicalAnnotation(Table.class);
        } else {
            return null;
        }
    } else {
        // ignore java annotation, an element is defined
        AnnotationDescriptor annotation = new AnnotationDescriptor(Table.class);
        copyAttribute(annotation, "name", element.getName(), false);
        copyAttribute(annotation, "catalog", element.getCatalog(), false);
        if (StringHelper.isNotEmpty(defaults.getCatalog()) && StringHelper.isEmpty((String) annotation.valueOf("catalog"))) {
            annotation.setValue("catalog", defaults.getCatalog());
        }
        copyAttribute(annotation, "schema", element.getSchema(), false);
        if (StringHelper.isNotEmpty(defaults.getSchema()) && StringHelper.isEmpty((String) annotation.valueOf("schema"))) {
            annotation.setValue("schema", defaults.getSchema());
        }
        buildUniqueConstraints(annotation, element.getUniqueConstraint());
        buildIndex(annotation, element.getIndex());
        return AnnotationFactory.create(annotation);
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbTable(org.hibernate.boot.jaxb.mapping.spi.JaxbTable) JaxbJoinTable(org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTable) Table(jakarta.persistence.Table) CollectionTable(jakarta.persistence.CollectionTable) JaxbSecondaryTable(org.hibernate.boot.jaxb.mapping.spi.JaxbSecondaryTable) JoinTable(jakarta.persistence.JoinTable) JaxbCollectionTable(org.hibernate.boot.jaxb.mapping.spi.JaxbCollectionTable) SecondaryTable(jakarta.persistence.SecondaryTable) JaxbTable(org.hibernate.boot.jaxb.mapping.spi.JaxbTable) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Example 8 with JaxbEntity

use of org.hibernate.boot.jaxb.mapping.spi.JaxbEntity in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getEntity.

private Entity getEntity(ManagedType element, XMLContext.Default defaults) {
    if (element == null) {
        return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation(Entity.class) : null;
    } else {
        if (element instanceof JaxbEntity) {
            JaxbEntity entityElement = (JaxbEntity) element;
            AnnotationDescriptor entity = new AnnotationDescriptor(Entity.class);
            copyAttribute(entity, "name", entityElement.getName(), false);
            if (defaults.canUseJavaAnnotations() && StringHelper.isEmpty((String) entity.valueOf("name"))) {
                Entity javaAnn = getPhysicalAnnotation(Entity.class);
                if (javaAnn != null) {
                    entity.setValue("name", javaAnn.name());
                }
            }
            return AnnotationFactory.create(entity);
        } else {
            // this is not an entity
            return null;
        }
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Entity(jakarta.persistence.Entity) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Example 9 with JaxbEntity

use of org.hibernate.boot.jaxb.mapping.spi.JaxbEntity in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getDiscriminatorValue.

private DiscriminatorValue getDiscriminatorValue(ManagedType root, XMLContext.Default defaults) {
    String element = root instanceof JaxbEntity ? ((JaxbEntity) root).getDiscriminatorValue() : null;
    if (element != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(DiscriminatorValue.class);
        ad.setValue("value", element);
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(DiscriminatorValue.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) DiscriminatorValue(jakarta.persistence.DiscriminatorValue) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Example 10 with JaxbEntity

use of org.hibernate.boot.jaxb.mapping.spi.JaxbEntity in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getCacheable.

private Cacheable getCacheable(ManagedType root, XMLContext.Default defaults) {
    if (root instanceof JaxbEntity) {
        Boolean attValue = ((JaxbEntity) root).isCacheable();
        if (attValue != null) {
            AnnotationDescriptor ad = new AnnotationDescriptor(Cacheable.class);
            ad.setValue("value", attValue);
            return AnnotationFactory.create(ad);
        }
    }
    if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(Cacheable.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Aggregations

JaxbEntity (org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)16 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)13 SecondaryTable (jakarta.persistence.SecondaryTable)2 JaxbMappedSuperclass (org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclass)2 JaxbPersistenceUnitDefaults (org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults)2 JaxbPersistenceUnitMetadata (org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata)2 JaxbSecondaryTable (org.hibernate.boot.jaxb.mapping.spi.JaxbSecondaryTable)2 CollectionTable (jakarta.persistence.CollectionTable)1 Convert (jakarta.persistence.Convert)1 DiscriminatorColumn (jakarta.persistence.DiscriminatorColumn)1 DiscriminatorType (jakarta.persistence.DiscriminatorType)1 DiscriminatorValue (jakarta.persistence.DiscriminatorValue)1 Entity (jakarta.persistence.Entity)1 Inheritance (jakarta.persistence.Inheritance)1 InheritanceType (jakarta.persistence.InheritanceType)1 JoinTable (jakarta.persistence.JoinTable)1 NamedEntityGraph (jakarta.persistence.NamedEntityGraph)1 NamedEntityGraphs (jakarta.persistence.NamedEntityGraphs)1 NamedNativeQueries (jakarta.persistence.NamedNativeQueries)1 NamedNativeQuery (jakarta.persistence.NamedNativeQuery)1