use of org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard in project hibernate-orm by hibernate.
the class ResultSetMappingProcessor method generateResultMapping.
public ResultSetMapping generateResultMapping(boolean queryHadAliases) {
if (!queryHadAliases) {
return this.resultSetMapping;
}
final ResultSetMappingImpl resultSetMapping = new ResultSetMappingImpl(null);
final Set<String> visited = new HashSet<>();
this.resultSetMapping.visitResultBuilders((i, resultBuilder) -> {
if (resultBuilder instanceof NativeQuery.RootReturn) {
final NativeQuery.RootReturn rootReturn = (NativeQuery.RootReturn) resultBuilder;
final String suffix = alias2Suffix.get(rootReturn.getTableAlias());
visited.add(rootReturn.getTableAlias());
if (suffix == null) {
resultSetMapping.addResultBuilder(resultBuilder);
} else {
final DynamicResultBuilderEntityStandard resultBuilderEntity = createSuffixedResultBuilder(rootReturn, suffix);
resultSetMapping.addResultBuilder(resultBuilderEntity);
alias2Return.put(rootReturn.getTableAlias(), resultBuilderEntity);
}
} else if (resultBuilder instanceof NativeQuery.CollectionReturn) {
final NativeQuery.CollectionReturn collectionReturn = (NativeQuery.CollectionReturn) resultBuilder;
final String suffix = alias2CollectionSuffix.get(collectionReturn.getTableAlias());
if (suffix == null) {
resultSetMapping.addResultBuilder(resultBuilder);
} else {
final CompleteResultBuilderCollectionStandard resultBuilderCollection = createSuffixedResultBuilder(collectionReturn, suffix, alias2Suffix.get(collectionReturn.getTableAlias()));
resultSetMapping.addResultBuilder(resultBuilderCollection);
alias2Return.put(collectionReturn.getTableAlias(), resultBuilderCollection);
}
} else {
resultSetMapping.addResultBuilder(resultBuilder);
}
});
this.resultSetMapping.visitLegacyFetchBuilders(fetchBuilder -> applyFetchBuilder(resultSetMapping, fetchBuilder, visited));
return resultSetMapping;
}
use of org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard in project hibernate-orm by hibernate.
the class NativeQueryImpl method addRoot.
@Override
public DynamicResultBuilderEntityStandard addRoot(String tableAlias, String entityName) {
final DynamicResultBuilderEntityStandard resultBuilder = Builders.entity(tableAlias, entityName, getSessionFactory());
resultSetMapping.addResultBuilder(resultBuilder);
return resultBuilder;
}
use of org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard in project hibernate-orm by hibernate.
the class ResultSetMappingProcessor method createSuffixedResultBuilder.
private DynamicResultBuilderEntityStandard createSuffixedResultBuilder(EntityMappingType entityMapping, String tableAlias, String suffix, LockMode lockMode, NavigablePath navigablePath) {
final SQLLoadable loadable = (SQLLoadable) entityMapping.getEntityPersister();
final DynamicResultBuilderEntityStandard resultBuilderEntity = new DynamicResultBuilderEntityStandard(entityMapping, tableAlias, navigablePath);
resultBuilderEntity.setLockMode(lockMode);
final String[] identifierAliases = loadable.getIdentifierAliases(suffix);
resultBuilderEntity.addIdColumnAliases(identifierAliases);
resultBuilderEntity.setDiscriminatorAlias(loadable.getDiscriminatorAlias(suffix));
if (loadable.hasIdentifierProperty()) {
resultBuilderEntity.addProperty(loadable.getIdentifierPropertyName(), identifierAliases);
}
for (String propertyName : loadable.getPropertyNames()) {
final String[] columnAliases = loadable.getSubclassPropertyColumnAliases(propertyName, suffix);
final Type propertyType = loadable.getPropertyType(propertyName);
addFetchBuilder(suffix, loadable, resultBuilderEntity, tableAlias, identifierAliases, propertyName, columnAliases, propertyType);
}
return resultBuilderEntity;
}
use of org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard in project hibernate-orm by hibernate.
the class FetchMementoHbmStandard method resolve.
@Override
public FetchBuilder resolve(Parent parent, Consumer<String> querySpaceConsumer, ResultSetMappingResolutionContext context) {
final Map<String, FetchBuilder> fetchBuilderMap = new HashMap<>();
fetchMementoMap.forEach((attrName, fetchMemento) -> fetchBuilderMap.put(attrName, fetchMemento.resolve(this, querySpaceConsumer, context)));
final DynamicResultBuilderEntityStandard resultBuilder;
if (fetchable instanceof PluralAttributeMapping) {
resultBuilder = new DynamicResultBuilderEntityStandard((EntityMappingType) ((PluralAttributeMapping) fetchable).getElementDescriptor().getPartMappingType(), tableAlias, navigablePath);
FetchBuilder element = fetchBuilderMap.get("element");
if (element != null) {
if (element instanceof DynamicFetchBuilder) {
resultBuilder.addIdColumnAliases(((DynamicFetchBuilder) element).getColumnAliases().toArray(new String[0]));
} else {
resultBuilder.addIdColumnAliases(((CompleteFetchBuilderEntityValuedModelPart) element).getColumnAliases().toArray(new String[0]));
}
}
FetchBuilder index = fetchBuilderMap.get("index");
if (index != null) {
resultBuilder.addFetchBuilder(CollectionPart.Nature.INDEX.getName(), index);
}
for (Map.Entry<String, FetchBuilder> entry : fetchBuilderMap.entrySet()) {
if (entry.getKey().startsWith(ELEMENT_PREFIX)) {
resultBuilder.addFetchBuilder(entry.getKey().substring(ELEMENT_PREFIX.length()), entry.getValue());
}
}
} else {
resultBuilder = new DynamicResultBuilderEntityStandard(((ToOneAttributeMapping) fetchable).getEntityMappingType(), tableAlias, navigablePath);
fetchBuilderMap.forEach(resultBuilder::addFetchBuilder);
}
return new DynamicFetchBuilderLegacy(tableAlias, ownerTableAlias, fetchable.getFetchableName(), keyColumnNames, fetchBuilderMap, resultBuilder);
}
use of org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard in project hibernate-orm by hibernate.
the class Builders method entity.
/**
* Creates a EntityResultBuilder allowing for further configuring of the mapping.
*/
public static DynamicResultBuilderEntityStandard entity(String tableAlias, String entityName, SessionFactoryImplementor sessionFactory) {
final RuntimeMetamodels runtimeMetamodels = sessionFactory.getRuntimeMetamodels();
final EntityMappingType entityMapping = runtimeMetamodels.getEntityMappingType(entityName);
return new DynamicResultBuilderEntityStandard(entityMapping, tableAlias);
}
Aggregations