rzo1 commented on code in PR #269:
URL: https://github.com/apache/openjpa/pull/269#discussion_r4484077328
##########
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java:
##########
@@ -5481,39 +5481,70 @@ public StoredProcedure
getStoredProcedure(DatabaseMetaData meta, DBIdentifier ca
if (_procs.containsKey(procedure)) {
return _procs.get(procedure);
}
- StoredProcedure sp = findStoredProcedure(meta, catalog, schema,
procedure);
- // If not found and name has uppercase chars, try lowercase
- // (databases like PostgreSQL fold unquoted identifiers to lowercase)
- if (sp == null &&
!procedure.equals(procedure.toLowerCase(Locale.ROOT))) {
- sp = findStoredProcedure(meta, catalog, schema,
procedure.toLowerCase(Locale.ROOT));
+ StoredProcedure sp = null;
+ for (String name : getStoredProcedureNameCandidates(procedure)) {
+ sp = findStoredProcedure(meta, catalog, schema, name);
+ if (sp != null) {
+ break;
+ }
+ }
+ if (sp != null) {
+ _procs.put(procedure, sp);
}
- _procs.put(procedure, sp);
return sp;
}
+ /**
+ * The names to look up a stored procedure with in the database metadata,
in order of preference.
+ * Metadata lookups are case sensitive, but the procedure was most likely
created with an unquoted
+ * name, which the database folded according to its {@link #schemaCase}:
e.g. Derby and Oracle store
+ * unquoted names in upper case, PostgreSQL in lower case. Hence the given
name is tried as is first,
+ * then folded to upper case if this database folds to upper case, then in
lower case and finally
+ * in upper case.
+ */
+ protected List<String> getStoredProcedureNameCandidates(String procedure) {
+ Set<String> names = new LinkedHashSet<>();
+ names.add(procedure);
+ if (SCHEMA_CASE_UPPER.equals(getSchemaCase())) {
+ names.add(procedure.toUpperCase(Locale.ROOT));
+ }
+ names.add(procedure.toLowerCase(Locale.ROOT));
+ names.add(procedure.toUpperCase(Locale.ROOT));
+ return new ArrayList<>(names);
Review Comment:
Thanks, done.
--
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]