openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [openjpa] branch master updated: OPENJPA-1303 ColumnDefIdentifierRule did not use invalidColumnWordSet
Date Tue, 30 Mar 2021 22:30:46 GMT
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 6a47c4c  OPENJPA-1303 ColumnDefIdentifierRule did not use invalidColumnWordSet
6a47c4c is described below

commit 6a47c4c03328689d1133c1a46c1f5d20b56549b9
Author: Mark Struberg <struberg@apache.org>
AuthorDate: Wed Mar 31 00:29:51 2021 +0200

    OPENJPA-1303 ColumnDefIdentifierRule did not use invalidColumnWordSet
---
 .../jdbc/identifier/ColumnDefIdentifierRule.java   |  7 +++---
 .../org/apache/openjpa/jdbc/sql/DBDictionary.java  | 27 +++++++++++-----------
 .../openjpa/jdbc/sql/SQLServerDictionary.java      |  5 ----
 .../openjpa/jdbc/sql/sql-invalid-column-names.rsrc |  1 +
 .../dynamicschema/TestDynamicSchemas.java          |  2 +-
 5 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnDefIdentifierRule.java
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnDefIdentifierRule.java
index 63cae55..6591659 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnDefIdentifierRule.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnDefIdentifierRule.java
@@ -18,6 +18,8 @@
  */
 package org.apache.openjpa.jdbc.identifier;
 
+import java.util.Set;
+
 import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
 
 /**
@@ -30,9 +32,8 @@ import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
  */
 public class ColumnDefIdentifierRule extends DBIdentifierRule {
 
-    public ColumnDefIdentifierRule() {
-        super();
-        setName(DBIdentifierType.COLUMN_DEFINITION.toString());
+    public ColumnDefIdentifierRule(Set<String> reservedWords) {
+        super(DBIdentifierType.COLUMN, reservedWords);
         // Disable auto delimiting of column definition.
         setCanDelimit(false);
     }
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
index 3ae7357..5d73230 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
@@ -516,9 +516,21 @@ public class DBDictionary
             "TINYINT",
         }));
 
+        // initialize the set of reserved SQL92 words from resource
+        reservedWordSet.addAll(loadFromResource("sql-keywords.rsrc"));
+
         selectWordSet.add("SELECT");
     }
 
+    private Collection<String> loadFromResource(String resourcename) {
+        try (InputStream in = DBDictionary.class.getResourceAsStream(resourcename)) {
+            String keywords = new BufferedReader(new InputStreamReader(in)).readLine();
+            return Arrays.asList(StringUtil.split(keywords, ",", 0));
+        } catch (IOException ioe) {
+            throw new GeneralException(ioe);
+        }
+    }
+
     /**
      * This method is called when the dictionary first sees any connection.
      * It is used to initialize dictionary metadata if needed. If you
@@ -598,7 +610,7 @@ public class DBDictionary
         // Disable delimiting of column definition.  DB platforms are very
         // picky about delimiters in column definitions. Base column types
         // do not require delimiters and will cause failures if delimited.
-        DBIdentifierRule cdRule = new ColumnDefIdentifierRule();
+        DBIdentifierRule cdRule = new ColumnDefIdentifierRule(invalidColumnWordSet);
         cdRule.setCanDelimit(false);
         namingRules.put(cdRule.getName(), cdRule);
     }
@@ -5026,17 +5038,6 @@ public class DBDictionary
 
     @Override
     public void endConfiguration() {
-        // initialize the set of reserved SQL92 words from resource
-        InputStream in = DBDictionary.class.getResourceAsStream("sql-keywords.rsrc");
-        try {
-            String keywords = new BufferedReader(new InputStreamReader(in)).readLine();
-            reservedWordSet.addAll(Arrays.asList(StringUtil.split(keywords, ",", 0)));
-        } catch (IOException ioe) {
-            throw new GeneralException(ioe);
-        } finally {
-            try { in.close(); } catch (IOException e) {}
-        }
-
         // add additional reserved words set by user
         if (reservedWords != null)
             reservedWordSet.addAll(Arrays.asList(StringUtil.split(reservedWords.toUpperCase(Locale.ENGLISH),
",", 0)));
@@ -5061,7 +5062,7 @@ public class DBDictionary
             selectWordSet.addAll(Arrays.asList(StringUtil.split(selectWords.toUpperCase(Locale.ENGLISH),
",", 0)));
 
         if (invalidColumnWordSet.isEmpty()) {
-            invalidColumnWordSet.addAll(reservedWordSet);
+            invalidColumnWordSet.addAll(loadFromResource("sql-invalid-column-names.rsrc"));
         }
 
         // initialize the error codes
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
index 252748f..c50ccb1 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java
@@ -81,11 +81,6 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
         timeWithZoneTypeName = "TIME";
         timestampWithZoneTypeName = "DATETIMEOFFSET";
 
-        // MS SQL Server uses those types for BLOBs
-        blobTypeName = "VARBINARY(MAX)";
-        longVarbinaryTypeName = "VARBINARY(MAX)";
-
-
         indexPhysicalForeignKeys = true; // MS-SQLServer does not automatically create an
index for a foreign key so we will
     }
 
diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-invalid-column-names.rsrc
b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-invalid-column-names.rsrc
new file mode 100644
index 0000000..22adb57
--- /dev/null
+++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-invalid-column-names.rsrc
@@ -0,0 +1 @@
+ACCESS,ADD,ALL,ALTER,AND,ANY,AS,ASC,AUDIT,BETWEEN,BY,CHAR,CHECK,COLUMN,COMMENT,CREATE,DATE,DECIMAL,DEFAULT,DELETE,DESC,DISTINCT,DROP,ELSE,EXISTS,FLOAT,FOR,FROM,GROUP,HAVING,IDENTIFIED,IN,INCREMENT,INDEX,INSERT,INTEGER,INTO,LIKE,LOCK,LONG,MINUS,NOT,NULL,NUMBER,OR,ORDER,SELECT,SESSION,SET,SIZE,SMALLINT,TABLE,THEN,TO,UNION,UNIQUE,UPDATE,USER,VALUES,VARCHAR,VIEW,WHERE,WITH
\ No newline at end of file
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/dynamicschema/TestDynamicSchemas.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/dynamicschema/TestDynamicSchemas.java
index 3bb7100..e440a3b 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/dynamicschema/TestDynamicSchemas.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/dynamicschema/TestDynamicSchemas.java
@@ -232,7 +232,7 @@ public class TestDynamicSchemas extends SingleEMFTestCase {
         for (Column column : columns) {
             assertTrue(column.getName().length() > 0);
             assertTrue(column.getName().length() <= dict.maxColumnNameLength);
-            assertFalse(dict.getInvalidColumnWordSet().
+            assertFalse("Column" + column.getName(), dict.getInvalidColumnWordSet().
                 contains(column.getName().toUpperCase()));
         }
     }

Mime
View raw message