use of org.hibernate.query.results.ResultSetMappingSqlSelection 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.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class CompleteResultBuilderBasicValuedStandard method buildResult.
@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
final DomainResultCreationStateImpl creationStateImpl = impl(domainResultCreationState);
final SessionFactoryImplementor sessionFactory = creationStateImpl.getSessionFactory();
final String columnName;
if (explicitColumnName != null) {
columnName = explicitColumnName;
} else {
columnName = jdbcResultsMetadata.resolveColumnName(resultPosition + 1);
}
// final int jdbcPosition;
// if ( explicitColumnName != null ) {
// jdbcPosition = jdbcResultsMetadata.resolveColumnPosition( explicitColumnName );
// }
// else {
// jdbcPosition = resultPosition + 1;
// }
//
// final BasicValuedMapping basicType;
// if ( explicitType != null ) {
// basicType = explicitType;
// }
// else {
// basicType = jdbcResultsMetadata.resolveType( jdbcPosition, explicitJavaType );
// }
//
// final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(
// creationStateImpl.resolveSqlExpression(
// columnName,
// processingState -> {
// final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition( jdbcPosition );
// return new SqlSelectionImpl( valuesArrayPosition, basicType );
// }
// ),
// basicType.getExpressibleJavaType(),
// sessionFactory.getTypeConfiguration()
// );
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(columnName, processingState -> {
final int jdbcPosition;
if (explicitColumnName != null) {
jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(explicitColumnName);
} else {
jdbcPosition = resultPosition + 1;
}
final BasicValuedMapping basicType;
if (explicitType != null) {
basicType = explicitType;
} else {
basicType = jdbcResultsMetadata.resolveType(jdbcPosition, explicitJavaType, sessionFactory);
}
final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
return new ResultSetMappingSqlSelection(valuesArrayPosition, basicType);
}), explicitJavaType, sessionFactory.getTypeConfiguration());
return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnName, sqlSelection.getExpressionType().getJdbcMappings().get(0).getMappedJavaType());
}
use of org.hibernate.query.results.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class CompleteResultBuilderCollectionStandard method resolveSelections.
private void resolveSelections(TableGroup tableGroup, ModelPart modelPart, String[] columnNames, JdbcValuesMetadata jdbcResultsMetadata, DomainResultCreationStateImpl creationStateImpl) {
final SelectableConsumer consumer = (selectionIndex, selectableMapping) -> {
final String columnName = columnNames[selectionIndex];
creationStateImpl.resolveSqlSelection(creationStateImpl.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableGroup.resolveTableReference(selectableMapping.getContainingTableExpression()), selectableMapping.getSelectionExpression()), processingState -> {
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnName);
final BasicValuedMapping basicType = (BasicValuedMapping) selectableMapping.getJdbcMapping();
final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
return new ResultSetMappingSqlSelection(valuesArrayPosition, basicType);
}), selectableMapping.getJdbcMapping().getMappedJavaType(), creationStateImpl.getSessionFactory().getTypeConfiguration());
};
if (modelPart instanceof EntityValuedModelPart) {
final EntityMappingType entityMappingType = ((EntityValuedModelPart) modelPart).getEntityMappingType();
int index = entityMappingType.getIdentifierMapping().forEachSelectable(consumer);
if (entityMappingType.getDiscriminatorMapping() != null) {
index += entityMappingType.getDiscriminatorMapping().forEachSelectable(index, consumer);
}
entityMappingType.forEachSelectable(index, consumer);
} else {
modelPart.forEachSelectable(consumer);
}
}
use of org.hibernate.query.results.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class CompleteFetchBuilderBasicPart method buildFetch.
@Override
public BasicFetch<?> buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
final DomainResultCreationStateImpl creationState = impl(domainResultCreationState);
final String mappedTable = referencedModelPart.getContainingTableExpression();
final String mappedColumn = referencedModelPart.getSelectionExpression();
final TableGroup tableGroup = creationState.getFromClauseAccess().getTableGroup(parent.getNavigablePath());
final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, mappedTable);
final String selectedAlias;
final int jdbcPosition;
if (selectionAlias != null) {
try {
jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(selectionAlias);
} catch (Exception e) {
throw new MissingSqlSelectionException("ResultSet mapping specified selected-alias `" + selectionAlias + "` which was not part of the ResultSet", e);
}
selectedAlias = selectionAlias;
} else {
if (!creationState.arePositionalSelectionsAllowed()) {
throw new PositionalSelectionsNotAllowedException("Positional SQL selection resolution not allowed");
}
jdbcPosition = creationState.getNumberOfProcessedSelections();
selectedAlias = jdbcResultsMetadata.resolveColumnName(jdbcPosition);
}
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition(jdbcPosition);
// we just care about the registration here. The ModelPart will find it later
creationState.resolveSqlExpression(createColumnReferenceKey(tableReference, mappedColumn), processingState -> new ResultSetMappingSqlSelection(valuesArrayPosition, referencedModelPart));
return (BasicFetch<?>) parent.generateFetchableFetch(referencedModelPart, fetchPath, FetchTiming.IMMEDIATE, true, selectedAlias, domainResultCreationState);
}
use of org.hibernate.query.results.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class CompleteFetchBuilderEntityValuedModelPart 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.DELAYED, true, null, domainResultCreationState);
}
Aggregations