/**
* Uppercase / Lowercase / Mixedcase identifiers are a big problem. Some databases support mixing case
* (like McKoi) others force identifier case to all uppercase or all lowercase. Some (like MySQL) can be
* configured to care or not care about case as well as depending on the platform the database is on. This
* method attempt to use the metadata from the driver to "fix" the case of the identifier to be acceptable
* for the specified session.
*
* @param session
* the session whose disposition on case we care about.
* @param identifier
* @return
*/
/**
* Uppercase / Lowercase / Mixedcase identifiers are a big problem. Some databases support mixing case
* (like McKoi) others force identifier case to all uppercase or all lowercase. Some (like MySQL) can be
* configured to care or not care about case as well as depending on the platform the database is on. This
* method attempt to use the metadata from the driver to "fix" the case of the identifier to be acceptable
* for the specified session.
*
* @param session
* the session whose disposition on case we care about.
* @param identifier
* @return
*/
public static String fixCase(ISession session, String identifier) {
if (identifier == null || identifier.equals("")) {
return identifier;
}
try {
DatabaseMetaData md = session.getSQLConnection().getConnection().getMetaData();
// Don't change the case of the identifier if database allows mixed
// case.
if (md.storesMixedCaseIdentifiers()) {
return identifier;
}
// Fix the case according to what the database tells us.
if (md.storesUpperCaseIdentifiers()) {
return identifier.toUpperCase();
}
else {
return identifier.toLowerCase();
}
}
catch (SQLException
e) {
if (log.isDebugEnabled()) {
log.debug("fixCase: unexpected exception: " + e.getMessage());
}
return identifier;
}
}
|