use of org.hibernate.query.sqm.sql.internal.AbstractSqmPathInterpretation in project hibernate-orm by hibernate.
the class CountFunction method canReplaceWithStar.
private boolean canReplaceWithStar(SqlAstNode arg, SqlAstTranslator<?> translator) {
// To determine if we can replace the argument with a star, we must know if the argument is nullable
if (arg instanceof AbstractSqmPathInterpretation<?>) {
final AbstractSqmPathInterpretation<?> pathInterpretation = (AbstractSqmPathInterpretation<?>) arg;
final TableGroup tableGroup = pathInterpretation.getTableGroup();
final Expression sqlExpression = pathInterpretation.getSqlExpression();
final JdbcMappingContainer expressionType = sqlExpression.getExpressionType();
// The entity identifier mapping is always considered non-nullable
final boolean isNonNullable = expressionType instanceof EntityIdentifierMapping;
// But we also have to check if it contains joins that could alter the nullability (RIGHT or FULL)
if (isNonNullable && tableGroup.canUseInnerJoins() && !hasJoinsAlteringNullability(tableGroup)) {
// COUNT can only be used in query specs as query groups can only refer positionally in the order by
final QuerySpec querySpec = (QuerySpec) translator.getCurrentQueryPart();
// On top of this, we also have to ensure that there are no neighbouring joins that alter nullability
for (TableGroup root : querySpec.getFromClause().getRoots()) {
final Boolean result = hasNeighbouringJoinsAlteringNullability(root, tableGroup);
if (result != null) {
return !result;
}
}
return true;
}
}
return false;
}
Aggregations