net.sf.dewdrop.sql.dialect
Class TypeMap

java.lang.Object
  extended bynet.sf.dewdrop.sql.dialect.TypeMap

public class TypeMap
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)"
 

Since:
6 January 2005
Author:
Christoph Beck, Les Hazlewood

Constructor Summary
TypeMap()
           
 
Method Summary
 String get(SqlDataType type)
          Retrieve the default type string for the specified SqlDataType.
 String get(SqlDataType type, int size, int precision)
          get type name for specified type and size
 void put(SqlDataType type, int capacity, String value)
          set a type name for specified type key and capacity
 void put(SqlDataType type, String value)
          set a default type name for specified type key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeMap

public TypeMap()
Method Detail

get

public String get(SqlDataType type)
Retrieve the default type string for the specified SqlDataType.

Parameters:
type - the type key
Returns:
the default type string associated with the specified key, or null if there is no default Dialect type string for the specified key.

get

public String get(SqlDataType type,
                  int size,
                  int precision)
get type name for specified type and size

Parameters:
type - the type key
size - the (maximum) type size/length
Returns:
the associated name with smallest capacity >= size, if available and the default type string otherwise ( or null if there is no default type string ).

put

public void put(SqlDataType type,
                int capacity,
                String value)
set a type name for specified type key and capacity

Parameters:
type - the type key

put

public void put(SqlDataType type,
                String value)
set a default type name for specified type key

Parameters:
type - the type key