Search in sources :

Example 1 with ColumnResult

use of jakarta.persistence.ColumnResult in project hibernate-orm by hibernate.

the class SqlResultSetMappingDescriptor method from.

// todo (6.0) : we can probably reuse the NamedResultSetMappingDefinition
// implementation between HBM and annotation handling.  We'd
// just need different "builders" for each source and handle the
// variances in those builders.  But once we have a
// NamedResultSetMappingDefinition and all of its sub-parts,
// resolving to a memento is the same
// -
// additionally, consider having the sub-parts (the return
// representations) be what is used and handed to the
// NamedResultSetMappingMemento directly.  They simply need
// to be capable of resolving themselves into ResultBuilders
// (`org.hibernate.query.results.ResultBuilder`) as part of the
// memento for its resolution
@SuppressWarnings("ForLoopReplaceableByForEach")
public static SqlResultSetMappingDescriptor from(SqlResultSetMapping mappingAnnotation, MetadataBuildingContext context) {
    final EntityResult[] entityResults = mappingAnnotation.entities();
    final ConstructorResult[] constructorResults = mappingAnnotation.classes();
    final ColumnResult[] columnResults = mappingAnnotation.columns();
    final List<ResultDescriptor> resultDescriptors = CollectionHelper.arrayList(entityResults.length + columnResults.length + columnResults.length);
    for (int i = 0; i < entityResults.length; i++) {
        final EntityResult entityResult = entityResults[i];
        resultDescriptors.add(new EntityResultDescriptor(entityResult, mappingAnnotation, context));
    }
    for (int i = 0; i < constructorResults.length; i++) {
        final ConstructorResult constructorResult = constructorResults[i];
        resultDescriptors.add(new ConstructorResultDescriptor(constructorResult, mappingAnnotation));
    }
    for (int i = 0; i < columnResults.length; i++) {
        final ColumnResult columnResult = columnResults[i];
        resultDescriptors.add(new JpaColumnResultDescriptor(columnResult, mappingAnnotation));
    }
    return new SqlResultSetMappingDescriptor(mappingAnnotation.name(), resultDescriptors, context);
}
Also used : EntityResult(jakarta.persistence.EntityResult) ConstructorResult(jakarta.persistence.ConstructorResult) ColumnResult(jakarta.persistence.ColumnResult)

Example 2 with ColumnResult

use of jakarta.persistence.ColumnResult 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 3 with ColumnResult

use of jakarta.persistence.ColumnResult 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)3 ConstructorResult (jakarta.persistence.ConstructorResult)2 EntityResult (jakarta.persistence.EntityResult)2 ArrayList (java.util.ArrayList)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbColumnResult (org.hibernate.boot.jaxb.mapping.spi.JaxbColumnResult)2 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