#2877 - Query Beans: Add lt, le, gt, ge <other property> e.g. whenRegistered.gt(QCustomer.Alias.whenActivated)

This commit is contained in:
Rob Bygrave committed 2022-11-02 16:32:49 +13:00
1 parent f6b87ed0b4
commit 600aa10453
3 files changed
+58

No files matched your search

@@ -40,6 +40,17 @@ public class PBaseCompareable<R, T> extends PBaseValueEqual<R, T> {
return _root; 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. * Greater than OR Null.
* *
@@ -62,6 +73,17 @@ public class PBaseCompareable<R, T> extends PBaseValueEqual<R, T> {
return _root; 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. * Greater than or Equal to OR Null.
* *
@@ -84,6 +106,17 @@ public class PBaseCompareable<R, T> extends PBaseValueEqual<R, T> {
return _root; 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. * Less than OR Null.
* *
@@ -106,6 +139,17 @@ public class PBaseCompareable<R, T> extends PBaseValueEqual<R, T> {
return _root; 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. * Less than or Equal to.
* *
@@ -454,6 +454,7 @@ public class QCustomerTest {
assertContains(new QCustomer().registered.lt(new Date()).query(), " where t0.registered < ?"); 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.before(new Date()).query(), " where t0.registered < ?");
assertContains(new QCustomer().registered.lessThan(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 @Test
@@ -461,6 +462,7 @@ public class QCustomerTest {
assertContains(new QCustomer().registered.le(new Date()).query(), " where t0.registered <= ?"); 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.lessOrEqualTo(new Date()).query(), " where t0.registered <= ?");
assertContains(new QCustomer().registered.le(QCustomer.Alias.whenUpdated).query(), " where t0.registered <= t0.when_updated");
} }
@Test @Test
@@ -468,6 +470,7 @@ public class QCustomerTest {
assertContains(new QCustomer().registered.after(new Date()).query(), " where t0.registered > ?"); 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(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 > ?"); 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.ge(new Date()).query(), " where t0.registered >= ?");
assertContains(new QCustomer().registered.greaterOrEqualTo(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<Customer> query, String match) { private void assertContains(Query<Customer> query, String match) {
@@ -217,6 +217,16 @@ public class QOrderTest {
} }
@Test
void propertyCompare() {
Query<Order> 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 @Test
void subQueryExists() { void subQueryExists() {
Query<OrderDetail> subQuery = new QOrderDetail() Query<OrderDetail> subQuery = new QOrderDetail()