[openjpa] branch master updated (7bc0929 -> db6f6b6)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[openjpa] branch master updated (7bc0929 -> db6f6b6)

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

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


    from 7bc0929  OPENJPA-2753 fix schema creation with PostgreSQL
     new 60ccac0  OPENJPA-2753 postgres doesn't know BLOG
     new db6f6b6  OPENJPA-2756 escape search strings for all Postgres versions

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../openjpa/jdbc/sql/PostgresDictionary.java       |  5 ++++-
 .../schema/TestSchemaGenerationProperties.java     | 24 ++++++++++++++++++++--
 .../schema/{create.sql => create-postgresql.sql}   |  6 +++---
 3 files changed, 29 insertions(+), 6 deletions(-)
 copy openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/schema/{create.sql => create-postgresql.sql} (84%)

Reply | Threaded
Open this post in threaded view
|

[openjpa] 01/02: OPENJPA-2753 postgres doesn't know BLOG

struberg
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

commit 60ccac0e2201b023fa6194523ab733ea12ee1172
Author: Mark Struberg <[hidden email]>
AuthorDate: Sat Nov 10 16:45:24 2018 +0100

    OPENJPA-2753 postgres doesn't know BLOG
   
    have to use BYTEA instead.
---
 .../schema/TestSchemaGenerationProperties.java     | 24 ++++++++++++++++++++--
 .../persistence/jdbc/schema/create-postgresql.sql  | 14 +++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaGenerationProperties.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaGenerationProperties.java
index c2e75fe..b74c4a6 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaGenerationProperties.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaGenerationProperties.java
@@ -30,6 +30,8 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.meta.MappingTool;
 import org.apache.openjpa.jdbc.schema.SchemaGroup;
 import org.apache.openjpa.jdbc.schema.SchemaTool;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.PostgresDictionary;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
@@ -139,13 +141,23 @@ public class TestSchemaGenerationProperties extends BaseJDBCTest {
     }
 
     public void testSchemaGenScriptCreate() throws Exception {
+
         testSchemaGenMetadataDrop();
 
+        JDBCConfiguration conf = (JDBCConfiguration) getPM().getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+
+        String createSql =
+                dict instanceof PostgresDictionary
+                        ? "org/apache/openjpa/persistence/jdbc/schema/create-postgresql.sql"
+                        : "org/apache/openjpa/persistence/jdbc/schema/create.sql";
+
+
         Map<String, String> properties = new HashMap<>();
         properties.put("javax.persistence.schema-generation.database.action", "create");
         properties.put("javax.persistence.schema-generation.create-source", "script");
         properties.put("javax.persistence.schema-generation.create-script-source",
-                       "org/apache/openjpa/persistence/jdbc/schema/create.sql");
+                       createSql);
 
         SchemaGroup dbSchemaGroup = getSchemaGroup(properties);
 
@@ -158,6 +170,14 @@ public class TestSchemaGenerationProperties extends BaseJDBCTest {
     public void testSchemaGenScriptDropAndCreate() throws Exception {
         testSchemaGenMetadataCreate();
 
+        JDBCConfiguration conf = (JDBCConfiguration) getPM().getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+
+        String createSql =
+                dict instanceof PostgresDictionary
+                        ? "org/apache/openjpa/persistence/jdbc/schema/create-postgresql.sql"
+                        : "org/apache/openjpa/persistence/jdbc/schema/create.sql";
+
         Map<String, String> properties = new HashMap<>();
         properties.put("javax.persistence.schema-generation.database.action", "drop-and-create");
         properties.put("javax.persistence.schema-generation.drop-source", "script");
@@ -165,7 +185,7 @@ public class TestSchemaGenerationProperties extends BaseJDBCTest {
                        "org/apache/openjpa/persistence/jdbc/schema/drop.sql");
         properties.put("javax.persistence.schema-generation.create-source", "script");
         properties.put("javax.persistence.schema-generation.create-script-source",
-                       "org/apache/openjpa/persistence/jdbc/schema/create.sql");
+                       createSql);
 
         SchemaGroup dbSchemaGroup = getSchemaGroup(properties);
 
diff --git a/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/schema/create-postgresql.sql b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/schema/create-postgresql.sql
new file mode 100644
index 0000000..4a7f07a
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/schema/create-postgresql.sql
@@ -0,0 +1,14 @@
+CREATE TABLE AUTOINCPC1 (ID INTEGER NOT NULL, STRNGFLD VARCHAR(50), DTYPE VARCHAR(255), ONEONE_ID INTEGER, INTFIELD INTEGER, CONSTRAINT SQL150111133630290 PRIMARY KEY (ID));
+CREATE TABLE AUTOINCPC3 (ID BIGINT NOT NULL, STRNGFLD VARCHAR(50), ONEONE_ID BIGINT, CONSTRAINT SQL150111133630380 PRIMARY KEY (ID));
+CREATE TABLE CONJOINPC4 (ID INTEGER NOT NULL, MANYTOMANY BYTEA, NAME VARCHAR(50), ONETOONE1_ID INTEGER, CONSTRAINT SQL150111133630400 PRIMARY KEY (ID));
+CREATE TABLE CONJOINPC5 (ID INTEGER NOT NULL, NAME VARCHAR(255), CONSTRAINT SQL150111133630420 PRIMARY KEY (ID));
+CREATE TABLE CUSTMAPPC (ID INTEGER NOT NULL, FEMALE SMALLINT, NAME VARCHAR(50), CONSTRAINT SQL150111133630430 PRIMARY KEY (ID));
+CREATE TABLE DFGTEST (ID BIGINT NOT NULL, DFGFIELD INTEGER, NONDFGFIELD INTEGER, CONSTRAINT SQL150111133630450 PRIMARY KEY (ID));
+CREATE TABLE EAGEROUTERJOINPC (ID BIGINT NOT NULL, NAME VARCHAR(255), HELPER BYTEA, CONSTRAINT SQL150111133630460 PRIMARY KEY (ID));
+CREATE TABLE EAGERPC (ID INTEGER NOT NULL, STRNGFLD VARCHAR(50), EAGER_ID INTEGER, EAGSUB INTEGER, HELPER_ID INTEGER, RECURSE_ID INTEGER, CONSTRAINT SQL150111133630470 PRIMARY KEY (ID));
+CREATE TABLE EAGERPCSUB (ID INTEGER NOT NULL, INTFIELD INTEGER, CONSTRAINT SQL150111133630480 PRIMARY KEY (ID));
+CREATE TABLE HELPERPC (ID INTEGER NOT NULL, STRNGFLD VARCHAR(50), EAGER_ID INTEGER, HELPER BYTEA, CONSTRAINT SQL150111133630500 PRIMARY KEY (ID));
+CREATE TABLE HELPERPC2 (ID INTEGER NOT NULL, STRNGFLD VARCHAR(50), HELPER_ID INTEGER, CONSTRAINT SQL150111133630510 PRIMARY KEY (ID));
+CREATE TABLE HELPERPC3 (ID INTEGER NOT NULL, STRNGFLD VARCHAR(50), DTYPE VARCHAR(255), INTFIELD INTEGER, CONSTRAINT SQL150111133630520 PRIMARY KEY (ID));
+CREATE TABLE INVERTA (ID INTEGER NOT NULL, TEST VARCHAR(35), INVERTB_ID INTEGER, CONSTRAINT SQL150111133630530 PRIMARY KEY (ID));
+CREATE TABLE INVERTB (ID INTEGER NOT NULL, TEST VARCHAR(35), INVERTA_ID INTEGER, CONSTRAINT SQL150111133630540 PRIMARY KEY (ID));

Reply | Threaded
Open this post in threaded view
|

[openjpa] 02/02: OPENJPA-2756 escape search strings for all Postgres versions

struberg
In reply to this post by struberg
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

commit db6f6b642203d60ae1fa7576715e180c6bbe6081
Author: Mark Struberg <[hidden email]>
AuthorDate: Sat Nov 10 20:47:09 2018 +0100

    OPENJPA-2756 escape search strings for all Postgres versions
   
    Can be disabled via config by explicitly setting the
    DBDictionary to requiresSearchStringEscapeForLike=false
    via persistence.xml for example.
---
 .../main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java    | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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 82c3dce..2ba03e0 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
@@ -753,9 +753,12 @@ public class PostgresDictionary
         if ((maj >= 9 || (maj == 8 && min >= 3))) {
             supportsXMLColumn = true;
         }
+
+        // PostgreSQL requires to escape search strings
+        requiresSearchStringEscapeForLike = true;
+
         // Old PostgreSQL requires double-escape for strings.
         if ((maj <= 8 || (maj == 9 && min == 0))) {
-            requiresSearchStringEscapeForLike = true;
             searchStringEscape = "\\\\";
         }
     }