mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1621 - Consider clean up white space in generated SQL (as in remove unneeded extra spaces)
This commit is contained in:
@@ -91,7 +91,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,7 +117,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,7 +147,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("select t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.email, " + concat("t0.last_name", ", ", "t0.first_name")
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
+ " fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains(
|
||||
"select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
|
||||
"select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,7 +36,7 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
|
||||
query.update();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("update o_customer set status=?, updtime=? where status = ? and id > ?");
|
||||
assertThat(query.getGeneratedSql()).contains("update o_customer set status=?, updtime=? where status = ? and id > ?");
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
List<MetaOrmQueryMetric> ormQueryMetrics = basic.getOrmQueryMetrics();
|
||||
@@ -166,7 +166,7 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
|
||||
query.update();
|
||||
|
||||
assertThat(sqlOf(query)).contains("update o_customer set status=?, updtime=? where id in (select t0.id from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t0.status = ? and t1.country_code = ? and t0.id > ? )");
|
||||
assertThat(sqlOf(query)).contains("update o_customer set status=?, updtime=? where id in (select t0.id from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t0.status = ? and t1.country_code = ? and t0.id > ?)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -8,18 +8,18 @@ import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
public class BetweenExpressionTest extends BaseExpressionTest {
|
||||
|
||||
@Test
|
||||
public void addSql() throws Exception {
|
||||
public void addSql() {
|
||||
|
||||
DefaultExpressionRequest expReq = newExpressionRequest();
|
||||
|
||||
BetweenExpression exp = new BetweenExpression("startDate", 1, 2);
|
||||
exp.addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("startDate between ? and ? ");
|
||||
assertThat(expReq.getSql()).isEqualTo("startDate between ? and ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyForPlanKey_isSameInstance() throws Exception {
|
||||
public void copyForPlanKey_isSameInstance() {
|
||||
|
||||
BetweenExpression exp = new BetweenExpression("startDate", 1, 2);
|
||||
SpiExpression other = exp.copyForPlanKey();
|
||||
@@ -28,7 +28,7 @@ public class BetweenExpressionTest extends BaseExpressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByPlan_when_properties_match() throws Exception {
|
||||
public void isSameByPlan_when_properties_match() {
|
||||
|
||||
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
|
||||
BetweenExpression exp1 = new BetweenExpression("startDate", 3, 4);
|
||||
@@ -38,7 +38,7 @@ public class BetweenExpressionTest extends BaseExpressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByPlan_when_properties_do_not_match() throws Exception {
|
||||
public void isSameByPlan_when_properties_do_not_match() {
|
||||
|
||||
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
|
||||
BetweenExpression exp1 = new BetweenExpression("endDate", 1, 2);
|
||||
@@ -48,7 +48,7 @@ public class BetweenExpressionTest extends BaseExpressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByBind_when_values_do_not_match() throws Exception {
|
||||
public void isSameByBind_when_values_do_not_match() {
|
||||
|
||||
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
|
||||
BetweenExpression exp1 = new BetweenExpression("startDate", 1, 3);
|
||||
@@ -58,7 +58,7 @@ public class BetweenExpressionTest extends BaseExpressionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByBind_when_values_match() throws Exception {
|
||||
public void isSameByBind_when_values_match() {
|
||||
|
||||
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
|
||||
BetweenExpression exp1 = new BetweenExpression("startDate", 1, 2);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class BetweenPropertyExpressionTest extends BaseExpressionTest {
|
||||
public void sqlExpression() {
|
||||
TDSpiExpressionRequest request = new TDSpiExpressionRequest(null);
|
||||
exp("a", "b", 10).addSql(request);
|
||||
assertThat(request.getSql()).isEqualTo(" ? between a and b ");
|
||||
assertThat(request.getSql()).isEqualTo(" ? between a and b");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,7 +15,7 @@ public class InRangeExpressionTest extends BaseExpressionTest {
|
||||
InRangeExpression exp = new InRangeExpression("startDate", 1, 2);
|
||||
exp.addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("(startDate >= ? and startDate < ?) ");
|
||||
assertThat(expReq.getSql()).isEqualTo("(startDate >= ? and startDate < ?)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,6 +21,17 @@ public class LogicExpressionTest extends BaseExpressionTest {
|
||||
return new LogicExpression.Or(a, b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addSql() {
|
||||
|
||||
DefaultExpressionRequest expReq = newExpressionRequest();
|
||||
|
||||
LogicExpression and = and(eq("a", 10), eq("b", 10));
|
||||
and.addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("(a = ? and b = ?)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByPlan_when_same() {
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class NoopExpressionTest extends BaseExpressionTest {
|
||||
query.findList();
|
||||
String generatedSql = sqlOf(query);
|
||||
|
||||
assertThat(generatedSql).contains("select t0.id from o_customer t0 where t0.name is null and 1=1 and t0.status is not null");
|
||||
assertThat(generatedSql).contains("select t0.id from o_customer t0 where t0.name is null and 1=1 and t0.status is not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,8 +2,8 @@ package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.ManyWhereJoins;
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Order;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class NullExpressionTest extends BaseExpressionTest {
|
||||
|
||||
nullExp("id", true).addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("id is not null ");
|
||||
assertThat(expReq.getSql()).isEqualTo("id is not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -32,7 +32,7 @@ public class NullExpressionTest extends BaseExpressionTest {
|
||||
|
||||
nullExp("id", false).addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("id is null ");
|
||||
assertThat(expReq.getSql()).isEqualTo("id is null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,7 +42,7 @@ public class NullExpressionTest extends BaseExpressionTest {
|
||||
|
||||
nullExp("customer", true).addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("customer.id is not null ");
|
||||
assertThat(expReq.getSql()).isEqualTo("customer.id is not null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,7 +52,7 @@ public class NullExpressionTest extends BaseExpressionTest {
|
||||
|
||||
nullExp("customer", false).addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("customer.id is null ");
|
||||
assertThat(expReq.getSql()).isEqualTo("customer.id is null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -64,6 +64,6 @@ public class HanaDbExpressionTest {
|
||||
public void testJson() {
|
||||
SpiExpressionRequest request = new DefaultExpressionRequest(null);
|
||||
expression.json(request, "jsonproperty", "path", Op.EQ, "val");
|
||||
assertEquals("json_value(jsonproperty, '$.path') = ? ", request.getSql());
|
||||
assertEquals("json_value(jsonproperty, '$.path') = ?", request.getSql());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
Query<Customer> query = parse("where name ieq 'Rob'");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) =?");
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +91,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
Query<Customer> query = parse("where name ine 'Rob'");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) !=?");
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) != ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +99,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
|
||||
Query<Customer> query = parse("where 'Rob' ieq name");
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) =?");
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +108,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
Query<Customer> query = parse("where 'Rob' ine name");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) !=?");
|
||||
assertThat(query.getGeneratedSql()).contains("where lower(t0.name) != ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,7 +156,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
Query<Customer> query = parse("where name = 'Rob' or (status = 'NEW' and smallnote is null)");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null ) )");
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.name = ? or (t0.status = ? and t0.smallnote is null))");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,7 +176,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
Query<Customer> query = parse("where (name = 'Rob' or status = 'NEW') and smallnote is null");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where ((t0.name = ? or t0.status = ? ) and t0.smallnote is null )");
|
||||
assertThat(query.getGeneratedSql()).contains("where ((t0.name = ? or t0.status = ?) and t0.smallnote is null)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,15 +195,15 @@ public class EqlParserTest extends BaseTestCase {
|
||||
|
||||
Query<Customer> query = parse("where not (name = 'Rob' and status = 'NEW')");
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ?)");
|
||||
|
||||
query = parse("where not ((name = 'Rob' and status = 'NEW'))");
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ?)");
|
||||
|
||||
query = parse("where not (((name = 'Rob') and (status = 'NEW')))");
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ? )");
|
||||
assertThat(query.getGeneratedSql()).contains("where not (t0.name = ? and t0.status = ?)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -281,7 +281,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
Query<Customer> query = parse("where name inrange 'As' to 'B'");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.name >= ? and t0.name < ?) ");
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.name >= ? and t0.name < ?)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -301,7 +301,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
Query<Customer> query = parse("where name between 'As' and 'B'");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where t0.name between ? and ? ");
|
||||
assertThat(query.getGeneratedSql()).contains("where t0.name between ? and ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -312,7 +312,7 @@ public class EqlParserTest extends BaseTestCase {
|
||||
query.setParameter("two", "b");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where t0.name between ? and ? ");
|
||||
assertThat(query.getGeneratedSql()).contains("where t0.name between ? and ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -5,10 +5,10 @@ import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.RawSql;
|
||||
import io.ebean.RawSqlBuilder;
|
||||
import org.tests.model.basic.OrderAggregate;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.OrderAggregate;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -128,7 +128,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertThat(query.getGeneratedSql()).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
|
||||
assertThat(query.getGeneratedSql()).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertThat(query.getGeneratedSql()).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
|
||||
assertThat(query.getGeneratedSql()).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
|
||||
assertNotNull(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class TestSecondaryQueries extends TransactionalTestCase {
|
||||
|
||||
String generatedSql = sqlOf(query, 2);
|
||||
//select t0.id c0, t0.status c1, t0.kcustomer_id c2 from o_order t0 where t0.status = ? ; --bind(NEW)
|
||||
assertEquals("select t0.id, t0.status, t0.kcustomer_id from o_order t0 where t0.status = ? ", generatedSql);
|
||||
assertEquals("select t0.id, t0.status, t0.kcustomer_id from o_order t0 where t0.status = ?", generatedSql);
|
||||
|
||||
|
||||
//List<SpiQuery<?>> secondaryQueries = spiQuery.getLoggedSecondaryQueries();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class TestAggregationMany extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.name, t1.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name, t1.name order by t0.id");
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.name, t1.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name, t1.name order by t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,6 +89,6 @@ public class TestAggregationMany extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name order by t0.id");
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.name, sum(t1.use_secs), sum(t1.fuel) from dmachine t0 left join d_machine_aux_use t1 on t1.machine_id = t0.id where t0.organisation_id = ? group by t0.id, t0.name order by t0.id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<DMachineStatsAgg> result = query.findList();
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date having sum(cost) > ?");
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date having sum(cost) > ?");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<DMachineStatsAgg> result = query.findList();
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.date > ? group by t0.machine_id");
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms), sum(cost) from d_machine_stats t0 where t0.date > ? group by t0.machine_id");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<DMachineStatsAgg> result = query.findList();
|
||||
assertThat(sqlOf(query)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), max(t0.rate), sum(cost), max(t0.total_kms) from d_machine_stats t0 where t0.date > ? group by t0.date having sum(t0.hours) > ?");
|
||||
assertThat(sqlOf(query)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), max(t0.rate), sum(cost), max(t0.total_kms) from d_machine_stats t0 where t0.date > ? group by t0.date having sum(t0.hours) > ?");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<DMachineStats> result = query.findList();
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, sum(t0.total_kms), sum(t0.hours) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date having sum(t0.hours) > ?");
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, sum(t0.total_kms), sum(t0.hours) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date having sum(t0.hours) > ?");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<DMachineStats> result = query.findList();
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms) from d_machine_stats t0 where t0.date > ? group by t0.machine_id having sum(t0.hours) > ?");
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, sum(t0.total_kms) from d_machine_stats t0 where t0.date > ? group by t0.machine_id having sum(t0.hours) > ?");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.date > ? group by t1.id, t1.name having sum(t0.hours) > ?");
|
||||
assertThat(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.date > ? group by t1.id, t1.name having sum(t0.hours) > ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,7 +139,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.date > ? group by t0.date, t1.id, t1.name having sum(t0.hours) > ?");
|
||||
assertThat(sql.get(0)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), t1.id, t1.name from d_machine_stats t0 join dmachine t1 on t1.id = t0.machine_id where t0.date > ? group by t0.date, t1.id, t1.name having sum(t0.hours) > ?");
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(2);
|
||||
|
||||
assertThat(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.date > ? group by t0.machine_id having sum(t0.hours) > ?");
|
||||
assertThat(sql.get(0)).contains("select sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.date > ? group by t0.machine_id having sum(t0.hours) > ?");
|
||||
assertThat(sql.get(1)).contains("select t0.id, t0.name from dmachine t0 where t0.id");
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(2);
|
||||
|
||||
assertThat(sql.get(0)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.date > ? group by t0.date, t0.machine_id having sum(t0.hours) > ?");
|
||||
assertThat(sql.get(0)).contains("select t0.date, sum(t0.total_kms), sum(t0.hours), t0.machine_id from d_machine_stats t0 where t0.date > ? group by t0.date, t0.machine_id having sum(t0.hours) > ?");
|
||||
assertThat(sql.get(1)).contains("select t0.id, t0.name from dmachine t0 where t0.id");
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<DMachineStats> result = query.findList();
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, max(t0.rate) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date");
|
||||
assertThat(sqlOf(query)).contains("select t0.machine_id, t0.date, max(t0.rate) from d_machine_stats t0 where t0.date > ? group by t0.machine_id, t0.date");
|
||||
assertThat(result).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
|
||||
assertThat(sqlOf(query)).contains("select t0.id, t0.name, sum(t1.total_kms) from dmachine t0 left join d_machine_stats t1 on t1.machine_id = t0.id where t0.name = ? group by t0.id, t0.name order by t0.id");
|
||||
assertThat(sqlOf(query)).contains("select t0.id, t0.name, sum(t1.total_kms) from dmachine t0 left join d_machine_stats t1 on t1.machine_id = t0.id where t0.name = ? group by t0.id, t0.name order by t0.id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,7 +244,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
|
||||
assertThat(sqlOf(query)).contains("select t0.id, t0.name, t1.date, max(t1.rate), sum(t1.total_kms) from dmachine t0 left join d_machine_stats t1 on t1.machine_id = t0.id where t0.name = ? group by t0.id, t0.name, t1.date order by t0.id");
|
||||
assertThat(sqlOf(query)).contains("select t0.id, t0.name, t1.date, max(t1.rate), sum(t1.total_kms) from dmachine t0 left join d_machine_stats t1 on t1.machine_id = t0.id where t0.name = ? group by t0.id, t0.name, t1.date order by t0.id");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ public class TestCacheViaComplexNaturalKey extends BaseTestCase {
|
||||
assertThat(sql).hasSize(1);
|
||||
if (isH2()) {
|
||||
// in clause with only 1 bind param - (sku=3 ... we got hits on sku 1 and 2)
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (? ) order by t0.sku desc; --bind(abc,Array[1]={3})");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (? ) order by t0.sku desc; --bind(abc,Array[1]={3})");
|
||||
}
|
||||
|
||||
assertThat(list).hasSize(3);
|
||||
@@ -169,7 +169,7 @@ public class TestCacheViaComplexNaturalKey extends BaseTestCase {
|
||||
assertThat(sql).hasSize(1);
|
||||
if (isH2()) {
|
||||
// in clause with 2 bind params as we got not hits on the cache
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (?, ? ) order by t0.sku desc; --bind(abc,Array[2]={3,4})");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey t0 where t0.store = ? and t0.sku in (?, ? ) order by t0.sku desc; --bind(abc,Array[2]={3,4})");
|
||||
}
|
||||
|
||||
assertThat(list).hasSize(2);
|
||||
|
||||
+10
-10
@@ -116,7 +116,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
assertThat(sql).hasSize(1);
|
||||
if (isH2()) {
|
||||
// in clause with only 1 bind param - (sku=3 ... we got hits on sku 1 and 2)
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.code in (? ) and t0.sku = ? order by t0.sku desc, t0.code; --bind(def,Array[1]={1000},2)");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.code in (? ) and t0.sku = ? order by t0.sku desc, t0.code; --bind(def,Array[1]={1000},2)");
|
||||
}
|
||||
|
||||
assertThat(list).hasSize(4);
|
||||
@@ -178,7 +178,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
assertThat(sql).hasSize(1);
|
||||
if (isH2()) {
|
||||
// in clause with 2 bind params as we got not hits on the cache
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku in (?, ?, ? ) and t0.code = ? order by t0.sku desc; --bind(abc,Array[3]={3,2,4},1001)");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and t0.sku in (?, ?, ? ) and t0.code = ? order by t0.sku desc; --bind(abc,Array[3]={3,2,4},1001)");
|
||||
}
|
||||
|
||||
assertThat(list).hasSize(2);
|
||||
@@ -278,13 +278,13 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
assertBeanCacheHitMiss(1, 0);
|
||||
|
||||
if (isH2()) {
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code) in (?, ? ) order by t0.sku desc; --bind(def,Array[2]={2-1000,3-1000})");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code) in (?, ? ) order by t0.sku desc; --bind(def,Array[2]={2-1000,3-1000})");
|
||||
} else if (isPostgres()) {
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||'-'||t0.code)");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||'-'||t0.code)");
|
||||
} else if (isHana()) {
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, '-'||t0.code)");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, '-'||t0.code)");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code)");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code)");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -321,13 +321,13 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
assertBeanCacheHitMiss(1, 0);
|
||||
|
||||
if (isH2()) {
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo') in (?, ? ) order by t0.sku desc; --bind(def,Array[2]={2:1000-foo,3:1000-foo})");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo') in (?, ? ) order by t0.sku desc; --bind(def,Array[2]={2:1000-foo,3:1000-foo})");
|
||||
} else if (isPostgres()){
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||':'||t0.code||'-foo')");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||':'||t0.code||'-foo')");
|
||||
} else if (isHana()){
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, ':'||t0.code||'-foo')");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, ':'||t0.code||'-foo')");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo')");
|
||||
assertThat(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo')");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TestMediaInheritanceJoinToMany extends BaseTestCase {
|
||||
|
||||
String generatedSql = query.getGeneratedSql();
|
||||
assertThat(generatedSql).contains("from mprofile t0 left join mmedia t1 on t1.id = t0.picture_id and t1.type = 'Picture' ");
|
||||
assertThat(generatedSql).contains("where t0.name = ? ");
|
||||
assertThat(generatedSql).contains("where t0.name = ?");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TestPview extends BaseTestCase {
|
||||
query.findList();
|
||||
String generatedSql = sqlOf(query, 1);
|
||||
|
||||
assertThat(generatedSql).contains("select distinct t0.amount, t1.value from paggview t0 join pp u1 on u1.id = t0.pview_id join pp_to_ww u2z_ on u2z_.pp_id = u1.id join wview u2 on u2.id = u2z_.ww_id left join pp t1 on t1.id = t0.pview_id where u2.id = ? order by t1.value");
|
||||
assertThat(generatedSql).contains("select distinct t0.amount, t1.value from paggview t0 join pp u1 on u1.id = t0.pview_id join pp_to_ww u2z_ on u2z_.pp_id = u1.id join wview u2 on u2.id = u2z_.ww_id left join pp t1 on t1.id = t0.pview_id where u2.id = ? order by t1.value");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class TestViewBaseEntity extends BaseTestCase {
|
||||
|
||||
List<EOrderAgg> list = query.findList();
|
||||
|
||||
assertThat(sqlOf(query, 3)).contains("select t0.order_id, t0.order_total, t0.ship_total, t0.order_id from order_agg_vw t0 where t0.order_total > ? ");
|
||||
assertThat(sqlOf(query, 3)).contains("select t0.order_id, t0.order_total, t0.ship_total, t0.order_id from order_agg_vw t0 where t0.order_total > ?");
|
||||
assertThat(list).isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.tests.query;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
String s = q.getGeneratedSql();
|
||||
|
||||
assertThat(s).contains("(t0.name like ");
|
||||
assertThat(s).contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )");
|
||||
assertThat(s).contains(" and t0.anniversary = ?) or (t0.status = ? and t0.id > ?)");
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
String s = q.getGeneratedSql();
|
||||
|
||||
assertThat(s).contains("(t0.name like ");
|
||||
assertThat(s).contains(" and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )");
|
||||
assertThat(s).contains(" and t0.anniversary = ?) or (t0.status = ? and t0.id > ?)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
q.findList();
|
||||
String s = q.getGeneratedSql();
|
||||
|
||||
assertThat(s).contains("where not (t0.id > ? and t0.anniversary = ? ) order by t0.name");
|
||||
assertThat(s).contains("where not (t0.id > ? and t0.anniversary = ?) order by t0.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +95,7 @@ public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
q.findList();
|
||||
String s = q.getGeneratedSql();
|
||||
|
||||
assertThat(s).contains("where (t0.status = ? or not (t0.id > ? and t0.anniversary = ? ) )");
|
||||
assertThat(s).contains("where (t0.status = ? or not (t0.id > ? and t0.anniversary = ?))");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,6 +119,6 @@ public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
q.findList();
|
||||
String s = q.getGeneratedSql();
|
||||
|
||||
assertThat(s).contains("where (t0.status = ? or not (t0.id > ? and t0.anniversary = ? ) )");
|
||||
assertThat(s).contains("where (t0.status = ? or not (t0.id > ? and t0.anniversary = ?))");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
|
||||
} else {
|
||||
String expectedSql = "select distinct t0.id, t0.name from o_customer t0 join o_order u1 on u1.kcustomer_id = t0.id join o_order_detail u2 on u2.order_id = u1.id join o_product u3 on u3.id = u2.product_id where u3.name = ? ";
|
||||
String expectedSql = "select distinct t0.id, t0.name from o_customer t0 join o_order u1 on u1.kcustomer_id = t0.id join o_order_detail u2 on u2.order_id = u1.id join o_product u3 on u3.id = u2.product_id where u3.name = ?";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
|
||||
String expectedSql = "select distinct on (t0.id) t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id left join o_order_detail u2 on u2.order_id = u1.id left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ? ) ";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
} else {
|
||||
String expectedSql = "select distinct t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id left join o_order_detail u2 on u2.order_id = u1.id left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ? ) ";
|
||||
String expectedSql = "select distinct t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id left join o_order_detail u2 on u2.order_id = u1.id left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ?)";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
|
||||
} else {
|
||||
String expectedSql = "select distinct t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id left join o_order_detail u2 on u2.order_id = u1.id left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ? ) ";
|
||||
String expectedSql = "select distinct t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id left join o_order_detail u2 on u2.order_id = u1.id left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ?)";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TestQueryExists extends BaseTestCase {
|
||||
|
||||
String sql = sqlOf(query);
|
||||
if (isH2() || isPostgres()) {
|
||||
assertThat(sql).contains("select t0.id from o_order t0 where t0.id > ? limit 1");
|
||||
assertThat(sql).contains("select t0.id from o_order t0 where t0.id > ? limit 1");
|
||||
}
|
||||
|
||||
assertThat(Ebean.find(Order.class).where().gt("id", 1).exists()).isTrue();
|
||||
|
||||
@@ -154,7 +154,7 @@ public class TestQueryFilterMany extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertEquals(2, sql.size());
|
||||
assertThat(sql.get(1)).contains("and (t0.status = ? or t0.order_date = ?");
|
||||
assertThat(sql.get(1)).contains("and (t0.status = ? or t0.order_date = ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -95,7 +95,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.units), sum(u1.units * u1.amount) from tevent_one t0");
|
||||
assertThat(sql).contains("from tevent_one t0 join tevent_many u1 on u1.event_id = t0.id ");
|
||||
assertThat(sql).contains("where u1.description like ");
|
||||
assertThat(sql).contains(" group by t0.id, t0.name having count(u1.id) >= ? order by t0.name");
|
||||
assertThat(sql).contains(" group by t0.id, t0.name having count(u1.id) >= ? order by t0.name");
|
||||
|
||||
// invoke lazy loading
|
||||
Long version = list.get(0).getVersion();
|
||||
@@ -169,7 +169,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
.orderBy().asc("name");
|
||||
|
||||
query1.findList();
|
||||
assertThat(query1.getGeneratedSql()).contains("having count(u1.id) >= ? order by t0.name");
|
||||
assertThat(query1.getGeneratedSql()).contains("having count(u1.id) >= ? order by t0.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -391,7 +391,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
assertThat(names).isNotEmpty();
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(trimSql(sql.get(0))).contains("select " + concat("t0.last_name",", ","t0.first_name") + " from contact t0 where t0.phone is null order by t0.last_name");
|
||||
assertThat(trimSql(sql.get(0))).contains("select " + concat("t0.last_name",", ","t0.first_name") + " from contact t0 where t0.phone is null order by t0.last_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -459,7 +459,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.email, " + concat("t0.last_name",", ","t0.first_name") + " lastName from contact t0 where t0.phone is null order by t0.last_name; --bind()");
|
||||
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.email, " + concat("t0.last_name",", ","t0.first_name") + " lastName from contact t0 where t0.phone is null order by t0.last_name; --bind()");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TestDisjunctWhereOuterJoin extends BaseTestCase {
|
||||
|
||||
String sql = sqlOf(query);
|
||||
assertSqlOuterJoins(sql);
|
||||
assertThat(sql).contains("where (t0.user_name = ? or u1.roleid = ? )");
|
||||
assertThat(sql).contains("where (t0.user_name = ? or u1.roleid = ?)");
|
||||
}
|
||||
|
||||
private void queryOrExpression(Integer roleid) {
|
||||
@@ -95,7 +95,7 @@ public class TestDisjunctWhereOuterJoin extends BaseTestCase {
|
||||
|
||||
String sql = sqlOf(query);
|
||||
assertSqlOuterJoins(sql);
|
||||
assertThat(sql).contains("where (t0.user_name = ? or u1.roleid = ? )");
|
||||
assertThat(sql).contains("where (t0.user_name = ? or u1.roleid = ?)");
|
||||
}
|
||||
|
||||
private void assertSqlOuterJoins(String sql) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class TestDisjunctWhereOuterOnMany extends BaseTestCase {
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
|
||||
} else {
|
||||
String expectedSql = "select distinct t0.id, t0.name, t0.description, t0.version from uuone t0 left join uutwo u1 on u1.master_id = t0.id where (t0.name = ? or u1.name = ? ) ";
|
||||
String expectedSql = "select distinct t0.id, t0.name, t0.description, t0.version from uuone t0 left join uutwo u1 on u1.master_id = t0.id where (t0.name = ? or u1.name = ?)";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ package org.tests.query.other;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import org.tests.model.converstation.Conversation;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.converstation.Conversation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TestQueryConversationRowCount extends BaseTestCase {
|
||||
assertThat(generatedSql).contains("select distinct t0.id, t0.title, t0.isopen");
|
||||
}
|
||||
assertThat(generatedSql).contains("left join c_participation u1 on u1.conversation_id = t0.id");
|
||||
assertThat(generatedSql).contains("where t0.group_id = ? and ((t0.isopen = ? and u1.user_id = ? ) or t0.isopen = ? )");
|
||||
assertThat(generatedSql).contains("where t0.group_id = ? and ((t0.isopen = ? and u1.user_id = ?) or t0.isopen = ?)");
|
||||
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
@@ -66,7 +66,7 @@ public class TestQueryConversationRowCount extends BaseTestCase {
|
||||
Assert.assertEquals(1, loggedSql.size());
|
||||
|
||||
String countSql = trimSql(loggedSql.get(0), 0);
|
||||
assertThat(countSql).contains("select count(*) from ( select distinct t0.id from c_conversation t0 left join c_participation u1 on u1.conversation_id = t0.id where t0.group_id = ? and ((t0.isopen = ? and u1.user_id = ? ) or t0.isopen = ? )");
|
||||
assertThat(countSql).contains("select count(*) from ( select distinct t0.id from c_conversation t0 left join c_participation u1 on u1.conversation_id = t0.id where t0.group_id = ? and ((t0.isopen = ? and u1.user_id = ?) or t0.isopen = ?))");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package org.tests.query.other;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class TestQueryRowCountWithMany extends BaseTestCase {
|
||||
Assert.assertEquals(list.size(), rowCount);
|
||||
Assert.assertEquals(2, sqlLogged.size());
|
||||
assertThat(trimSql(sqlLogged.get(1), 1)).contains(
|
||||
"select count(*) from ( select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id where u1.product_id = ? )");
|
||||
"select count(*) from ( select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id where u1.product_id = ?)");
|
||||
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class TestQueryRowCountWithMany extends BaseTestCase {
|
||||
List<String> sqlLogged = LoggedSqlCollector.stop();
|
||||
|
||||
Assert.assertEquals(1, sqlLogged.size());
|
||||
assertThat(trimSql(sqlLogged.get(0), 1)).contains("select count(*) from ( select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id where u1.product_id = ? )");
|
||||
assertThat(trimSql(sqlLogged.get(0), 1)).contains("select count(*) from ( select distinct t0.id from o_order t0 join o_order_detail u1 on u1.order_id = t0.id where u1.product_id = ?)");
|
||||
|
||||
query.findList();
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
.orderBy().asc("name");
|
||||
|
||||
query.findSingleAttributeList();
|
||||
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 where t0.status = ? order by t0.name");
|
||||
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 where t0.status = ? order by t0.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,7 +140,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
|
||||
List<String> names = query.findSingleAttributeList();
|
||||
|
||||
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 where t0.status = ? ");
|
||||
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 where t0.status = ?");
|
||||
assertThat(names).isNotNull();
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
|
||||
List<String> names = query.findSingleAttributeList();
|
||||
|
||||
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t0.status = ? and lower(t1.city) like ");
|
||||
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 left join o_address t1 on t1.id = t0.billing_address_id where t0.status = ? and lower(t1.city) like ");
|
||||
assertThat(names).isNotNull();
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
assertThat(sqlOf(query)).contains("select distinct t1.billing_address_id from contact t0 "
|
||||
+ "join o_customer t1 on t1.id = t0.customer_id " // two spaces!
|
||||
+ "left join o_address t2 on t2.id = t1.billing_address_id "
|
||||
+ "where t2.city = ? "
|
||||
+ "where t2.city = ? "
|
||||
+ "order by t1.billing_address_id desc");
|
||||
}
|
||||
|
||||
@@ -427,7 +427,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
assertThat(sqlOf(query)).contains("select distinct t1.billing_address_id from contact t0 "
|
||||
+ "join o_customer t1 on t1.id = t0.customer_id "
|
||||
+ "left join o_address t2 on t2.id = t1.billing_address_id "
|
||||
+ "where t2.city = ? "
|
||||
+ "where t2.city = ? "
|
||||
+ "order by t1.billing_address_id desc");
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
assertThat(sqlOf(query)).contains("select distinct t1.billing_address_id from contact t0 "
|
||||
+ "join o_customer t1 on t1.id = t0.customer_id "
|
||||
+ "left join o_address t2 on t2.id = t1.billing_address_id "
|
||||
+ "where t2.city = ? "
|
||||
+ "where t2.city = ? "
|
||||
+ "order by t1.billing_address");
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
assertThat(sqlOf(query)).contains("select distinct t1.billing_address_id from contact t0 "
|
||||
+ "join o_customer t1 on t1.id = t0.customer_id "
|
||||
+ "left join o_address t2 on t2.id = t1.shipping_address_id "
|
||||
+ "where t2.city = ? "
|
||||
+ "where t2.city = ? "
|
||||
+ "order by t1.billing_address_id desc");
|
||||
|
||||
}
|
||||
@@ -533,7 +533,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
assertThat(sqlOf(query)).contains("select r1.attribute_, count(*) from ("
|
||||
+ "select t0.first_name as attribute_ from contact t0 "
|
||||
+ "join o_customer t1 on t1.id = t0.customer_id "
|
||||
+ "left join o_address t2 on t2.id = t1.shipping_address_id where t2.line_1 = ? "
|
||||
+ "left join o_address t2 on t2.id = t1.shipping_address_id where t2.line_1 = ?"
|
||||
+ ") r1 group by r1.attribute_ order by r1.attribute_");
|
||||
assertThat(list3.get(0)).isInstanceOf(CountedValue.class);
|
||||
//assertThat(list3.toString()).isEqualTo("[1: Bugs1, 1: Fiona, 1: Fred1, 1: Jim1, 1: Tracy]");
|
||||
@@ -552,7 +552,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
+ "from contact t0 join o_customer t1 on t1.id = t0.customer_id "
|
||||
+ "left join o_address t2 on t2.id = t1.billing_address_id "
|
||||
+ "left join o_address t3 on t3.id = t1.shipping_address_id "
|
||||
+ "where (t3.line_1 <> ? or t3.line_1 is null ) "
|
||||
+ "where (t3.line_1 <> ? or t3.line_1 is null)"
|
||||
+ ") r1 group by r1.attribute_ order by r1.attribute_");
|
||||
assertThat(list4.get(0)).isInstanceOf(CountedValue.class);
|
||||
//assertThat(list4.toString()).isEqualTo("[1: null, 3: Bos town, 3: P.O.Box 1234]");
|
||||
@@ -568,7 +568,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
|
||||
+ "select t2.line_1 as attribute_ from contact t0 "
|
||||
+ "join o_customer t1 on t1.id = t0.customer_id "
|
||||
+ "left join o_address t2 on t2.id = t1.billing_address_id "
|
||||
+ "where t2.line_1 is not null "
|
||||
+ "where t2.line_1 is not null"
|
||||
+ ") r1 group by r1.attribute_ order by r1.attribute_ desc ");
|
||||
if (isSqlServer()) {
|
||||
assertThat(sqlOf(query)).endsWith(" fetch next 2 rows only");
|
||||
|
||||
@@ -79,8 +79,8 @@ public class TestSoftDeleteBasic extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains("from ebasic_sdchild t0 where t0.owner_id = ? and t0.deleted = ");
|
||||
assertThat(sql.get(1)).contains("from ebasic_sdchild t0 where t0.owner_id = ? and t0.deleted = ");
|
||||
assertThat(sql.get(0)).contains("from ebasic_sdchild t0 where t0.owner_id = ? and t0.deleted = ");
|
||||
assertThat(sql.get(1)).contains("from ebasic_sdchild t0 where t0.owner_id = ? and t0.deleted = ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user