use of org.hibernate.sql.ast.spi.SqlExpressionResolver in project hibernate-orm by hibernate.
the class BasicAttributeMapping method resolveSqlSelection.
private SqlSelection resolveSqlSelection(NavigablePath navigablePath, TableGroup tableGroup, boolean allowFkOptimization, DomainResultCreationState creationState) {
final SqlExpressionResolver expressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, getContainingTableExpression(), allowFkOptimization);
return expressionResolver.resolveSqlSelection(expressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumnExpression), sqlAstProcessingState -> new ColumnReference(tableReference, this, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory())), valueConverter == null ? getMappedType().getMappedJavaType() : valueConverter.getRelationalJavaType(), creationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
}
use of org.hibernate.sql.ast.spi.SqlExpressionResolver in project hibernate-orm by hibernate.
the class CollectionIdentifierDescriptorImpl method generateFetch.
@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
// get the collection TableGroup
final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess();
final TableGroup tableGroup = fromClauseAccess.getTableGroup(fetchablePath.getParent());
final SqlAstCreationState astCreationState = creationState.getSqlAstCreationState();
final SqlAstCreationContext astCreationContext = astCreationState.getCreationContext();
final SessionFactoryImplementor sessionFactory = astCreationContext.getSessionFactory();
final SqlExpressionResolver sqlExpressionResolver = astCreationState.getSqlExpressionResolver();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableGroup.getPrimaryTableReference(), columnName), p -> new ColumnReference(tableGroup.getPrimaryTableReference().getIdentificationVariable(), columnName, false, null, null, type, sessionFactory)), type.getJavaTypeDescriptor(), sessionFactory.getTypeConfiguration());
return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, FetchTiming.IMMEDIATE, creationState);
}
use of org.hibernate.sql.ast.spi.SqlExpressionResolver in project hibernate-orm by hibernate.
the class CollectionIdentifierDescriptorImpl method createDomainResult.
public DomainResult<?> createDomainResult(NavigablePath collectionPath, TableGroup tableGroup, DomainResultCreationState creationState) {
final SqlAstCreationState astCreationState = creationState.getSqlAstCreationState();
final SqlAstCreationContext astCreationContext = astCreationState.getCreationContext();
final SessionFactoryImplementor sessionFactory = astCreationContext.getSessionFactory();
final SqlExpressionResolver sqlExpressionResolver = astCreationState.getSqlExpressionResolver();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableGroup.getPrimaryTableReference(), columnName), p -> new ColumnReference(tableGroup.getPrimaryTableReference().getIdentificationVariable(), columnName, false, null, null, type, sessionFactory)), type.getJavaTypeDescriptor(), sessionFactory.getTypeConfiguration());
// noinspection unchecked
return new BasicResult<>(sqlSelection.getValuesArrayPosition(), null, (JavaType<Object>) type.getJavaTypeDescriptor(), collectionPath);
}
use of org.hibernate.sql.ast.spi.SqlExpressionResolver in project hibernate-orm by hibernate.
the class DynamicResultBuilderBasicConverted method buildResult.
@Override
public BasicResult<?> buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
final TypeConfiguration typeConfiguration = domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration();
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(columnAlias, state -> {
final int currentJdbcPosition = resultPosition + 1;
final int jdbcPosition;
if (columnAlias != null) {
jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
} else {
jdbcPosition = currentJdbcPosition;
}
final BasicType<?> basicType = jdbcResultsMetadata.resolveType(jdbcPosition, basicValueConverter.getRelationalJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory());
final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
return new ResultSetMappingSqlSelection(valuesArrayPosition, (BasicValuedMapping) basicType);
}), basicValueConverter.getDomainJavaType(), typeConfiguration);
return new BasicResult<>(sqlSelection.getValuesArrayPosition(), columnAlias, basicValueConverter.getDomainJavaType(), basicValueConverter);
}
use of org.hibernate.sql.ast.spi.SqlExpressionResolver in project hibernate-orm by hibernate.
the class DynamicResultBuilderEntityStandard method resolveSqlSelection.
private void resolveSqlSelection(String columnAlias, String columnKey, JdbcMapping jdbcMapping, JdbcValuesMetadata jdbcResultsMetadata, DomainResultCreationState domainResultCreationState) {
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(columnKey, state -> {
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnAlias);
final int valuesArrayPosition = jdbcPosition - 1;
return new ResultSetMappingSqlSelection(valuesArrayPosition, jdbcMapping);
}), jdbcMapping.getMappedJavaType(), domainResultCreationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
}
Aggregations