use of jakarta.persistence.EntityResult 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);
}
use of jakarta.persistence.EntityResult 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;
}
Aggregations