use of org.hibernate.query.results.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class CompleteResultBuilderBasicValuedConverted 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 int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
return new ResultSetMappingSqlSelection(valuesArrayPosition, underlyingMapping);
}), valueConverter.getDomainJavaType(), sessionFactory.getTypeConfiguration());
return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnName, valueConverter.getDomainJavaType(), valueConverter);
}
use of org.hibernate.query.results.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class ImplicitFetchBuilderBasic method buildFetch.
@Override
public BasicFetch<?> buildFetch(FetchParent parent, NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
final TableGroup parentTableGroup = creationStateImpl.getFromClauseAccess().getTableGroup(parent.getNavigablePath());
final String table = fetchable.getContainingTableExpression();
final String column;
// In case of a formula we look for a result set position with the fetchable name
if (fetchable.isFormula()) {
column = fetchable.getFetchableName();
} else {
column = fetchable.getSelectionExpression();
}
final Expression expression = creationStateImpl.resolveSqlExpression(createColumnReferenceKey(parentTableGroup.resolveTableReference(fetchPath, table), fetchable.getSelectionExpression()), processingState -> {
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(column);
final int valuesArrayPosition = jdbcPositionToValuesArrayPosition(jdbcPosition);
return new ResultSetMappingSqlSelection(valuesArrayPosition, fetchable);
});
final SqlSelection sqlSelection = creationStateImpl.resolveSqlSelection(expression, fetchable.getJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
final BasicValueConverter<?, ?> valueConverter;
if (fetchable instanceof ConvertibleModelPart) {
valueConverter = ((ConvertibleModelPart) fetchable).getValueConverter();
} else {
valueConverter = null;
}
return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), parent, fetchPath, fetchable, valueConverter, FetchTiming.IMMEDIATE, domainResultCreationState);
}
use of org.hibernate.query.results.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class DynamicResultBuilderAttribute method buildResult.
@Override
public DomainResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
// todo (6.0) : TableGroups + `attributeMapping#buldResult`
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(columnAlias, state -> {
final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
final int valuesArrayPosition = resultSetPosition - 1;
return new ResultSetMappingSqlSelection(valuesArrayPosition, attributeMapping);
}), attributeMapping.getJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnAlias, attributeMapping.getJavaType(), attributeMapping.getValueConverter());
}
use of org.hibernate.query.results.ResultSetMappingSqlSelection in project hibernate-orm by hibernate.
the class DynamicResultBuilderBasicStandard method buildResult.
@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
final SessionFactoryImplementor sessionFactory = domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory();
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
final Expression expression = sqlExpressionResolver.resolveSqlExpression(columnName, state -> {
final int jdbcPosition;
if (columnPosition > 0) {
jdbcPosition = columnPosition;
} else {
jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnName);
}
final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
final BasicType<?> basicType;
if (explicitType != null) {
basicType = explicitType;
} else {
basicType = jdbcResultsMetadata.resolveType(jdbcPosition, explicitJavaType, sessionFactory);
}
return new ResultSetMappingSqlSelection(valuesArrayPosition, (BasicValuedMapping) basicType);
});
final JavaType<?> javaType;
if (explicitJavaType != null) {
javaType = explicitJavaType;
} else {
javaType = expression.getExpressionType().getJdbcMappings().get(0).getMappedJavaType();
}
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(expression, javaType, sessionFactory.getTypeConfiguration());
// StandardRowReader expects there to be a JavaType as part of the ResultAssembler.
assert javaType != null;
return new BasicResult<>(sqlSelection.getValuesArrayPosition(), resultAlias, javaType);
}
Aggregations