HHH-13494 LobTypeMappings should not use a Bounded ConcurrentHashmap
This commit is contained in:
parent
8727072cdc
commit
1ed8f7e626
|
@ -10,62 +10,74 @@ import java.sql.Types;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.internal.util.collections.BoundedConcurrentHashMap;
|
|
||||||
import org.hibernate.type.descriptor.JdbcTypeNameMapper;
|
import org.hibernate.type.descriptor.JdbcTypeNameMapper;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
* @author Sanne Grinovero
|
||||||
*/
|
*/
|
||||||
public class LobTypeMappings {
|
public class LobTypeMappings {
|
||||||
private static final Logger log = Logger.getLogger( LobTypeMappings.class );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton access
|
* Singleton access
|
||||||
*/
|
*/
|
||||||
public static final LobTypeMappings INSTANCE = new LobTypeMappings();
|
public static final LobTypeMappings INSTANCE = new LobTypeMappings();
|
||||||
|
|
||||||
private final Map<Integer,Integer> lobCodeByNonLobCode;
|
|
||||||
|
|
||||||
private LobTypeMappings() {
|
private LobTypeMappings() {
|
||||||
this.lobCodeByNonLobCode = new BoundedConcurrentHashMap<Integer, Integer>();
|
|
||||||
|
|
||||||
// BLOB mappings
|
|
||||||
this.lobCodeByNonLobCode.put( Types.BLOB, Types.BLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.BINARY, Types.BLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.VARBINARY, Types.BLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.LONGVARBINARY, Types.BLOB );
|
|
||||||
|
|
||||||
// CLOB mappings
|
|
||||||
this.lobCodeByNonLobCode.put( Types.CLOB, Types.CLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.CHAR, Types.CLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.VARCHAR, Types.CLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.LONGVARCHAR, Types.CLOB );
|
|
||||||
|
|
||||||
// NCLOB mappings
|
|
||||||
this.lobCodeByNonLobCode.put( Types.NCLOB, Types.NCLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.NCHAR, Types.NCLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.NVARCHAR, Types.NCLOB );
|
|
||||||
this.lobCodeByNonLobCode.put( Types.LONGNVARCHAR, Types.NCLOB );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCorrespondingLobCode(int jdbcTypeCode) {
|
public boolean hasCorrespondingLobCode(final int jdbcTypeCode) {
|
||||||
return lobCodeByNonLobCode.containsKey( jdbcTypeCode );
|
return
|
||||||
|
// BLOB mappings
|
||||||
|
jdbcTypeCode == Types.BLOB ||
|
||||||
|
jdbcTypeCode == Types.BINARY ||
|
||||||
|
jdbcTypeCode == Types.VARBINARY ||
|
||||||
|
jdbcTypeCode == Types.LONGVARBINARY ||
|
||||||
|
|
||||||
|
// CLOB mappings
|
||||||
|
jdbcTypeCode == Types.CLOB ||
|
||||||
|
jdbcTypeCode == Types.CHAR ||
|
||||||
|
jdbcTypeCode == Types.VARCHAR ||
|
||||||
|
jdbcTypeCode == Types.LONGVARCHAR ||
|
||||||
|
|
||||||
|
// NCLOB mappings
|
||||||
|
jdbcTypeCode == Types.NCLOB ||
|
||||||
|
jdbcTypeCode == Types.NCHAR ||
|
||||||
|
jdbcTypeCode == Types.NVARCHAR ||
|
||||||
|
jdbcTypeCode == Types.LONGNVARCHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCorrespondingLobCode(int jdbcTypeCode) {
|
public int getCorrespondingLobCode(final int jdbcTypeCode) {
|
||||||
Integer lobTypeCode = lobCodeByNonLobCode.get( jdbcTypeCode );
|
switch ( jdbcTypeCode ) {
|
||||||
if ( lobTypeCode == null ) {
|
|
||||||
throw new IllegalArgumentException(
|
// BLOB mappings
|
||||||
|
case Types.BLOB :
|
||||||
|
case Types.BINARY :
|
||||||
|
case Types.VARBINARY :
|
||||||
|
case Types.LONGVARBINARY : return Types.BLOB;
|
||||||
|
|
||||||
|
// CLOB mappings
|
||||||
|
case Types.CLOB :
|
||||||
|
case Types.CHAR :
|
||||||
|
case Types.VARCHAR :
|
||||||
|
case Types.LONGVARCHAR : return Types.CLOB;
|
||||||
|
|
||||||
|
// NCLOB mappings
|
||||||
|
case Types.NCLOB :
|
||||||
|
case Types.NCHAR :
|
||||||
|
case Types.NVARCHAR :
|
||||||
|
case Types.LONGNVARCHAR : return Types.NCLOB;
|
||||||
|
|
||||||
|
// Anything else:
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(
|
||||||
String.format(
|
String.format(
|
||||||
Locale.ROOT,
|
Locale.ROOT,
|
||||||
"JDBC type-code [%s (%s)] not known to have a corresponding LOB equivalent",
|
"JDBC type-code [%s (%s)] not known to have a corresponding LOB equivalent",
|
||||||
jdbcTypeCode,
|
jdbcTypeCode,
|
||||||
JdbcTypeNameMapper.getTypeName( jdbcTypeCode )
|
JdbcTypeNameMapper.getTypeName( jdbcTypeCode )
|
||||||
)
|
) );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return lobTypeCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue