FileDocCategorySizeDatePackage
TypeNames.javaAPI DocHibernate 3.2.53647Wed Mar 30 12:01:42 BST 2005org.hibernate.dialect

TypeNames

public class TypeNames extends Object
This class maps a type to names. Associations may be marked with a capacity. Calling the get() method with a type and actual size n will return the associated name with smallest capacity >= n, if available and an unmarked default type otherwise. Eg, 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)"
author
Christoph Beck

Fields Summary
private HashMap
weighted
private HashMap
defaults
Constructors Summary
Methods Summary
public java.lang.Stringget(int typecode)
get default type name for specified type

param
typecode the type key
return
the default type name associated with specified key


	                     	 
	      
		String result = (String) defaults.get( new Integer(typecode) );
		if (result==null) throw new MappingException("No Dialect mapping for JDBC type: " + typecode);
		return result;
	
public java.lang.Stringget(int typecode, int size, int precision, int scale)
get type name for specified type and size

param
typecode the type key
param
size the SQL length
param
scale the SQL scale
param
precision the SQL precision
return
the associated name with smallest capacity >= size, if available and the default type name otherwise

		Map map = (Map) weighted.get( new Integer(typecode) );
		if ( map!=null && map.size()>0 ) {
			// iterate entries ordered by capacity to find first fit
			Iterator entries = map.entrySet().iterator();
			while ( entries.hasNext() ) {
				Map.Entry entry = (Map.Entry)entries.next();
				if ( size <= ( (Integer) entry.getKey() ).intValue() ) {
					return replace( (String) entry.getValue(), size, precision, scale );
				}
			}
		}
		return replace( get(typecode), size, precision, scale );
	
public voidput(int typecode, int capacity, java.lang.String value)
set a type name for specified type key and capacity

param
typecode the type key

		TreeMap map = (TreeMap)weighted.get( new Integer(typecode) );
		if (map == null) {// add new ordered map
			map = new TreeMap();
			weighted.put( new Integer(typecode), map );
		}
		map.put(new Integer(capacity), value);
	
public voidput(int typecode, java.lang.String value)
set a default type name for specified type key

param
typecode the type key

		defaults.put( new Integer(typecode), value );
	
private static java.lang.Stringreplace(java.lang.String type, int size, int precision, int scale)

		type = StringHelper.replaceOnce(type, "$s", Integer.toString(scale) );
		type = StringHelper.replaceOnce(type, "$l", Integer.toString(size) );
		return StringHelper.replaceOnce(type, "$p", Integer.toString(precision) );