use of org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy in project hibernate-orm by hibernate.
the class NativeQueryImpl method addFetch.
@Override
public FetchReturn addFetch(String tableAlias, String ownerTableAlias, String joinPropertyName) {
final DynamicFetchBuilderLegacy fetchBuilder = Builders.fetch(tableAlias, ownerTableAlias, joinPropertyName);
resultSetMapping.addLegacyFetchBuilder(fetchBuilder);
return fetchBuilder;
}
use of org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy 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.DynamicFetchBuilderLegacy in project hibernate-orm by hibernate.
the class CompleteResultBuilderBasicModelPart method buildResult.
@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
final DomainResultCreationStateImpl creationStateImpl = impl(domainResultCreationState);
final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, modelPart.getContainingTableExpression());
final String mappedColumn = modelPart.getSelectionExpression();
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumn), processingState -> {
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition(jdbcPosition);
return new ResultSetMappingSqlSelection(valuesArrayPosition, modelPart);
}), modelPart.getJavaType(), creationStateImpl.getSessionFactory().getTypeConfiguration());
// noinspection unchecked
return new BasicResult(sqlSelection.getValuesArrayPosition(), columnAlias, modelPart.getJavaType());
}
use of org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy in project hibernate-orm by hibernate.
the class CompleteFetchBuilderEmbeddableValuedModelPart method buildFetch.
@Override
public Fetch buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
assert fetchPath.equals(navigablePath);
final DomainResultCreationStateImpl creationStateImpl = impl(domainResultCreationState);
final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
modelPart.forEachSelectable((selectionIndex, selectableMapping) -> {
final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, selectableMapping.getContainingTableExpression());
final String mappedColumn = selectableMapping.getSelectionExpression();
final String columnAlias = columnAliases.get(selectionIndex);
creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumn), processingState -> {
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition(jdbcPosition);
return new ResultSetMappingSqlSelection(valuesArrayPosition, selectableMapping.getJdbcMapping());
}), modelPart.getJavaType(), creationStateImpl.getSessionFactory().getTypeConfiguration());
});
return parent.generateFetchableFetch(modelPart, fetchPath, FetchTiming.IMMEDIATE, true, null, domainResultCreationState);
}
use of org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy in project hibernate-orm by hibernate.
the class ResultSetMappingImpl method addLegacyFetchBuilder.
@Override
public void addLegacyFetchBuilder(DynamicFetchBuilderLegacy fetchBuilder) {
final Map<String, DynamicFetchBuilderLegacy> existingFetchBuildersByOwner;
if (legacyFetchBuilders == null) {
legacyFetchBuilders = new HashMap<>();
existingFetchBuildersByOwner = null;
} else {
existingFetchBuildersByOwner = legacyFetchBuilders.get(fetchBuilder.getOwnerAlias());
}
final Map<String, DynamicFetchBuilderLegacy> fetchBuildersByOwner;
if (existingFetchBuildersByOwner == null) {
fetchBuildersByOwner = new HashMap<>();
legacyFetchBuilders.put(fetchBuilder.getOwnerAlias(), fetchBuildersByOwner);
} else {
fetchBuildersByOwner = existingFetchBuildersByOwner;
}
final DynamicFetchBuilderLegacy previousBuilder = fetchBuildersByOwner.put(fetchBuilder.getFetchableName(), fetchBuilder);
if (previousBuilder != null) {
// todo (6.0) : error? log? nothing?
}
}
Aggregations