From 6861dd1d02751ae55ef64dd51f6808d044dc560d Mon Sep 17 00:00:00 2001 From: Mark Struberg Date: Fri, 2 Apr 2021 12:01:02 +0200 Subject: [PATCH] OPENJPA-1303 differentiate btw COLUMN and COLUMN_DEF rules Column names and Column definitions (the types, e.g. VARCHAR(20) ) have different rules. We now can properly specify both of em. --- .../identifier/ColumnDefIdentifierRule.java | 5 +-- .../jdbc/identifier/ColumnIdentifierRule.java | 35 +++++++++++++++++++ .../openjpa/jdbc/identifier/DBIdentifier.java | 6 ++++ .../apache/openjpa/jdbc/sql/DBDictionary.java | 9 +++-- 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnIdentifierRule.java 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 65916593a..1e9a9e158 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 @@ -32,8 +32,9 @@ import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; */ public class ColumnDefIdentifierRule extends DBIdentifierRule { - public ColumnDefIdentifierRule(Set reservedWords) { - super(DBIdentifierType.COLUMN, reservedWords); + public ColumnDefIdentifierRule() { + super(); + setName(DBIdentifierType.COLUMN_DEFINITION.toString()); // Disable auto delimiting of column definition. setCanDelimit(false); } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnIdentifierRule.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnIdentifierRule.java new file mode 100644 index 000000000..cae84d290 --- /dev/null +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/ColumnIdentifierRule.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.jdbc.identifier; + +import java.util.Set; + +import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; + +/** + * Default rule for column names. + * Column names which are forbidden as column names will get detected properly. + * Those reserved words might differ from the general reserved words. + */ +public class ColumnIdentifierRule extends DBIdentifierRule { + + public ColumnIdentifierRule(Set reservedWords) { + super(DBIdentifierType.COLUMN, reservedWords); + } +} diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifier.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifier.java index 255784aed..05fd32bf6 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifier.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/DBIdentifier.java @@ -42,7 +42,13 @@ public class DBIdentifier extends IdentifierImpl implements Cloneable, Identifie SCHEMA, CATALOG, DATABASE, + /** + * used for column names + */ COLUMN, + /** + * used for column type definition + */ COLUMN_DEFINITION, SEQUENCE, CONSTRAINT, 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 5d732307e..e4ae5bf60 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 @@ -72,6 +72,7 @@ import javax.sql.DataSource; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.identifier.ColumnDefIdentifierRule; +import org.apache.openjpa.jdbc.identifier.ColumnIdentifierRule; import org.apache.openjpa.jdbc.identifier.DBIdentifier; import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType; import org.apache.openjpa.jdbc.identifier.DBIdentifierRule; @@ -610,9 +611,11 @@ 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(invalidColumnWordSet); - cdRule.setCanDelimit(false); - namingRules.put(cdRule.getName(), cdRule); + DBIdentifierRule columnDefinitionNamingRule = new ColumnDefIdentifierRule(); + namingRules.put(columnDefinitionNamingRule.getName(), columnDefinitionNamingRule); + + DBIdentifierRule columnNamingRule = new ColumnIdentifierRule(invalidColumnWordSet); + namingRules.put(columnNamingRule.getName(), columnNamingRule); } //////////////////////