HHH-9732 - Audit code for spots that would benefit from a case-insensitive keyed Map

This commit is contained in:
Steve Ebersole 2015-04-22 13:17:21 -05:00
parent 3c85127f82
commit 52589379e1
2 changed files with 12 additions and 26 deletions

View File

@ -28,7 +28,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.persistence.AttributeConverter;
import javax.persistence.SharedCacheMode;
@ -333,15 +332,9 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
@Override
public MetadataBuilder applySqlFunction(String functionName, SQLFunction function) {
if ( this.options.sqlFunctionMap == null ) {
// need to use this form as we want to specify the "concurrency level" as 1
// since only one thread will ever (should) be updating this
this.options.sqlFunctionMap = new HashMap<String, SQLFunction>();
}
// HHH-7721: SQLFunctionRegistry expects all lowercase. Enforce,
// just in case a user's customer dialect uses mixed cases.
this.options.sqlFunctionMap.put( functionName.toLowerCase(Locale.ROOT), function );
this.options.sqlFunctionMap.put( functionName, function );
return this;
}
@ -351,7 +344,6 @@ public class MetadataBuilderImpl implements MetadataBuilder, TypeContributions {
this.options.auxiliaryDatabaseObjectList = new ArrayList<AuxiliaryDatabaseObject>();
}
this.options.auxiliaryDatabaseObjectList.add( auxiliaryDatabaseObject );
return this;
}

View File

@ -23,9 +23,8 @@
*/
package org.hibernate.dialect.function;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import org.hibernate.dialect.Dialect;
@ -35,20 +34,20 @@ import org.hibernate.dialect.Dialect;
* @author Steve Ebersole
*/
public class SQLFunctionRegistry {
private final Dialect dialect;
private final Map<String, SQLFunction> userFunctions;
private final Map<String,SQLFunction> functionMap = new TreeMap<String, SQLFunction>(String.CASE_INSENSITIVE_ORDER);
/**
* Constructs a SQLFunctionRegistry
*
* @param dialect The dialect
* @param userFunctions Any application-supplied function definitions
* @param userFunctionMap Any application-supplied function definitions
*/
public SQLFunctionRegistry(Dialect dialect, Map<String, SQLFunction> userFunctions) {
this.dialect = dialect;
this.userFunctions = new HashMap<String, SQLFunction>();
if ( userFunctions != null ) {
this.userFunctions.putAll( userFunctions );
public SQLFunctionRegistry(Dialect dialect, Map<String, SQLFunction> userFunctionMap) {
// Apply the Dialect functions first
functionMap.putAll( dialect.getFunctions() );
// so that user supplied functions "override" them
if ( userFunctionMap != null ) {
functionMap.putAll( userFunctionMap );
}
}
@ -60,11 +59,7 @@ public class SQLFunctionRegistry {
* @return The located function, maye return {@code null}
*/
public SQLFunction findSQLFunction(String functionName) {
final String name = functionName.toLowerCase(Locale.ROOT);
final SQLFunction userFunction = userFunctions.get( name );
return userFunction != null
? userFunction
: dialect.getFunctions().get( name );
return functionMap.get( functionName );
}
/**
@ -76,8 +71,7 @@ public class SQLFunctionRegistry {
*/
@SuppressWarnings("UnusedDeclaration")
public boolean hasFunction(String functionName) {
final String name = functionName.toLowerCase(Locale.ROOT);
return userFunctions.containsKey( name ) || dialect.getFunctions().containsKey( name );
return functionMap.containsKey( functionName );
}
}