Skip to content

Commit

Permalink
Get rid of double quoting SQL identifiers to avoid case sensitive mod…
Browse files Browse the repository at this point in the history
…e on PostgreSQL
  • Loading branch information
beikov committed Apr 29, 2024
1 parent 7040630 commit 0edfcb5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<Integer> actual = new ArrayList<Integer>();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%'") })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<query>Select c from Coffee c where c.brandName='decaf'</query>
</named-query>
<named-native-query name="xmlNamedNativeQuery" result-class="ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee">
<query>select c."ID", c."BRANDNAME", c."PRICE" from "COFFEE" c WHERE c."BRANDNAME" = 'decaf'</query>
<query>select c.ID, c.BRANDNAME, c.PRICE from COFFEE c WHERE c.BRANDNAME = 'decaf'</query>
</named-native-query>
<named-native-query name="xmlOverridesNamedNativeQuery"
result-class="ee.jakarta.tck.persistence.core.entitytest.apitests.Coffee">
<query>select c."ID", c."BRANDNAME", c."PRICE" from "COFFEE" c WHERE c."BRANDNAME" = 'decaf'</query>
<query>select c.ID, c.BRANDNAME, c.PRICE from COFFEE c WHERE c.BRANDNAME = 'decaf'</query>
</named-native-query>
</entity-mappings>

0 comments on commit 0edfcb5

Please sign in to comment.