There is a possibility in the Configuration class to override table and column names. This is a great feature. However, it would be really nice, implement a renaming algorithm in a custom class.
Use-cases:
Atlassian Jira
For example in Atlassian Jira, some tables are created with no quotes and tables beginning with AO prefix are created with upper-case. The implementation would check this and
- if the table starts with AO, it would replace always the table and column names to be upper-case
- otherwise it would replace the table name to have the same case as it is specified by the database (e.g.: upper-case in Oracle, lower-case in postgres, ...)
Resolving table names from database metadata
We get all table and column names from the database connection. We expect that there are no two tables with the same name but different mixture of upper- and lower-case letters. When the name-mapping implementation is called, it always replaces the table and column names to the ones that exist in the database.
Conclusion
We use quoting in our products with upper-case letters only to make querydsl work in every database. E.g.:
- Oracle does not work with lower-case letters in special queries even if quoting is used
- Postgresql JDBC driver quotes table names always if insert-with-key is used. Therefore we must provide exactly the same name as it is used in the database.
We cannot use our naming strategy in case of 3rd products (like Jira, Liferay, Alfresco, ...) as some of them do not use quoting. However, name-mapping could be solved very easily with a primitive implementation of an interface in these situations.
If you agree, I would provide a patch that
- Extends the Configuration class with an addDynamicNameMapping(DynamicNameMapping) function. This function could be called several times and multiple name mapping could be added
- When a table name is searched, first the current nameMapping Map would be checked, and then the dynamicNameMapping objects would be called until a mapping is found