mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 21:15:52 +00:00
#1753 - Tidy for Issue with using the Formula-Properties
This commit is contained in:
@@ -265,9 +265,8 @@ class CQueryBuilder {
|
||||
if (!countDistinct) {
|
||||
// minimise select clause for standard count
|
||||
if (manyWhereJoins.isFormulaWithJoin()) {
|
||||
// FIXME: we join the strings here and on the other side we split them again
|
||||
// this is not yet optimal
|
||||
query.select(String.join(",",manyWhereJoins.getFormulaJoinProperties()));
|
||||
// Note that this is not yet optimal (split and join)
|
||||
query.select(String.join(",", manyWhereJoins.getFormulaJoinProperties()));
|
||||
} else {
|
||||
query.setSelectId();
|
||||
}
|
||||
|
||||
@@ -299,8 +299,7 @@ public final class SqlTreeBuilder {
|
||||
if (manyWhereJoins.isFormulaWithJoin()) {
|
||||
for (String property: manyWhereJoins.getFormulaJoinProperties()) {
|
||||
STreeProperty beanProperty = desc.findPropertyFromPath(property);
|
||||
SqlTreeNodeFormulaWhereJoin nodeJoin = new SqlTreeNodeFormulaWhereJoin(beanProperty, SqlJoinType.OUTER);
|
||||
myJoinList.add(nodeJoin);
|
||||
myJoinList.add(new SqlTreeNodeFormulaWhereJoin(beanProperty, SqlJoinType.OUTER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,18 +67,15 @@ class SqlTreeNodeFormulaWhereJoin implements SqlTreeNode {
|
||||
*/
|
||||
@Override
|
||||
public void appendFrom(DbSqlContext ctx, SqlJoinType currentJoinType) {
|
||||
|
||||
// always use the join type as per this many where join
|
||||
// (OUTER for disjunction and otherwise INNER)
|
||||
nodeBeanProp.appendFrom(ctx, manyJoinType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void dependentTables(Set<String> tables) {
|
||||
//FIXME: we cannot easily determine the dependent tables, this would require an enhancement
|
||||
//of the @Formula(dependentTables=...) annotation
|
||||
// FIXME: we cannot easily determine the dependent tables this would require an enhancement
|
||||
// of the @Formula(dependentTables=...) annotation
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,6 +67,25 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("join (select order_id, count(*) as total_items,");
|
||||
assertThat(loggedSql.get(0)).contains("elect count(*) from ( select t0.id, z_bt0.total_items from o_order t0 join (select order_id,");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_OrderFindCount_multiFormula() {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
int orders = Ebean.find(Order.class)
|
||||
.where()
|
||||
.eq("totalItems", 3)
|
||||
.gt("totalAmount", 10)
|
||||
.findCount();
|
||||
|
||||
assertThat(orders).isEqualTo(2);
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("select count(*) from ( select t0.id, z_bt0.total_items, z_bt0.total_amount from o_order t0 join (select order_id,");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,6 +102,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("join (select order_id, count(*) as total_items,");
|
||||
assertThat(loggedSql.get(0)).contains("select t0.order_date from o_order t0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,6 +122,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("join (select order_id, count(*) as total_items,");
|
||||
assertThat(loggedSql.get(0)).contains("select t0.id, z_bt0.total_items from o_order t0 join (select order_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,10 +133,10 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
List<ParentPerson> orderIds = Ebean.find(ParentPerson.class)
|
||||
.where().eq("totalAge", 3)
|
||||
.findIds();
|
||||
// TODO: There are no beans in database, so for now only the query must run.
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("where coalesce(f2.child_age, 0) = ?; --bind(3)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,10 +149,10 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
//.where().eq("totalAge", 3)
|
||||
.where().eq("familyName", "foo")
|
||||
.findList();
|
||||
// TODO: There are no beans in database, so for now only the query must run.
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("select t0.identifier from parent_person t0 where t0.family_name = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,10 +163,11 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
Ebean.find(ParentPerson.class)
|
||||
.where().eq("totalAge", 3)
|
||||
.findCount();
|
||||
// TODO: There are no beans in database, so for now only the query must run.
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("where coalesce(f2.child_age, 0) = ?)");
|
||||
assertThat(loggedSql.get(0)).contains("select count(*) from ( select t0.identifier, coalesce(f2.child_age, 0) from parent_person t0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,13 +176,14 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
Ebean.find(ParentPerson.class)
|
||||
.select("address") // .select("address, totalAge") would work
|
||||
.select("address")
|
||||
.where().eq("totalAge", 3)
|
||||
.findSingleAttributeList();
|
||||
// TODO: There are no beans in database, so for now only the query must run.
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("select t0.address from parent_person t0 left join (select i2.parent_identifier");
|
||||
assertThat(loggedSql.get(0)).contains("where coalesce(f2.child_age, 0) = ?; --bind(3)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,10 +196,10 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
.setMaxRows(1)
|
||||
.orderById(true)
|
||||
.findOne();
|
||||
// TODO: There are no beans in database, so for now only the query must run.
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("where coalesce(f2.child_age, 0) = ? order by t0.identifier");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,10 +210,11 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
Ebean.find(ChildPerson.class)
|
||||
.where().eq("parent.totalAge", 3)
|
||||
.findIds();
|
||||
// TODO: There are no beans in database, so for now only the query must run.
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.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) = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,9 +225,10 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
Ebean.find(ChildPerson.class)
|
||||
.where().eq("parent.totalAge", 3)
|
||||
.findCount();
|
||||
// TODO: There are no beans in database, so for now only the query must run.
|
||||
|
||||
List<String> loggedSql = LoggedSqlCollector.stop();
|
||||
assertEquals(1, loggedSql.size());
|
||||
assertThat(loggedSql.get(0)).contains("select count(*) from ( select t0.identifier");
|
||||
assertThat(loggedSql.get(0)).contains("where coalesce(f2.child_age, 0) = ?");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user