mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-11 01:37:07 +00:00
#1621 - Consider clean up white space in generated SQL (as in remove unneeded extra spaces)
This commit is contained in:
1 parent
5052afbd07
commit
89beaee0f6
46 files changed
+148
-137
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user