org.codehaus.modello.generator.database.type
Class Types

java.lang.Object
  extended byorg.codehaus.modello.generator.database.type.Types

public class Types
extends java.lang.Object

Manages the set of types supported by a database provider, and the mappings from standard JDBC types to the provider types.

Version:
1.1 2003/02/05 08:08:37
Author:
Tim Anderson

Field Summary
private  java.util.List autoIncList
          A list of all auto-increment mappings, in the order they were registered
private  java.util.HashMap autoIncMappings
          A map of JDBC type names to a List of corresponding database types, which may be used as auto-increment types.
private  java.util.List mappingList
          A list of all mappings, in the order they were registered
private  java.util.HashMap mappings
          A map of JDBC type names to a List of corresponding database types.
private  java.util.LinkedHashMap types
           
 
Constructor Summary
Types()
          Construct a new empty Types
 
Method Summary
 void addAutoIncrementMapping(Mapping mapping)
          Add an auto-increment mapping.
 void addMapping(Mapping mapping)
          Add a mapping.
 void addType(Type type)
          Add a type.
 TypeMapping getAutoIncrementMapping(java.lang.String name, long size)
          Returns the closest auto-increment type mapping matching the requested type name and size
 java.util.List getAutoIncrementMappings()
          Returns all auto-increment mappings
 java.util.List getMappings()
          Returns all mappings that the database supports
 java.lang.String getSQLType(Column column)
          Helper to return the SQL type for a column
 Type getType(java.lang.String sqlName)
          Returns a type, based on its name
protected  TypeMapping getTypeMapping(java.util.List mappings, long size)
          Returns the closest type mapping for a requested size, from a list of Mappings.
 TypeMapping getTypeMapping(java.lang.String name, long size)
          Returns the first type matching the requested type name and size
 java.util.List getTypes()
          Returns all types
 TypeMapping promote(java.lang.String name, long size)
          Promote a type to that supported by the database provider.
protected  TypeMapping promote(java.lang.String name, long size, java.lang.String[] types)
          Promote a type to that supported by the database provider.
protected  TypeMapping promote(java.lang.String name, long size, java.lang.String[] types, java.lang.String defaultName)
          Promote a type to that supported by the database provider.
 TypeMapping promote(java.lang.String fromName, java.lang.String toName, long size)
          Promote a type to another type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

types

private java.util.LinkedHashMap types

mappingList

private java.util.List mappingList
A list of all mappings, in the order they were registered


mappings

private java.util.HashMap mappings
A map of JDBC type names to a List of corresponding database types. A list is required as some vendors alias their types


autoIncList

private java.util.List autoIncList
A list of all auto-increment mappings, in the order they were registered


autoIncMappings

private java.util.HashMap autoIncMappings
A map of JDBC type names to a List of corresponding database types, which may be used as auto-increment types. A list is required as some vendors alias their types

Constructor Detail

Types

public Types()
Construct a new empty Types

Method Detail

getTypes

public java.util.List getTypes()
Returns all types


getType

public Type getType(java.lang.String sqlName)
Returns a type, based on its name

Parameters:
sqlName - the name of the type
Returns:
the type corresponding to sqlName, or null if no such type exists

addType

public void addType(Type type)
Add a type. Types are uniquely identified by their Type.getSQLName() - if a type already exists with the same name, it will be replaced


getMappings

public java.util.List getMappings()
Returns all mappings that the database supports


addMapping

public void addMapping(Mapping mapping)
Add a mapping. Mappings are identified by their Mapping.getName(). Multiple mappings can be added with the same name.

Throws:
java.lang.IllegalArgumentException - if no there is no corresponding Type registered for Mapping.getSQLName()

getAutoIncrementMappings

public java.util.List getAutoIncrementMappings()
Returns all auto-increment mappings


addAutoIncrementMapping

public void addAutoIncrementMapping(Mapping mapping)
Add an auto-increment mapping. Mappings are identified by their Mapping.getName(). Multiple mappings can be added with the same name.

Throws:
java.lang.IllegalArgumentException - if no there is no corresponding Type registered for Mapping.getSQLName()

getTypeMapping

public TypeMapping getTypeMapping(java.lang.String name,
                                  long size)
Returns the first type matching the requested type name and size

Parameters:
name - the JDBC type name
size - the requested size. A size of 0 indicates that the type has no size
Returns:
the closest matching type, or null if none exists

getAutoIncrementMapping

public TypeMapping getAutoIncrementMapping(java.lang.String name,
                                           long size)
Returns the closest auto-increment type mapping matching the requested type name and size

Parameters:
name - the JDBC type name
size - the requested size. A size <= 0 indicates that the type has no size
Returns:
the closest matching mapping, or null if none exists

promote

public TypeMapping promote(java.lang.String name,
                           long size)
Promote a type to that supported by the database provider. Note that this only promotes types when the type semantics remain unchanged - it will not promote a CHAR to a VARCHAR for example as some providers do not support indexes on VARCHAR columns. If this is the desired behaviour, add a mapping.

Parameters:
name - the JDBC type name
size - the requested size
Returns:
the promoted type mapping, or null if the type can't be promoted

promote

public TypeMapping promote(java.lang.String fromName,
                           java.lang.String toName,
                           long size)
Promote a type to another type

Parameters:
fromName - the JDBC type name to promote
toName - the JDBC type name to promote to
size - the requested size
Returns:
the promoted type mapping, or null if the promotion is invalid, or isn't supported by the database provider

getSQLType

public java.lang.String getSQLType(Column column)
Helper to return the SQL type for a column

Parameters:
column - the column
Returns:
the SQL type of column

getTypeMapping

protected TypeMapping getTypeMapping(java.util.List mappings,
                                     long size)
Returns the closest type mapping for a requested size, from a list of Mappings. Note that the returned mapping may specify a size less than that requested.

Parameters:
mappings - a list of Mappings
size - the requested size
Returns:
the closest type mapping

promote

protected TypeMapping promote(java.lang.String name,
                              long size,
                              java.lang.String[] types)
Promote a type to that supported by the database provider.

Parameters:
name - the JDBC type name
size - the requested size
types - the set of JDBC types that name may be promoted to
Returns:
the promoted type mapping, or null if the type can't be promoted

promote

protected TypeMapping promote(java.lang.String name,
                              long size,
                              java.lang.String[] types,
                              java.lang.String defaultName)
Promote a type to that supported by the database provider.

Parameters:
name - the JDBC type name
size - the requested size
types - the set of JDBC types that name may be promoted to
defaultName - the default type name to promote to. If non-null, this is used in preference to those listed by types
Returns:
the promoted type mapping, or null if the type can't be promoted