use of org.hibernate.sql.ast.spi.SqlSelection in project hibernate-orm by hibernate.
the class SimpleForeignKeyDescriptor method createDomainResult.
private <T> DomainResult<T> createDomainResult(NavigablePath navigablePath, TableGroup tableGroup, SelectableMapping selectableMapping, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final TableReference tableReference = tableGroup.resolveTableReference(navigablePath.append(getTargetPart().getFetchableName()), selectableMapping.getContainingTableExpression());
final String identificationVariable = tableReference.getIdentificationVariable();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, selectableMapping.getSelectionExpression()), s -> new ColumnReference(identificationVariable, selectableMapping, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory())), selectableMapping.getJdbcMapping().getJavaTypeDescriptor(), sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
// noinspection unchecked
return new BasicResult<T>(sqlSelection.getValuesArrayPosition(), null, selectableMapping.getJdbcMapping().getJavaTypeDescriptor());
}
use of org.hibernate.sql.ast.spi.SqlSelection 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.sql.ast.spi.SqlSelection 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.sql.ast.spi.SqlSelection 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.sql.ast.spi.SqlSelection 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());
}
Aggregations