mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Re-add test and fix post-merge compile errors
This commit is contained in:
@@ -2,10 +2,12 @@ package org.tests.query.joins;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.OrderShipment;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.tests.model.family.ChildPerson;
|
||||
import org.tests.model.family.ParentPerson;
|
||||
@@ -59,8 +61,8 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
LoggedSql.start();
|
||||
|
||||
int orders = DB.find(Order.class)
|
||||
.where().eq("totalItems", 3)
|
||||
.findCount();
|
||||
.where().eq("totalItems", 3)
|
||||
.findCount();
|
||||
assertThat(orders).isEqualTo(2);
|
||||
|
||||
List<String> sql = LoggedSql.stop();
|
||||
@@ -69,6 +71,94 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
assertSql(sql.get(0)).contains("select count(*) from ( select t0.id from o_order t0 left join (select order_id,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderOnChainedFormulaProperty() {
|
||||
// test that join to order.details is not included
|
||||
|
||||
// Tests if SqlTreeBuilder.IncludesDistiller.createExtraJoin appends formulaJoinProperties
|
||||
Query<OrderShipment> shipQuery = DB.find(OrderShipment.class)
|
||||
.select("id")
|
||||
.order().asc("order.totalAmount");
|
||||
|
||||
shipQuery.findList();
|
||||
assertThat(shipQuery.getGeneratedSql()).isEqualTo("select t0.id "
|
||||
+ "from or_order_ship t0 "
|
||||
+ "left join o_order t1 on t1.id = t0.order_id "
|
||||
+ "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id "
|
||||
+ "order by z_bt1.total_amount");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereOnChainedFormulaProperty() {
|
||||
// test that join to order.details is not included
|
||||
|
||||
// Tests if SqlTreeBuilder.IncludesDistiller.createExtraJoin appends formulaJoinProperties
|
||||
Query<OrderShipment> shipQuery = DB.find(OrderShipment.class)
|
||||
.select("id")
|
||||
.where().isNotNull("order.totalAmount").query();
|
||||
|
||||
shipQuery.findList();
|
||||
assertThat(shipQuery.getGeneratedSql()).isEqualTo("select t0.id "
|
||||
+ "from or_order_ship t0 "
|
||||
+ "left join o_order t1 on t1.id = t0.order_id "
|
||||
+ "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id "
|
||||
+ "where z_bt1.total_amount is not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereOnChainedFormulaManyWhere() {
|
||||
// test that join to order.details is not included
|
||||
|
||||
// Tests if SqlTreeBuilder.IncludesDistiller.createExtraJoin appends formulaJoinProperties
|
||||
Query<OrderShipment> shipQuery = DB.find(OrderShipment.class)
|
||||
.select("id")
|
||||
.where().isNotNull("order.shipments.order.totalAmount").query();
|
||||
|
||||
shipQuery.findList();
|
||||
assertThat(shipQuery.getGeneratedSql()).isEqualTo("select distinct t0.id "
|
||||
+ "from or_order_ship t0 "
|
||||
+ "join o_order u1 on u1.id = t0.order_id "
|
||||
+ "join or_order_ship u2 on u2.order_id = u1.id "
|
||||
+ "join o_order u3 on u3.id = u2.order_id "
|
||||
+ "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bu3 on z_bu3.order_id = u3.id "
|
||||
+ "where z_bu3.total_amount is not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderOnChainedFormulaPropertyWithFetch() {
|
||||
|
||||
// Tests if SqlTreeBuilder.buildSelectChain appends formulaJoinProperties
|
||||
Query<OrderShipment> shipQuery = DB.find(OrderShipment.class)
|
||||
.select("id")
|
||||
.fetch("order", "totalAmount")
|
||||
.order().asc("order.totalAmount");
|
||||
|
||||
shipQuery.findList();
|
||||
assertThat(shipQuery.getGeneratedSql()).isEqualTo("select t0.id, t1.id, z_bt1.total_amount "
|
||||
+ "from or_order_ship t0 "
|
||||
+ "left join o_order t1 on t1.id = t0.order_id "
|
||||
+ "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id "
|
||||
+ "order by z_bt1.total_amount");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereOnChainedFormulaPropertyWithFetch() {
|
||||
// Tests if SqlTreeBuilder.buildSelectChain appends formulaJoinProperties
|
||||
Query<OrderShipment> shipQuery = DB.find(OrderShipment.class)
|
||||
.select("id")
|
||||
.fetch("order", "totalAmount")
|
||||
.where().isNotNull("order.totalAmount").query();
|
||||
|
||||
shipQuery.findList();
|
||||
assertThat(shipQuery.getGeneratedSql()).isEqualTo("select t0.id, t1.id, z_bt1.total_amount "
|
||||
+ "from or_order_ship t0 "
|
||||
+ "left join o_order t1 on t1.id = t0.order_id "
|
||||
+ "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id "
|
||||
+ "where z_bt1.total_amount is not null");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_OrderFindCount_multiFormula() {
|
||||
|
||||
@@ -211,13 +301,15 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
LoggedSql.start();
|
||||
|
||||
DB.find(ChildPerson.class)
|
||||
.where().eq("parent.totalAge", 3)
|
||||
.findIds();
|
||||
.where().eq("parent.totalAge", 3)
|
||||
.findIds();
|
||||
|
||||
List<String> loggedSql = LoggedSql.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("select t0.identifier from child_person t0 left join (select i2.parent_identifier");
|
||||
assertThat(loggedSql.get(0)).contains("where coalesce(f2.child_age, 0) = ?");
|
||||
assertThat(loggedSql.get(0))
|
||||
.contains("select t0.identifier from child_person t0")
|
||||
.contains("left join (select i2.parent_identifier")
|
||||
.contains("where coalesce(f2.child_age, 0) = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -231,7 +323,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
|
||||
List<String> loggedSql = LoggedSql.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("select count(*) from ( select t0.identifier");
|
||||
assertThat(loggedSql.get(0)).contains("select count(*) from child_person t0 left join parent_person t1 on t1.identifier = t0.parent_identifier");
|
||||
assertThat(loggedSql.get(0)).contains("where coalesce(f2.child_age, 0) = ?");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user