use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method getSelectItemsToInline.
private BitSet getSelectItemsToInline() {
final QuerySpec querySpec = (QuerySpec) getQueryPartStack().getCurrent();
final List<SqlSelection> sqlSelections = querySpec.getSelectClause().getSqlSelections();
final BitSet bitSet = new BitSet(sqlSelections.size());
for (Expression groupByClauseExpression : querySpec.getGroupByClauseExpressions()) {
final SqlSelectionExpression selectItemReference = getSelectItemReference(groupByClauseExpression);
if (selectItemReference != null) {
bitSet.set(sqlSelections.indexOf(selectItemReference.getSelection()));
}
}
return bitSet;
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class ExpressionReplacementWalker method visitInListPredicate.
@Override
public void visitInListPredicate(InListPredicate inListPredicate) {
final Expression testExpression = replaceExpression(inListPredicate.getTestExpression());
List<Expression> items = null;
final List<Expression> listExpressions = inListPredicate.getListExpressions();
for (int i = 0; i < listExpressions.size(); i++) {
final Expression listExpression = listExpressions.get(i);
final Expression newListExpression = replaceExpression(listExpression);
if (newListExpression != listExpression) {
if (items == null) {
items = new ArrayList<>(listExpressions);
}
items.set(i, newListExpression);
}
}
if (testExpression != inListPredicate.getTestExpression() || items != null) {
returnedNode = new InListPredicate(testExpression, items == null ? listExpressions : items, inListPredicate.isNegated(), inListPredicate.getExpressionType());
} else {
returnedNode = inListPredicate;
}
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class ColumnReference method apply.
@Override
public void apply(QuerySpec ast, TableGroup tableGroup, String collation, String modelPartName, SortOrder sortOrder, NullPrecedence nullPrecedence, SqlAstCreationState creationState) {
final Expression expression = resolve(ast, tableGroup, modelPartName, creationState);
// SQL Server even reports a query error in this case
if (ast.hasSortSpecifications()) {
for (SortSpecification sortSpecification : ast.getSortSpecifications()) {
if (sortSpecification.getSortExpression() == expression) {
return;
}
}
}
final Expression sortExpression = OrderingExpression.applyCollation(expression, collation, creationState);
ast.addSortSpecification(new SortSpecification(sortExpression, sortOrder, nullPrecedence));
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class SelfRenderingOrderingExpression method apply.
@Override
public void apply(QuerySpec ast, TableGroup tableGroup, String collation, String modelPartName, SortOrder sortOrder, NullPrecedence nullPrecedence, SqlAstCreationState creationState) {
final Expression expression = resolve(ast, tableGroup, modelPartName, creationState);
// SQL Server even reports a query error in this case
if (ast.hasSortSpecifications()) {
for (SortSpecification sortSpecification : ast.getSortSpecifications()) {
if (sortSpecification.getSortExpression() == expression) {
return;
}
}
}
final Expression sortExpression = OrderingExpression.applyCollation(expression, collation, creationState);
ast.addSortSpecification(new SortSpecification(sortExpression, sortOrder, nullPrecedence));
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class SimpleNaturalIdLoader method applyNaturalIdRestriction.
@Override
protected void applyNaturalIdRestriction(Object bindValue, TableGroup rootTableGroup, Consumer<Predicate> predicateConsumer, BiConsumer<JdbcParameter, JdbcParameterBinding> jdbcParameterConsumer, LoaderSqlAstCreationState sqlAstCreationState, SharedSessionContractImplementor session) {
if (bindValue == null) {
naturalIdMapping().getAttribute().forEachSelectable((index, selectable) -> {
final Expression columnReference = resolveColumnReference(rootTableGroup, selectable, sqlAstCreationState.getSqlExpressionResolver(), session.getFactory());
predicateConsumer.accept(new NullnessPredicate(columnReference));
});
} else {
naturalIdMapping().getAttribute().breakDownJdbcValues(bindValue, (jdbcValue, jdbcValueMapping) -> {
final Expression columnReference = resolveColumnReference(rootTableGroup, jdbcValueMapping, sqlAstCreationState.getSqlExpressionResolver(), session.getFactory());
if (jdbcValue == null) {
predicateConsumer.accept(new NullnessPredicate(columnReference));
} else {
final JdbcParameter jdbcParameter = new JdbcParameterImpl(jdbcValueMapping.getJdbcMapping());
final ComparisonPredicate predicate = new ComparisonPredicate(columnReference, ComparisonOperator.EQUAL, jdbcParameter);
predicateConsumer.accept(predicate);
jdbcParameterConsumer.accept(jdbcParameter, new JdbcParameterBindingImpl(jdbcValueMapping.getJdbcMapping(), jdbcValue));
}
}, session);
}
}
Aggregations