From a44004655632142db89ef696059e06b69c1519d6 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 5 Jul 2023 18:12:40 +0200 Subject: [PATCH] HHH-16898 add JpaExpression.equalTo() --- .../org/hibernate/query/criteria/JpaExpression.java | 4 ++++ .../FullyQualifiedReflectivePathTerminal.java | 10 ++++++++++ .../sqm/tree/expression/AbstractSqmExpression.java | 11 ++++++++++- .../query/sqm/tree/expression/SqmExpression.java | 8 +++++++- .../query/sqm/tree/expression/SqmFieldLiteral.java | 10 ++++++++++ .../hibernate/query/sqm/tree/select/SqmSubQuery.java | 10 ++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaExpression.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaExpression.java index cb608307cd..b9fdb7f5ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaExpression.java @@ -52,4 +52,8 @@ public interface JpaExpression extends JpaSelection, Expression { @Override JpaPredicate in(Expression> values); + + JpaPredicate equalTo(Expression that); + + JpaPredicate equalTo(T that); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java index 3b468be55d..f3fc22a4de 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java @@ -207,6 +207,16 @@ public class FullyQualifiedReflectivePathTerminal return null; } + @Override + public SqmPredicate equalTo(Expression that) { + return null; + } + + @Override + public SqmPredicate equalTo(Object that) { + return null; + } + @Override public SqmPredicate in(Object... values) { return null; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java index 8e3afe48ec..d65fffc917 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java @@ -23,7 +23,6 @@ import org.hibernate.type.descriptor.java.JavaType; import jakarta.persistence.criteria.Expression; -import static org.hibernate.query.internal.QueryHelper.highestPrecedenceType; import static org.hibernate.query.internal.QueryHelper.highestPrecedenceType2; /** @@ -115,6 +114,16 @@ public abstract class AbstractSqmExpression extends AbstractJpaSelection i return nodeBuilder().isNotNull( this ); } + @Override + public SqmPredicate equalTo(Expression that) { + return nodeBuilder().equal( this, that ); + } + + @Override + public SqmPredicate equalTo(T that) { + return nodeBuilder().equal( this, that ); + } + @Override public SqmPredicate in(Object... values) { return nodeBuilder().in( this, values ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java index 54999fc56b..0eb906338f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java @@ -36,7 +36,7 @@ import static java.util.Arrays.asList; public interface SqmExpression extends SqmSelectableNode, JpaExpression { /** * The expression's type. - * + *

* Can change as a result of calls to {@link #applyInferableType} */ @Override @@ -92,6 +92,12 @@ public interface SqmExpression extends SqmSelectableNode, JpaExpression @Override SqmPredicate isNotNull(); + @Override + SqmPredicate equalTo(Expression that); + + @Override + SqmPredicate equalTo(T that); + @Override SqmPredicate in(Object... values); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java index 5582aa62a9..1076006b37 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java @@ -152,6 +152,16 @@ public class SqmFieldLiteral implements SqmExpression, SqmExpressible, return nodeBuilder().isNull( this ); } + @Override + public SqmPredicate equalTo(Expression that) { + return nodeBuilder().equal( this, that ); + } + + @Override + public SqmPredicate equalTo(T that) { + return nodeBuilder().equal( this, that ); + } + @Override public SqmPredicate isNotNull() { return nodeBuilder().isNotNull( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java index dabd51f5c8..17ed46df7c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java @@ -560,6 +560,16 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele return nodeBuilder().isNotNull( this ); } + @Override + public SqmPredicate equalTo(Expression that) { + return nodeBuilder().equal( this, that ); + } + + @Override + public SqmPredicate equalTo(T that) { + return nodeBuilder().equal( this, that ); + } + @Override public SqmInPredicate in(Object... values) { return nodeBuilder().in( this, values );