use of org.hibernate.sql.results.graph.basic.BasicFetch 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(), parent, 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.results.graph.basic.BasicFetch in project hibernate-orm by hibernate.
the class AnyDiscriminatorPart method generateFetch.
@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final SessionFactoryImplementor sessionFactory = sqlAstCreationState.getCreationContext().getSessionFactory();
final FromClauseAccess fromClauseAccess = sqlAstCreationState.getFromClauseAccess();
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final TableGroup tableGroup = fromClauseAccess.getTableGroup(fetchablePath.getParent().getParent());
final TableReference tableReference = tableGroup.resolveTableReference(fetchablePath, table);
final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, column), processingState -> new ColumnReference(tableReference, column, false, null, null, jdbcMapping(), sessionFactory));
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(columnReference, jdbcMapping().getMappedJavaType(), fetchParent, sessionFactory.getTypeConfiguration());
return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
use of org.hibernate.sql.results.graph.basic.BasicFetch in project hibernate-orm by hibernate.
the class AnyKeyPart method generateFetch.
@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess();
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
final SessionFactoryImplementor sessionFactory = creationState.getSqlAstCreationState().getCreationContext().getSessionFactory();
final TableGroup tableGroup = fromClauseAccess.getTableGroup(fetchParent.getNavigablePath().getParent());
final TableReference tableReference = tableGroup.resolveTableReference(fetchablePath, table);
final Expression columnReference = sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, column), processingState -> new ColumnReference(tableReference, column, false, null, null, jdbcMapping, sessionFactory));
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(columnReference, getJavaType(), fetchParent, sessionFactory.getTypeConfiguration());
return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
use of org.hibernate.sql.results.graph.basic.BasicFetch in project hibernate-orm by hibernate.
the class BasicValuedCollectionPart method generateFetch.
@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
ResultsLogger.RESULTS_LOGGER.debugf("Generating Fetch for collection-part : `%s` -> `%s`", collectionDescriptor.getRole(), nature.getName());
NavigablePath parentNavigablePath = fetchablePath.getParent();
if (parentNavigablePath instanceof EntityIdentifierNavigablePath) {
parentNavigablePath = parentNavigablePath.getParent();
}
final TableGroup tableGroup = creationState.getSqlAstCreationState().getFromClauseAccess().findTableGroup(parentNavigablePath);
final SqlSelection sqlSelection = resolveSqlSelection(fetchablePath, tableGroup, true, fetchParent, creationState);
return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, valueConverter, FetchTiming.IMMEDIATE, creationState);
}
use of org.hibernate.sql.results.graph.basic.BasicFetch in project hibernate-orm by hibernate.
the class AbstractDiscriminatorMapping method generateFetch.
@Override
public BasicFetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().getTableGroup(fetchParent.getNavigablePath());
assert tableGroup != null;
final SqlSelection sqlSelection = resolveSqlSelection(fetchablePath, getUnderlyingJdbcMappingType(), tableGroup, fetchParent, creationState.getSqlAstCreationState());
return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
Aggregations