OPENJPA-1303 ColumnDefIdentifierRule did not use invalidColumnWordSet

This commit is contained in:
Mark Struberg 2021-03-31 00:29:51 +02:00
parent 80a16896f1
commit 6a47c4c033
5 changed files with 20 additions and 22 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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()));
}
}