mirror of https://github.com/apache/openjpa.git
OPENJPA-1303 ColumnDefIdentifierRule did not use invalidColumnWordSet
This commit is contained in:
parent
80a16896f1
commit
6a47c4c033
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.jdbc.identifier;
|
package org.apache.openjpa.jdbc.identifier;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
|
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 class ColumnDefIdentifierRule extends DBIdentifierRule {
|
||||||
|
|
||||||
public ColumnDefIdentifierRule() {
|
public ColumnDefIdentifierRule(Set<String> reservedWords) {
|
||||||
super();
|
super(DBIdentifierType.COLUMN, reservedWords);
|
||||||
setName(DBIdentifierType.COLUMN_DEFINITION.toString());
|
|
||||||
// Disable auto delimiting of column definition.
|
// Disable auto delimiting of column definition.
|
||||||
setCanDelimit(false);
|
setCanDelimit(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,9 +516,21 @@ public class DBDictionary
|
||||||
"TINYINT",
|
"TINYINT",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// initialize the set of reserved SQL92 words from resource
|
||||||
|
reservedWordSet.addAll(loadFromResource("sql-keywords.rsrc"));
|
||||||
|
|
||||||
selectWordSet.add("SELECT");
|
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.
|
* This method is called when the dictionary first sees any connection.
|
||||||
* It is used to initialize dictionary metadata if needed. If you
|
* 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
|
// Disable delimiting of column definition. DB platforms are very
|
||||||
// picky about delimiters in column definitions. Base column types
|
// picky about delimiters in column definitions. Base column types
|
||||||
// do not require delimiters and will cause failures if delimited.
|
// do not require delimiters and will cause failures if delimited.
|
||||||
DBIdentifierRule cdRule = new ColumnDefIdentifierRule();
|
DBIdentifierRule cdRule = new ColumnDefIdentifierRule(invalidColumnWordSet);
|
||||||
cdRule.setCanDelimit(false);
|
cdRule.setCanDelimit(false);
|
||||||
namingRules.put(cdRule.getName(), cdRule);
|
namingRules.put(cdRule.getName(), cdRule);
|
||||||
}
|
}
|
||||||
|
@ -5026,17 +5038,6 @@ public class DBDictionary
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endConfiguration() {
|
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
|
// add additional reserved words set by user
|
||||||
if (reservedWords != null)
|
if (reservedWords != null)
|
||||||
reservedWordSet.addAll(Arrays.asList(StringUtil.split(reservedWords.toUpperCase(Locale.ENGLISH), ",", 0)));
|
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)));
|
selectWordSet.addAll(Arrays.asList(StringUtil.split(selectWords.toUpperCase(Locale.ENGLISH), ",", 0)));
|
||||||
|
|
||||||
if (invalidColumnWordSet.isEmpty()) {
|
if (invalidColumnWordSet.isEmpty()) {
|
||||||
invalidColumnWordSet.addAll(reservedWordSet);
|
invalidColumnWordSet.addAll(loadFromResource("sql-invalid-column-names.rsrc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize the error codes
|
// initialize the error codes
|
||||||
|
|
|
@ -81,11 +81,6 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary {
|
||||||
timeWithZoneTypeName = "TIME";
|
timeWithZoneTypeName = "TIME";
|
||||||
timestampWithZoneTypeName = "DATETIMEOFFSET";
|
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
|
indexPhysicalForeignKeys = true; // MS-SQLServer does not automatically create an index for a foreign key so we will
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -232,7 +232,7 @@ public class TestDynamicSchemas extends SingleEMFTestCase {
|
||||||
for (Column column : columns) {
|
for (Column column : columns) {
|
||||||
assertTrue(column.getName().length() > 0);
|
assertTrue(column.getName().length() > 0);
|
||||||
assertTrue(column.getName().length() <= dict.maxColumnNameLength);
|
assertTrue(column.getName().length() <= dict.maxColumnNameLength);
|
||||||
assertFalse(dict.getInvalidColumnWordSet().
|
assertFalse("Column" + column.getName(), dict.getInvalidColumnWordSet().
|
||||||
contains(column.getName().toUpperCase()));
|
contains(column.getName().toUpperCase()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue