mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
This commit is contained in:
1 parent
b300db77ff
commit
f6b87ed0b4
4 files changed
+120
No files matched your search
@@ -155,6 +155,39 @@ public class QCustomerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalTo_byProperty() {
|
||||
Query<Customer> query = new QCustomer()
|
||||
.select(QCustomer.Alias.id)
|
||||
.billingAddress.city.eq(QCustomer.Alias.shippingAddress.city)
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
String generatedSql = query.getGeneratedSql();
|
||||
|
||||
// select t0.id from be_customer t0
|
||||
// left join o_address t2 on t2.id = t0.shipping_address_id
|
||||
// left join o_address t1 on t1.id = t0.billing_address_id
|
||||
// where t1.city = t2.city
|
||||
assertThat(generatedSql).contains("where t1.city = t2.city");
|
||||
}
|
||||
|
||||
@Test
|
||||
void notEqual_byProperty() {
|
||||
Query<Customer> query = new QCustomer()
|
||||
.select(QCustomer.Alias.id)
|
||||
.billingAddress.city.ne(QCustomer.Alias.shippingAddress.city)
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
String generatedSql = query.getGeneratedSql();
|
||||
|
||||
// select t0.id from be_customer t0
|
||||
// left join o_address t2 on t2.id = t0.shipping_address_id
|
||||
// left join o_address t1 on t1.id = t0.billing_address_id
|
||||
// where t1.city <> t2.city
|
||||
assertThat(generatedSql).contains("where t1.city <> t2.city");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmpty() {
|
||||
|
||||
@@ -2,12 +2,15 @@ package org.querytest;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.FetchGroup;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.example.domain.Customer;
|
||||
import org.example.domain.Order;
|
||||
import org.example.domain.OrderDetail;
|
||||
import org.example.domain.otherpackage.PhoneNumber;
|
||||
import org.example.domain.query.QCustomer;
|
||||
import org.example.domain.query.QOrder;
|
||||
import org.example.domain.query.QOrderDetail;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -214,6 +217,52 @@ public class QOrderTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void subQueryExists() {
|
||||
Query<OrderDetail> subQuery = new QOrderDetail()
|
||||
.alias("od")
|
||||
.orderQty.gt(10)
|
||||
.id.eq(QOrder.Alias.details.id)
|
||||
//.where().raw("details.id = od.id")
|
||||
.query();
|
||||
|
||||
Query<Order> query = new QOrder()
|
||||
.exists(subQuery)
|
||||
.orderBy("orderDate").query();
|
||||
|
||||
query.findList();
|
||||
|
||||
// select distinct t0.id, t0.status, t0.order_date, t0.ship_date, t0.version, t0.when_created, t0.when_updated, t0.customer_id, t0.shipping_address_id, t0.order_date
|
||||
// from o_order t0
|
||||
// left join o_order_detail t1 on t1.order_id = t0.id
|
||||
// where exists (select 1 from o_order_detail od where od.order_qty > ? and od.id = t1.id) order by t0.order_date
|
||||
String sql = query.getGeneratedSql();
|
||||
assertThat(sql).contains(" exists (select 1 from o_order_detail od where od.order_qty > ? and od.id = t1.id)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void subQueryNotExists() {
|
||||
Query<OrderDetail> subQuery = new QOrderDetail()
|
||||
.alias("od")
|
||||
.orderQty.gt(10)
|
||||
.id.eq(QOrder.Alias.details.id)
|
||||
//.where().raw("details.id = od.id")
|
||||
.query();
|
||||
|
||||
Query<Order> query = new QOrder()
|
||||
.notExists(subQuery)
|
||||
.orderBy("orderDate")
|
||||
.query();
|
||||
query.findList();
|
||||
|
||||
// select distinct t0.id, t0.status, t0.order_date, t0.ship_date, t0.version, t0.when_created, t0.when_updated, t0.customer_id, t0.shipping_address_id, t0.order_date
|
||||
// from o_order t0
|
||||
// left join o_order_detail t1 on t1.order_id = t0.id
|
||||
// where not exists (select 1 from o_order_detail od where od.order_qty > ? and od.id = t1.id) order by t0.order_date
|
||||
String sql = query.getGeneratedSql();
|
||||
assertThat(sql).contains(" not exists (select 1 from o_order_detail od where od.order_qty > ? and od.id = t1.id)");
|
||||
}
|
||||
|
||||
private static void setupData() {
|
||||
customer = new Customer();
|
||||
customer.name = "Fred";
|
||||
|
||||
Reference in new issue
Block a user