rzo1 commented on code in PR #304:
URL: https://github.com/apache/openjpa/pull/304#discussion_r4550724786
##########
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/identifier/Normalizer.java:
##########
@@ -71,6 +71,24 @@ public static String normalizeString(String name) {
return name;
}
+ /**
+ * Normalizes a single part name with the given rule rather than the
+ * default rule, such as the rule of a dictionary that delimits its
+ * reserved words.
+ * @param name
+ * @param rule
+ * @since 4.2.0
+ */
+ public static String normalizeString(String name, IdentifierRule rule) {
+ if (StringUtil.isEmpty(name)) {
+ return name;
+ }
+ if (!normalizer.isDelimited(rule, name)) {
Review Comment:
Yes, that split is the intended design:
- The static `Normalizer` now does only the database-independent part: it
delimits what has to be delimited syntactically, the same for every database.
Before this PR it was "default rule + whatever reserved words the last
configured MySQL/MariaDB dictionary had put into it", which is exactly the bug:
the dictionary configured last decided the names of every persistence unit in
the JVM.
- The reserved words of a database only matter where a name is generated for
that database or reaches it, and those paths now go through the dictionary
(`DBDictionary.normalize` / `toDBName` / `fromDBName`): default names in the
mapping defaults and `makeNameValid`, configured schemas
(`openjpa.jdbc.Schema`, the persistence-unit default schema) and given table
names, `XMLSchemaParser`, DDL/SQL, and names read back from the database
metadata. A `DBIdentifier` created statically before that is an intermediate
value; the dictionary normalizes it when it matters.
- To make sure nothing relied on the old shared state,
`TestNamesPerDictionary` records the generated names (tables, columns, join
tables/columns, sequences, indexes, constraints, delimited and mixed-case
names, configured schemas, metadata lookups) per dictionary. For 17 setups the
names of each dictionary alone are identical before and after this change, and
with several dictionaries configured one after another, interleaved or on
different threads at the same time, each gets the names it gets alone. Plus the
full suite on Derby, the dictionary/schema tests on MySQL, MariaDB and
PostgreSQL, and the TCK on Derby, PostgreSQL, MySQL and MariaDB.
So the static instance being "unequipped" is what makes it safe: it can no
longer carry one database's words into another persistence unit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]