From 0edfcb534184a6d50475b9c26b404e6bf66edd44 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 29 Apr 2024 18:32:53 +0200 Subject: [PATCH] Get rid of double quoting SQL identifiers to avoid case sensitive mode on PostgreSQL --- .../core/annotations/nativequery/Client.java | 48 +++++++++---------- .../core/entitytest/apitests/Client.java | 2 +- .../core/entitytest/apitests/Coffee.java | 6 +-- .../entitytest/apitests/CoffeeMappedSC.java | 2 +- .../entitytest/apitests/myMappingFile.xml | 4 +- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/nativequery/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/nativequery/Client.java index b31919d932..a5a53b7089 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/nativequery/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/annotations/nativequery/Client.java @@ -105,9 +105,9 @@ public void nativeQueryTest2() throws Exception { getEntityManager().persist(o9); logger.log(Logger.Level.TRACE, "Execute Query"); - q = getEntityManager().createNativeQuery("Select o.\"ID\" AS \"OID\", o.\"TOTALPRICE\" AS \"OPRICE\", " - + "o.\"FK1_FOR_ITEM\" AS \"OITEM\", i.\"ITEMNAME\" AS \"INAME\" from \"ORDER1\" o, \"ITEM\" i " - + "WHERE (o.\"TOTALPRICE\" < 100) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")", "Order2ItemResults") + q = getEntityManager().createNativeQuery("Select o.ID AS \"OID\", o.TOTALPRICE AS \"OPRICE\", " + + "o.FK1_FOR_ITEM AS \"OITEM\", i.ITEMNAME AS \"INAME\" from ORDER1 o, ITEM i " + + "WHERE (o.TOTALPRICE < 100) AND (o.FK1_FOR_ITEM = i.ID)", "Order2ItemResults") .getResultList(); if (q.size() != 1) { @@ -217,9 +217,9 @@ public void nativeQueryTest3() throws Exception { logger.log(Logger.Level.TRACE, "Execute Query"); q = getEntityManager() - .createNativeQuery("Select o.\"ID\" AS \"THISID\", o.\"TOTALPRICE\" AS \"THISPRICE\", " - + "o.\"FK1_FOR_ITEM\" AS \"THISITEM\", i.\"ID\", i.\"ITEMNAME\" from \"ORDER1\" o, \"ITEM\" i " - + "WHERE (o.\"TOTALPRICE\" > 140) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")", "Order3ItemResults") + .createNativeQuery("Select o.ID AS \"THISID\", o.TOTALPRICE AS \"THISPRICE\", " + + "o.FK1_FOR_ITEM AS \"THISITEM\", i.ID, i.\"ITEMNAME\" from ORDER1 o, ITEM i " + + "WHERE (o.TOTALPRICE > 140) AND (o.FK1_FOR_ITEM = i.ID)", "Order3ItemResults") .getResultList(); if (q.size() != 1) { @@ -322,9 +322,9 @@ public void nativeQueryColumnResultTypeTest() throws Exception { getEntityManager().persist(o9); logger.log(Logger.Level.TRACE, "Execute Query"); - q = getEntityManager().createNativeQuery("Select o.\"ID\" AS \"OID\", o.\"TOTALPRICE\" AS \"OPRICE\", " - + "o.\"FK1_FOR_ITEM\" AS \"OITEM\", i.\"ITEMNAME\" AS \"INAME\" from \"ORDER1\" o, \"ITEM\" i " - + "WHERE (o.\"TOTALPRICE\" < 100) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")", "Order4ItemResults") + q = getEntityManager().createNativeQuery("Select o.ID AS \"OID\", o.TOTALPRICE AS \"OPRICE\", " + + "o.FK1_FOR_ITEM AS \"OITEM\", i.ITEMNAME AS \"INAME\" from ORDER1 o, ITEM i " + + "WHERE (o.TOTALPRICE < 100) AND (o.FK1_FOR_ITEM = i.ID)", "Order4ItemResults") .getResultList(); if (q.size() != 1) { @@ -430,9 +430,9 @@ public void nativeQueryTestConstructorResult() throws Exception { logger.log(Logger.Level.TRACE, "Execute Query"); q = getEntityManager() .createNativeQuery( - "Select o.\"ID\" AS \"OID\", o.\"TOTALPRICE\" AS \"OPRICE\", " - + "i.\"ITEMNAME\" AS \"OITEMNAME\" from \"ORDER1\" o, \"ITEM\" i " - + "WHERE (o.\"TOTALPRICE\" < 100) AND (o.\"FK1_FOR_ITEM\" = i.\"ID\")", + "Select o.ID AS \"OID\", o.TOTALPRICE AS \"OPRICE\", " + + "i.ITEMNAME AS \"OITEMNAME\" from ORDER1 o, ITEM i " + + "WHERE (o.TOTALPRICE < 100) AND (o.FK1_FOR_ITEM = i.ID)", "Order5ItemResults") .getResultList(); @@ -500,8 +500,8 @@ public void nativeQueryTestConstructorResultWithId() throws Exception { logger.log(Logger.Level.TRACE, "Execute Query"); q = getEntityManager().createNativeQuery( - "Select o.\"ID\" AS \"OID\", o.\"TOTAL\" AS \"PTOTAL\" from \"PURCHASE_ORDER\" o " - + "WHERE (o.\"TOTAL\" < 50)", + "Select o.ID AS \"OID\", o.TOTAL AS \"PTOTAL\" from PURCHASE_ORDER o " + + "WHERE (o.TOTAL < 50)", "PurchaseOrder1Results").getResultList(); if (q.size() != 1) { @@ -568,7 +568,7 @@ public void nativeQueryTestConstructorResultNoId() throws Exception { logger.log(Logger.Level.TRACE, "Execute Query"); q = getEntityManager().createNativeQuery( - "Select o.\"TOTAL\" AS \"PTOTAL\" from \"PURCHASE_ORDER\" o " + "WHERE (o.\"TOTAL\" < 50)", + "Select o.TOTAL AS \"PTOTAL\" from PURCHASE_ORDER o " + "WHERE (o.TOTAL < 50)", "PurchaseOrder2Results").getResultList(); if (q.size() != 1) { @@ -640,7 +640,7 @@ public void createNativeQueryStringTest() throws Exception { getEntityManager().persist(o3); logger.log(Logger.Level.TRACE, "Execute Query"); - q = getEntityManager().createNativeQuery("Select o.\"ID\" from \"ORDER1\" o WHERE o.\"ID\" = 2 ") + q = getEntityManager().createNativeQuery("Select o.ID from ORDER1 o WHERE o.ID = 2 ") .getResultList(); List actual = new ArrayList(); @@ -703,7 +703,7 @@ public void createNativeQueryResultClassTest() throws Exception { getEntityManager().persist(o3); logger.log(Logger.Level.TRACE, "Execute Query"); - q = getEntityManager().createNativeQuery("Select * from \"ORDER1\" o WHERE o.\"ID\" = 2 ", Order1.class) + q = getEntityManager().createNativeQuery("Select * from ORDER1 o WHERE o.ID = 2 ", Order1.class) .getResultList(); if (q.size() != 1) { @@ -765,7 +765,7 @@ public void createNativeQueryResultClassTQTest() throws Exception { getEntityManager().persist(o3); logger.log(Logger.Level.TRACE, "Execute Query"); - q = getEntityManager().createNativeQuery("Select * from \"ORDER1\" o WHERE o.\"ID\" = 2 ", Order1.class) + q = getEntityManager().createNativeQuery("Select * from ORDER1 o WHERE o.ID = 2 ", Order1.class) .getResultList(); if (q.size() != 1) { @@ -804,7 +804,7 @@ public void createNativeQueryResultClassTQTest() throws Exception { public void executeUpdateTransactionRequiredExceptionTest() throws Exception { boolean pass = false; try { - getEntityManager().createNativeQuery("Delete from \"ORDER1\"").executeUpdate(); + getEntityManager().createNativeQuery("Delete from ORDER1").executeUpdate(); logger.log(Logger.Level.ERROR, "TransactionRequiredException was not thrown"); } catch (TransactionRequiredException ise) { logger.log(Logger.Level.TRACE, "Received expected TransactionRequiredException"); @@ -857,7 +857,7 @@ public void setParameterTest() throws Exception { getEntityManager().persist(o3); logger.log(Logger.Level.TRACE, "Execute Query"); - q = getEntityManager().createNativeQuery("Select * from \"ORDER1\" o WHERE o.\"ID\" = ? ", Order1.class) + q = getEntityManager().createNativeQuery("Select * from ORDER1 o WHERE o.ID = ? ", Order1.class) .setParameter(1, 2).getResultList(); if (q.size() != 1) { @@ -917,7 +917,7 @@ public void getSingleResultTest() throws Exception { getEntityManager().persist(o3); logger.log(Logger.Level.TRACE, "Execute Query"); - q = getEntityManager().createNativeQuery("Select COUNT(*) from \"ORDER1\" o").getSingleResult(); + q = getEntityManager().createNativeQuery("Select COUNT(*) from ORDER1 o").getSingleResult(); int i = 0; i = convertToInt(q); if (i == 3) { @@ -957,9 +957,9 @@ private void removeTestData() { try { getEntityTransaction().begin(); getEntityManager().createNativeQuery("Delete FROM ORDER2").executeUpdate(); - getEntityManager().createNativeQuery("Delete FROM \"ORDER1\"").executeUpdate(); - getEntityManager().createNativeQuery("Delete FROM \"ITEM\"").executeUpdate(); - getEntityManager().createNativeQuery("Delete FROM \"PURCHASE_ORDER\"").executeUpdate(); + getEntityManager().createNativeQuery("Delete FROM ORDER1").executeUpdate(); + getEntityManager().createNativeQuery("Delete FROM ITEM").executeUpdate(); + getEntityManager().createNativeQuery("Delete FROM PURCHASE_ORDER").executeUpdate(); getEntityTransaction().commit(); } catch (Exception e) { diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Client.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Client.java index 614507a69c..dca8fdda91 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Client.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Client.java @@ -992,7 +992,7 @@ private void removeTestData() { } try { getEntityTransaction().begin(); - getEntityManager().createNativeQuery("DELETE FROM \"COFFEE\"").executeUpdate(); + getEntityManager().createNativeQuery("DELETE FROM COFFEE").executeUpdate(); getEntityTransaction().commit(); } catch (Exception e) { logger.log(Logger.Level.ERROR, "Exception encountered while removing entities:", e); diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Coffee.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Coffee.java index d532f07ce8..0811f3bdba 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Coffee.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/Coffee.java @@ -29,9 +29,9 @@ import jakarta.persistence.Table; @NamedNativeQueries({ - @NamedNativeQuery(name = "findAllSQLCoffees2", query = "select \"ID\", \"BRANDNAME\", \"PRICE\" from \"COFFEE\"", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class), - @NamedNativeQuery(name = "findAllSQLCoffees", query = "select \"ID\", \"BRANDNAME\", \"PRICE\" from \"COFFEE\"", resultSetMapping = "CoffeeResult"), - @NamedNativeQuery(name = "xmlOverridesNamedNativeQuery", query = "select \"ID\", \"BRANDNAME\", \"PRICE\" from \"COFFEE\"", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class) }) + @NamedNativeQuery(name = "findAllSQLCoffees2", query = "select ID, BRANDNAME, PRICE from COFFEE c", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class), + @NamedNativeQuery(name = "findAllSQLCoffees", query = "select ID, BRANDNAME, PRICE from COFFEE c", resultSetMapping = "CoffeeResult"), + @NamedNativeQuery(name = "xmlOverridesNamedNativeQuery", query = "select ID, BRANDNAME, PRICE from COFFEE c", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class) }) @SqlResultSetMapping(name = "CoffeeResult", entities = @EntityResult(entityClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class)) @NamedQueries({ @NamedQuery(name = "findAllCoffees", query = "Select c from Coffee c", lockMode = LockModeType.PESSIMISTIC_READ), diff --git a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/CoffeeMappedSC.java b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/CoffeeMappedSC.java index 893bb493be..2c304d5219 100644 --- a/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/CoffeeMappedSC.java +++ b/jpa/spec-tests/src/main/java/ee/jakarta/tck/persistence/core/entitytest/apitests/CoffeeMappedSC.java @@ -24,7 +24,7 @@ import jakarta.persistence.NamedQuery; @NamedNativeQueries({ - @NamedNativeQuery(name = "findDecafSQLCoffees", query = "Select c.\"ID\", c.\"BRANDNAME\", c.\"PRICE\" from \"COFFEE\" c where c.\"BRANDNAME\" like '%decaf%' ", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class) }) + @NamedNativeQuery(name = "findDecafSQLCoffees", query = "Select c.ID, c.BRANDNAME, c.PRICE from COFFEE c where c.BRANDNAME like '%decaf%' ", resultClass = ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee.class) }) @NamedQueries({ @NamedQuery(name = "findDecafCoffees", query = "Select c from Coffee c where c.brandName like '%decaf%'") }) diff --git a/jpa/spec-tests/src/main/resources/ee/jakarta/tck/persistence/core/entitytest/apitests/myMappingFile.xml b/jpa/spec-tests/src/main/resources/ee/jakarta/tck/persistence/core/entitytest/apitests/myMappingFile.xml index d6b060df7f..d6219be9e9 100644 --- a/jpa/spec-tests/src/main/resources/ee/jakarta/tck/persistence/core/entitytest/apitests/myMappingFile.xml +++ b/jpa/spec-tests/src/main/resources/ee/jakarta/tck/persistence/core/entitytest/apitests/myMappingFile.xml @@ -29,10 +29,10 @@ Select c from Coffee c where c.brandName='decaf' - select c."ID", c."BRANDNAME", c."PRICE" from "COFFEE" c WHERE c."BRANDNAME" = 'decaf' + select c.ID, c.BRANDNAME, c.PRICE from COFFEE c WHERE c.BRANDNAME = 'decaf' - select c."ID", c."BRANDNAME", c."PRICE" from "COFFEE" c WHERE c."BRANDNAME" = 'decaf' + select c.ID, c.BRANDNAME, c.PRICE from COFFEE c WHERE c.BRANDNAME = 'decaf'