Search in sources :

Example 1 with JaxbEntityResult

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

the class JPAXMLOverriddenAnnotationReader method buildSqlResultsetMappings.

public static List<SqlResultSetMapping> buildSqlResultsetMappings(List<JaxbSqlResultSetMapping> elements, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    final List<SqlResultSetMapping> builtResultSetMappings = new ArrayList<>();
    // iterate over each <sql-result-set-mapping/> element
    for (JaxbSqlResultSetMapping resultSetMappingElement : elements) {
        final AnnotationDescriptor resultSetMappingAnnotation = new AnnotationDescriptor(SqlResultSetMapping.class);
        copyAttribute(resultSetMappingAnnotation, "name", resultSetMappingElement.getName(), true);
        // iterate over the <sql-result-set-mapping/> sub-elements, which should include:
        // * <entity-result/>
        // * <column-result/>
        // * <constructor-result/>
        List<EntityResult> entityResultAnnotations = null;
        List<ColumnResult> columnResultAnnotations = null;
        List<ConstructorResult> constructorResultAnnotations = null;
        for (JaxbEntityResult resultElement : resultSetMappingElement.getEntityResult()) {
            if (entityResultAnnotations == null) {
                entityResultAnnotations = new ArrayList<>();
            }
            // process the <entity-result/>
            entityResultAnnotations.add(buildEntityResult(resultElement, defaults, classLoaderAccess));
        }
        for (JaxbColumnResult resultElement : resultSetMappingElement.getColumnResult()) {
            if (columnResultAnnotations == null) {
                columnResultAnnotations = new ArrayList<>();
            }
            columnResultAnnotations.add(buildColumnResult(resultElement, defaults, classLoaderAccess));
        }
        for (JaxbConstructorResult resultElement : resultSetMappingElement.getConstructorResult()) {
            if (constructorResultAnnotations == null) {
                constructorResultAnnotations = new ArrayList<>();
            }
            constructorResultAnnotations.add(buildConstructorResult(resultElement, defaults, classLoaderAccess));
        }
        if (entityResultAnnotations != null && !entityResultAnnotations.isEmpty()) {
            resultSetMappingAnnotation.setValue("entities", entityResultAnnotations.toArray(new EntityResult[entityResultAnnotations.size()]));
        }
        if (columnResultAnnotations != null && !columnResultAnnotations.isEmpty()) {
            resultSetMappingAnnotation.setValue("columns", columnResultAnnotations.toArray(new ColumnResult[columnResultAnnotations.size()]));
        }
        if (constructorResultAnnotations != null && !constructorResultAnnotations.isEmpty()) {
            resultSetMappingAnnotation.setValue("classes", constructorResultAnnotations.toArray(new ConstructorResult[constructorResultAnnotations.size()]));
        }
        builtResultSetMappings.add(AnnotationFactory.create(resultSetMappingAnnotation));
    }
    return builtResultSetMappings;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbColumnResult(org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResult) JaxbSqlResultSetMapping(org.hibernate.boot.jaxb.mapping.spi.JaxbSqlResultSetMapping) ArrayList(java.util.ArrayList) EntityResult(jakarta.persistence.EntityResult) JaxbEntityResult(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResult) ConstructorResult(jakarta.persistence.ConstructorResult) JaxbConstructorResult(org.hibernate.boot.jaxb.mapping.spi.JaxbConstructorResult) JaxbConstructorResult(org.hibernate.boot.jaxb.mapping.spi.JaxbConstructorResult) ColumnResult(jakarta.persistence.ColumnResult) JaxbColumnResult(org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResult) JaxbEntityResult(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResult) SqlResultSetMapping(jakarta.persistence.SqlResultSetMapping) JaxbSqlResultSetMapping(org.hibernate.boot.jaxb.mapping.spi.JaxbSqlResultSetMapping)

Aggregations

ColumnResult (jakarta.persistence.ColumnResult)1 ConstructorResult (jakarta.persistence.ConstructorResult)1 EntityResult (jakarta.persistence.EntityResult)1 SqlResultSetMapping (jakarta.persistence.SqlResultSetMapping)1 ArrayList (java.util.ArrayList)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 JaxbColumnResult (org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResult)1 JaxbConstructorResult (org.hibernate.boot.jaxb.mapping.spi.JaxbConstructorResult)1 JaxbEntityResult (org.hibernate.boot.jaxb.mapping.spi.JaxbEntityResult)1 JaxbSqlResultSetMapping (org.hibernate.boot.jaxb.mapping.spi.JaxbSqlResultSetMapping)1