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