From 264842393026308166b681e27756714a4efc557f Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Wed, 8 May 2019 23:22:13 +1200 Subject: [PATCH] #1696 - Refactor - trim unnecessary whitespace around IN clause bind parameters --- .../server/persist/platform/MultiValueBind.java | 4 ++-- src/test/java/org/tests/cache/TestBeanCache.java | 6 +++--- src/test/java/org/tests/merge/TestMergeCustomer.java | 2 +- .../org/tests/model/aggregation/TestAggregationMany.java | 2 +- .../model/basic/cache/TestCacheViaComplexNaturalKey.java | 6 +++--- .../model/basic/cache/TestCacheViaComplexNaturalKey3.java | 8 ++++---- .../org/tests/model/history/TestHistoryOneToMany.java | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/ebeaninternal/server/persist/platform/MultiValueBind.java b/src/main/java/io/ebeaninternal/server/persist/platform/MultiValueBind.java index 7df88ebde..41fbc3f6f 100644 --- a/src/main/java/io/ebeaninternal/server/persist/platform/MultiValueBind.java +++ b/src/main/java/io/ebeaninternal/server/persist/platform/MultiValueBind.java @@ -62,9 +62,9 @@ public class MultiValueBind { } sb.append(" in (?"); for (int i = 1; i < size; i++) { - sb.append(", ").append("?"); + sb.append(",?"); } - sb.append(" ) "); + sb.append(")"); return sb.toString(); } } diff --git a/src/test/java/org/tests/cache/TestBeanCache.java b/src/test/java/org/tests/cache/TestBeanCache.java index 42af7612f..783c300a5 100644 --- a/src/test/java/org/tests/cache/TestBeanCache.java +++ b/src/test/java/org/tests/cache/TestBeanCache.java @@ -76,7 +76,7 @@ public class TestBeanCache extends BaseTestCase { List sql = LoggedSqlCollector.current(); assertThat(sql).hasSize(1); if (isH2()) { - assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?, ?, ? )"); + assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?,?,?)"); } log.info("All hits (3 of 3) ..."); @@ -105,7 +105,7 @@ public class TestBeanCache extends BaseTestCase { assertThat(sql).hasSize(1); if (isH2()) { // fetch the miss from DB - assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (? )"); + assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?)"); } // remove beans so that we get a "partial" hit (1 out of 3 in cache) @@ -124,7 +124,7 @@ public class TestBeanCache extends BaseTestCase { assertThat(sql).hasSize(1); if (isH2()) { // fetch the misses from DB - assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?, ? )"); + assertThat(sql.get(0)).contains("from o_cached_bean t0 where t0.id in (?,?)"); } } diff --git a/src/test/java/org/tests/merge/TestMergeCustomer.java b/src/test/java/org/tests/merge/TestMergeCustomer.java index 4b4a38b78..6990a8f65 100644 --- a/src/test/java/org/tests/merge/TestMergeCustomer.java +++ b/src/test/java/org/tests/merge/TestMergeCustomer.java @@ -313,7 +313,7 @@ public class TestMergeCustomer extends BaseTestCase { assertThat(sql.get(0)).contains("select t0.id, t3.id, t1.id, t2.id from mcustomer t0 left join maddress t3 on t3.id = t0.shipping_address_id left join maddress t1 on t1.id = t0.billing_address_id left join mcontact t2 on t2.customer_id = t0.id where t0.id = ?"); if (isH2() || isHana()) { // with nested OneToMany .. we need a second query to read the contact message ids - assertThat(sql.get(1)).contains("select t0.contact_id, t0.id from mcontact_message t0 where (t0.contact_id) in (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"); + assertThat(sql.get(1)).contains("select t0.contact_id, t0.id from mcontact_message t0 where (t0.contact_id) in (?,?,?,?,?,?,?,?,?,?)"); } assertThat(sql.get(2)).contains("delete from mcontact_message where contact_id = ?"); assertThat(sql.get(3)).contains("delete from mcontact where id=?"); diff --git a/src/test/java/org/tests/model/aggregation/TestAggregationMany.java b/src/test/java/org/tests/model/aggregation/TestAggregationMany.java index 093221042..462783597 100644 --- a/src/test/java/org/tests/model/aggregation/TestAggregationMany.java +++ b/src/test/java/org/tests/model/aggregation/TestAggregationMany.java @@ -36,7 +36,7 @@ public class TestAggregationMany extends BaseTestCase { assertThat(machines).hasSize(5); if (isH2()) { - assertThat(sql.get(1)).contains("select t0.machine_id, t0.name, sum(t0.use_secs), sum(t0.fuel) from d_machine_aux_use t0 where (t0.machine_id) in (?, ?, ?, ?, ? ) group by t0.machine_id, t0.name;"); + assertThat(sql.get(1)).contains("select t0.machine_id, t0.name, sum(t0.use_secs), sum(t0.fuel) from d_machine_aux_use t0 where (t0.machine_id) in (?,?,?,?,?) group by t0.machine_id, t0.name;"); } } diff --git a/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey.java b/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey.java index c9352f5fc..a822c3e94 100644 --- a/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey.java +++ b/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey.java @@ -110,7 +110,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); @@ -149,7 +149,7 @@ public class TestCacheViaComplexNaturalKey extends BaseTestCase { assertThat(list).hasSize(3); assertThat(sql).hasSize(1); if (isH2()) { - assertThat(sql.get(0)).contains("where t0.store = ? and t0.sku in (?, ? ) order by t0.sku desc; --bind(abc,Array[2]={1,3})"); + assertThat(sql.get(0)).contains("where t0.store = ? and t0.sku in (?,?) order by t0.sku desc; --bind(abc,Array[2]={1,3})"); } assertNaturalKeyHitMiss(1, 2); assertBeanCacheHitMiss(1, 0); @@ -207,7 +207,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); diff --git a/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey3.java b/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey3.java index 256c730e6..cb0ec0c58 100644 --- a/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey3.java +++ b/src/test/java/org/tests/model/basic/cache/TestCacheViaComplexNaturalKey3.java @@ -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,7 +278,7 @@ 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)"); } else if (isHana()) { @@ -321,7 +321,7 @@ 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')"); } else if (isHana()){ diff --git a/src/test/java/org/tests/model/history/TestHistoryOneToMany.java b/src/test/java/org/tests/model/history/TestHistoryOneToMany.java index 7ca93fbe7..589c4daba 100644 --- a/src/test/java/org/tests/model/history/TestHistoryOneToMany.java +++ b/src/test/java/org/tests/model/history/TestHistoryOneToMany.java @@ -51,7 +51,7 @@ public class TestHistoryOneToMany extends BaseTestCase { if (isH2()) { assertThat(sql).hasSize(2); assertThat(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' limit 10"); - assertThat(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (? )"); + assertThat(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (?)"); } assertThat(list).hasSize(1);