Package org.hibernate.dialect
Class TypeNames
- java.lang.Object
-
- org.hibernate.dialect.TypeNames
-
public final class TypeNames extends Object
This class maintains a mapping of JDBC type codes to SQL type names for a dialect of SQL. An association between a type code and a SQL type name may be registered with a capacity, that is, with the maximum size that the given SQL type can accommodate.When a type association is retrieved for a given type code and actual size n,
get()
will return the associated type name with the smallest capacity greater than or equal to n, if available, or an unmarked default type otherwise.For example, setting:
names.put( type, "TEXT" ); names.put( type, 255, "VARCHAR($l)" ); names.put( type, 65534, "LONGVARCHAR($l)" );
will give you back the following:names.get( type ) // --> "TEXT" (default) names.get( type, 100 ) // --> "VARCHAR(100)" (100 is in [0:255]) names.get( type, 1000 ) // --> "LONGVARCHAR(1000)" (1000 is in [256:65534]) names.get( type, 100000 ) // --> "TEXT" (default)
On the other hand, simply putting:names.put( type, "VARCHAR($l)" );
would result in:names.get( type ) // --> "VARCHAR($l)" (will cause trouble) names.get( type, 100 ) // --> "VARCHAR(100)" names.get( type, 10000 ) // --> "VARCHAR(10000)"
Registered type names may contain the placemarkers$l
,$p
, and$s
, which will be replaced by the length, precision, and size passed toget(int, Long, Integer, Integer)
.
-
-
Constructor Summary
Constructors Constructor Description TypeNames()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsTypeName(String typeName)
Check whether or not the provided typeName exists.String
get(int typeCode)
Get default type name for specifiedJDBC type code
.String
get(int typeCode, Long size, Integer precision, Integer scale)
Get the SQL type name for the specifiedJDBC type code
and size, filling in the placemarkers$l
,$p
, and$s
with the given length, precision, and scale.void
put(int typeCode, long capacity, String value)
Register a mapping from the given JDBC type code to the given SQL type name, with a specified maximum size.void
put(int typeCode, String value)
Register a mapping from the given JDBC type code to the given SQL type name, with no specified maximum size.
-
-
-
Method Detail
-
get
public String get(int typeCode)
Get default type name for specifiedJDBC type code
. Does not fill in any placemarkers.- Parameters:
typeCode
- the JDBC type code- Returns:
- the default type name associated with specified key, or null if there was no type name associated with the key
-
get
public String get(int typeCode, Long size, Integer precision, Integer scale)
Get the SQL type name for the specifiedJDBC type code
and size, filling in the placemarkers$l
,$p
, and$s
with the given length, precision, and scale.- Parameters:
typeCode
- the JDBC type codesize
- the SQL length, if anyprecision
- the SQL precision, if anyscale
- the SQL scale, if any- Returns:
- the associated name with smallest capacity >= size, if available and the default type name otherwise
-
put
public void put(int typeCode, long capacity, String value)
Register a mapping from the given JDBC type code to the given SQL type name, with a specified maximum size.- Parameters:
typeCode
- the JDBC type codecapacity
- The capacity for this weightingvalue
- The mapping (type name)
-
put
public void put(int typeCode, String value)
Register a mapping from the given JDBC type code to the given SQL type name, with no specified maximum size.- Parameters:
typeCode
- the JDBC type codevalue
- The mapping (type name)
-
containsTypeName
public boolean containsTypeName(String typeName)
Check whether or not the provided typeName exists.- Parameters:
typeName
- the type name.- Returns:
- true if the given string has been registered as a type.
-
-