You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by st...@apache.org on 2021/04/05 17:42:05 UTC

[openjpa] branch master updated: OPENJPA-2860 PostgreSQL >= 10 supports setQueryTimeout

This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git


The following commit(s) were added to refs/heads/master by this push:
     new 044c7d2  OPENJPA-2860 PostgreSQL >= 10 supports setQueryTimeout
044c7d2 is described below

commit 044c7d27b1e787509d00837443511a9f76cbf6dc
Author: Mark Struberg <st...@apache.org>
AuthorDate: Mon Apr 5 18:16:48 2021 +0200

    OPENJPA-2860 PostgreSQL >= 10 supports setQueryTimeout
---
 .../org/apache/openjpa/jdbc/schema/SchemaTool.java |  3 +--
 .../openjpa/jdbc/sql/PostgresDictionary.java       | 23 +++++++++++++++++-----
 .../openjpa/jdbc/sql/sql-error-state-codes.xml     |  2 +-
 .../persistence/query/TestTimeoutException.java    |  1 +
 4 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
index e138c74..6abe8cd 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
@@ -1317,8 +1317,7 @@ public class SchemaTool {
                     }
                 }
                 if (!tables.isEmpty())
-                    gen.generateSchemas((DBIdentifier[]) tables.toArray
-                        (new DBIdentifier[tables.size()]));
+                    gen.generateSchemas(tables.toArray(new DBIdentifier[tables.size()]));
             }
             _db = gen.getSchemaGroup();
         }
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
index c6a94b6..dd47fc2 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
@@ -176,7 +176,6 @@ public class PostgresDictionary extends DBDictionary {
         booleanRepresentation = BooleanRepresentationFactory.BOOLEAN;
 
         supportsLockingWithDistinctClause = false;
-        supportsQueryTimeout = false;
         supportsLockingWithOuterJoin = false;
 
         reservedWordSet.addAll(Arrays.asList(new String[]{
@@ -212,8 +211,13 @@ public class PostgresDictionary extends DBDictionary {
         _timestampTypes.add(timestampTypeName.toUpperCase(Locale.ENGLISH)); // handle user configured timestamp types.
 
         indexPhysicalForeignKeys = true; // PostgreSQL does not automatically create an index for a foreign key so we will
+
+        // PostgreSQL requires to escape search strings
+        requiresSearchStringEscapeForLike = true;
     }
 
+
+
     @Override
     public Date getDate(ResultSet rs, int column)
         throws SQLException {
@@ -796,7 +800,7 @@ public class PostgresDictionary extends DBDictionary {
     }
 
     /**
-     * Determine XML column support and backslash handling.
+     * Determine XML column support and backslash handling, etc
      */
     @Override
     public void connectedConfiguration(Connection conn) throws SQLException {
@@ -825,9 +829,10 @@ public class PostgresDictionary extends DBDictionary {
         if ((maj >= 9 || (maj == 8 && min >= 3))) {
             supportsXMLColumn = true;
         }
-
-        // PostgreSQL requires to escape search strings
-        requiresSearchStringEscapeForLike = true;
+        if (maj < 10) {
+            // setQueryTimeout only got implemented pretty late
+            supportsQueryTimeout = false;
+        }
 
         // Old PostgreSQL requires double-escape for strings.
         if ((maj <= 8 || (maj == 9 && min == 0))) {
@@ -835,6 +840,14 @@ public class PostgresDictionary extends DBDictionary {
         }
     }
 
+    @Override
+    public boolean isFatalException(int subtype, SQLException ex) {
+        if ((subtype == StoreException.LOCK  && "57014".equals(ex.getSQLState()))) {
+            return false;
+        }
+        return super.isFatalException(subtype, ex);
+    }
+
     /**
      * If column is an XML column, PostgreSQL requires that its value is set
      * by using {@link PreparedStatement#setObject(int, Object, int)}
diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
index afcff44..6e9a4a5 100644
--- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
+++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
@@ -191,7 +191,7 @@
 	</dictionary>
 
 	<dictionary class="org.apache.openjpa.jdbc.sql.PostgresDictionary">
-		<lock>55P03,40P01</lock>
+		<lock>55P03,40P01,57014</lock>
 		<referential-integrity>23000,23502,23503,23514</referential-integrity>
 		<object-exists>23505</object-exists>
 		<object-not-found></object-not-found>
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java
index 7956455..cbf276a 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestTimeoutException.java
@@ -53,6 +53,7 @@ public class TestTimeoutException extends SingleEMFTestCase {
         assertNotNull(dict);
         if (!dict.supportsSelectForUpdate || !dict.supportsQueryTimeout || dict instanceof SolidDBDictionary)
             setTestsDisabled(true);
+
         if (emf == null) {
             closeEMF(tempEMF);
         }