Search in sources :

Example 1 with JaxbColumnResult

use of org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResult 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)

Example 2 with JaxbColumnResult

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

the class JPAXMLOverriddenAnnotationReader method buildConstructorResult.

private static ConstructorResult buildConstructorResult(JaxbConstructorResult constructorResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
    AnnotationDescriptor constructorResultDescriptor = new AnnotationDescriptor(ConstructorResult.class);
    final Class entityClass = resolveClassReference(constructorResultElement.getTargetClass(), defaults, classLoaderAccess);
    constructorResultDescriptor.setValue("targetClass", entityClass);
    List<ColumnResult> columnResultAnnotations = new ArrayList<>();
    for (JaxbColumnResult columnResultElement : constructorResultElement.getColumn()) {
        columnResultAnnotations.add(buildColumnResult(columnResultElement, defaults, classLoaderAccess));
    }
    constructorResultDescriptor.setValue("columns", columnResultAnnotations.toArray(new ColumnResult[columnResultAnnotations.size()]));
    return AnnotationFactory.create(constructorResultDescriptor);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbColumnResult(org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResult) ArrayList(java.util.ArrayList) ColumnResult(jakarta.persistence.ColumnResult) JaxbColumnResult(org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResult) IdClass(jakarta.persistence.IdClass) MapKeyClass(jakarta.persistence.MapKeyClass) JaxbIdClass(org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass) JaxbMapKeyClass(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyClass)

Aggregations

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