diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java index 4e0ba7c1d..466093ac2 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java @@ -40,6 +40,17 @@ public class PBaseCompareable extends PBaseValueEqual { return _root; } + /** + * Greater than other property. + * + * @param other the other property to compare + * @return the root query bean instance + */ + public final R gt(TQProperty other) { + expr().raw(_name + " > " + other.propertyName()); + return _root; + } + /** * Greater than OR Null. * @@ -62,6 +73,17 @@ public class PBaseCompareable extends PBaseValueEqual { return _root; } + /** + * Greater than or Equal to other property. + * + * @param other the other property to compare + * @return the root query bean instance + */ + public final R ge(TQProperty other) { + expr().raw(_name + " >= " + other.propertyName()); + return _root; + } + /** * Greater than or Equal to OR Null. * @@ -84,6 +106,17 @@ public class PBaseCompareable extends PBaseValueEqual { return _root; } + /** + * Less than other property. + * + * @param other the other property to compare + * @return the root query bean instance + */ + public final R lt(TQProperty other) { + expr().raw(_name + " < " + other.propertyName()); + return _root; + } + /** * Less than OR Null. * @@ -106,6 +139,17 @@ public class PBaseCompareable extends PBaseValueEqual { return _root; } + /** + * Less than or Equal to other property. + * + * @param other the other property to compare + * @return the root query bean instance + */ + public final R le(TQProperty other) { + expr().raw(_name + " <= " + other.propertyName()); + return _root; + } + /** * Less than or Equal to. * diff --git a/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java b/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java index cf32f9af2..18cb0dfc7 100644 --- a/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java +++ b/ebean-querybean/src/test/java/org/querytest/QCustomerTest.java @@ -454,6 +454,7 @@ public class QCustomerTest { assertContains(new QCustomer().registered.lt(new Date()).query(), " where t0.registered < ?"); assertContains(new QCustomer().registered.before(new Date()).query(), " where t0.registered < ?"); assertContains(new QCustomer().registered.lessThan(new Date()).query(), " where t0.registered < ?"); + assertContains(new QCustomer().registered.lt(QCustomer.Alias.whenUpdated).query(), " where t0.registered < t0.when_updated"); } @Test @@ -461,6 +462,7 @@ public class QCustomerTest { assertContains(new QCustomer().registered.le(new Date()).query(), " where t0.registered <= ?"); assertContains(new QCustomer().registered.lessOrEqualTo(new Date()).query(), " where t0.registered <= ?"); + assertContains(new QCustomer().registered.le(QCustomer.Alias.whenUpdated).query(), " where t0.registered <= t0.when_updated"); } @Test @@ -468,6 +470,7 @@ public class QCustomerTest { assertContains(new QCustomer().registered.after(new Date()).query(), " where t0.registered > ?"); assertContains(new QCustomer().registered.gt(new Date()).query(), " where t0.registered > ?"); + assertContains(new QCustomer().registered.gt(QCustomer.Alias.whenUpdated).query(), " where t0.registered > t0.when_updated"); assertContains(new QCustomer().registered.greaterThan(new Date()).query(), " where t0.registered > ?"); } @@ -477,6 +480,7 @@ public class QCustomerTest { assertContains(new QCustomer().registered.ge(new Date()).query(), " where t0.registered >= ?"); assertContains(new QCustomer().registered.greaterOrEqualTo(new Date()).query(), " where t0.registered >= ?"); + assertContains(new QCustomer().registered.ge(QCustomer.Alias.whenUpdated).query(), " where t0.registered >= t0.when_updated"); } private void assertContains(Query query, String match) { diff --git a/ebean-querybean/src/test/java/org/querytest/QOrderTest.java b/ebean-querybean/src/test/java/org/querytest/QOrderTest.java index 13d34bf1e..3edfc9310 100644 --- a/ebean-querybean/src/test/java/org/querytest/QOrderTest.java +++ b/ebean-querybean/src/test/java/org/querytest/QOrderTest.java @@ -217,6 +217,16 @@ public class QOrderTest { } + @Test + void propertyCompare() { + Query query = new QOrder() + .orderDate.lt(QOrder.Alias.customer.registered) + .query(); + + query.findList(); + assertThat(query.getGeneratedSql()).contains(" from o_order t0 join be_customer t1 on t1.id = t0.customer_id where t0.order_date < t1.registered"); + } + @Test void subQueryExists() { Query subQuery = new QOrderDetail()