use of org.hibernate.sql.ast.tree.expression.SqlTuple in project hibernate-orm by hibernate.
the class EmbeddedCollectionPart method toSqlExpression.
@Override
public SqlTuple toSqlExpression(TableGroup tableGroup, Clause clause, SqmToSqlAstConverter walker, SqlAstCreationState sqlAstCreationState) {
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final List<Expression> expressions = new ArrayList<>();
getEmbeddableTypeDescriptor().forEachSelectable((columnIndex, selection) -> {
assert containingTableExpression.equals(selection.getContainingTableExpression());
final TableReference tableReference = tableGroup.resolveTableReference(tableGroup.getNavigablePath().append(getNavigableRole().getNavigableName()), selection.getContainingTableExpression());
expressions.add(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, selection.getSelectionExpression()), sqlAstProcessingState -> new ColumnReference(tableReference, selection, sqlAstCreationState.getCreationContext().getSessionFactory())));
});
return new SqlTuple(expressions, this);
}
use of org.hibernate.sql.ast.tree.expression.SqlTuple in project hibernate-orm by hibernate.
the class H2SqlAstTranslator method visitInSubQueryPredicate.
@Override
public void visitInSubQueryPredicate(InSubQueryPredicate inSubQueryPredicate) {
final SqlTuple lhsTuple;
// As of 1.4.200 this is supported
if (getDialect().getVersion().isBefore(1, 4, 200) && (lhsTuple = SqlTupleContainer.getSqlTuple(inSubQueryPredicate.getTestExpression())) != null && lhsTuple.getExpressions().size() != 1) {
inSubQueryPredicate.getTestExpression().accept(this);
if (inSubQueryPredicate.isNegated()) {
appendSql(" not");
}
appendSql(" in");
final boolean renderAsArray = this.renderAsArray;
this.renderAsArray = true;
inSubQueryPredicate.getSubQuery().accept(this);
this.renderAsArray = renderAsArray;
} else {
super.visitInSubQueryPredicate(inSubQueryPredicate);
}
}
use of org.hibernate.sql.ast.tree.expression.SqlTuple in project hibernate-orm by hibernate.
the class AbstractCompositeIdentifierMapping method toSqlExpression.
@Override
public SqlTuple toSqlExpression(TableGroup tableGroup, Clause clause, SqmToSqlAstConverter walker, SqlAstCreationState sqlAstCreationState) {
final SelectableMappings selectableMappings = getEmbeddableTypeDescriptor();
final List<ColumnReference> columnReferences = CollectionHelper.arrayList(selectableMappings.getJdbcTypeCount());
final NavigablePath navigablePath = tableGroup.getNavigablePath().append(getNavigableRole().getNavigableName());
final TableReference defaultTableReference = tableGroup.resolveTableReference(navigablePath, getContainingTableExpression());
getEmbeddableTypeDescriptor().forEachSelectable((columnIndex, selection) -> {
final TableReference tableReference = defaultTableReference.resolveTableReference(selection.getContainingTableExpression()) != null ? defaultTableReference : tableGroup.resolveTableReference(navigablePath, selection.getContainingTableExpression());
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver().resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, selection.getSelectionExpression()), sqlAstProcessingState -> new ColumnReference(tableReference.getIdentificationVariable(), selection, sqlAstCreationState.getCreationContext().getSessionFactory()));
columnReferences.add((ColumnReference) columnReference);
});
return new SqlTuple(columnReferences, this);
}
use of org.hibernate.sql.ast.tree.expression.SqlTuple in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method visitInSubQueryPredicate.
@Override
public void visitInSubQueryPredicate(InSubQueryPredicate inSubQueryPredicate) {
final SqlTuple lhsTuple;
if ((lhsTuple = SqlTupleContainer.getSqlTuple(inSubQueryPredicate.getTestExpression())) != null) {
if (lhsTuple.getExpressions().size() == 1) {
// Special case for tuples with arity 1 as any DBMS supports scalar IN predicates
lhsTuple.getExpressions().get(0).accept(this);
if (inSubQueryPredicate.isNegated()) {
appendSql(" not");
}
appendSql(" in");
inSubQueryPredicate.getSubQuery().accept(this);
} else if (!supportsRowValueConstructorSyntaxInInSubQuery()) {
emulateSubQueryRelationalRestrictionPredicate(inSubQueryPredicate, inSubQueryPredicate.isNegated(), inSubQueryPredicate.getSubQuery(), lhsTuple, this::renderSelectTupleComparison, ComparisonOperator.EQUAL);
} else {
inSubQueryPredicate.getTestExpression().accept(this);
if (inSubQueryPredicate.isNegated()) {
appendSql(" not");
}
appendSql(" in");
inSubQueryPredicate.getSubQuery().accept(this);
}
} else {
inSubQueryPredicate.getTestExpression().accept(this);
if (inSubQueryPredicate.isNegated()) {
appendSql(" not");
}
appendSql(" in");
inSubQueryPredicate.getSubQuery().accept(this);
}
}
use of org.hibernate.sql.ast.tree.expression.SqlTuple in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method visitNullnessPredicate.
@Override
public void visitNullnessPredicate(NullnessPredicate nullnessPredicate) {
final Expression expression = nullnessPredicate.getExpression();
final String predicateValue;
if (nullnessPredicate.isNegated()) {
predicateValue = " is not null";
} else {
predicateValue = " is null";
}
final SqlTuple tuple;
if ((tuple = SqlTupleContainer.getSqlTuple(expression)) != null) {
String separator = NO_SEPARATOR;
// as the embeddable is not considered as null, if at least one sub-part is not null
if (nullnessPredicate.isNegated() && expression.getExpressionType() instanceof AttributeMapping) {
appendSql('(');
for (Expression exp : tuple.getExpressions()) {
appendSql(separator);
exp.accept(this);
appendSql(predicateValue);
separator = " or ";
}
appendSql(')');
} else // For the is null check, and also for tuples in SQL in general,
// the semantics is that all sub-parts must match the predicate
{
for (Expression exp : tuple.getExpressions()) {
appendSql(separator);
exp.accept(this);
appendSql(predicateValue);
separator = " and ";
}
}
} else {
expression.accept(this);
appendSql(predicateValue);
}
}
Aggregations