HHH-13495 Do not use BoundedConcurrentHashMap for NationalizedTypeMappings

This commit is contained in:
Sanne Grinovero 2019-07-10 19:07:49 +01:00 committed by gbadner
parent 3088a2cfd0
commit ab832caf0d
1 changed files with 8 additions and 22 deletions

View File

@ -9,10 +9,6 @@ package org.hibernate.type.descriptor.sql;
import java.sql.Types;
import java.util.Map;
import org.hibernate.internal.util.collections.BoundedConcurrentHashMap;
import org.jboss.logging.Logger;
/**
* Manages a mapping between nationalized and non-nationalized variants of JDBC types.
*
@ -22,33 +18,23 @@ import org.jboss.logging.Logger;
* @author Steve Ebersole
*/
public class NationalizedTypeMappings {
private static final Logger log = Logger.getLogger( NationalizedTypeMappings.class );
/**
* Singleton access
*/
public static final NationalizedTypeMappings INSTANCE = new NationalizedTypeMappings();
private final Map<Integer,Integer> nationalizedCodeByNonNationalized;
public NationalizedTypeMappings() {
this.nationalizedCodeByNonNationalized = new BoundedConcurrentHashMap<Integer, Integer>();
map( Types.CHAR, Types.NCHAR );
map( Types.CLOB, Types.NCLOB );
map( Types.LONGVARCHAR, Types.LONGNVARCHAR );
map( Types.VARCHAR, Types.NVARCHAR );
}
private void map(int nonNationalizedCode, int nationalizedCode) {
nationalizedCodeByNonNationalized.put( nonNationalizedCode, nationalizedCode );
private NationalizedTypeMappings() {
}
public int getCorrespondingNationalizedCode(int jdbcCode) {
Integer nationalizedCode = nationalizedCodeByNonNationalized.get( jdbcCode );
if ( nationalizedCode == null ) {
log.debug( "Unable to locate nationalized jdbc-code equivalent for given jdbc code : " + jdbcCode );
return jdbcCode;
switch ( jdbcCode ) {
case Types.CHAR: return Types.NCHAR;
case Types.CLOB: return Types.NCLOB;
case Types.LONGVARCHAR: return Types.LONGNVARCHAR;
case Types.VARCHAR: return Types.NVARCHAR;
default:
throw new IllegalArgumentException( "Unable to locate nationalized jdbc-code equivalent for given jdbc code : " + jdbcCode );
}
return nationalizedCode;
}
}