org.codehaus.modello.generator.database.type
Class Types
java.lang.Object
org.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.
Types() - Construct a new empty
Types
|
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(String name, long size) - Returns the closest auto-increment type mapping matching the requested
type name and size
|
List | getAutoIncrementMappings() - Returns all auto-increment mappings
|
List | getMappings() - Returns all mappings that the database supports
|
String | getSQLType(Column column) - Helper to return the SQL type for a column
|
Type | getType(String sqlName) - Returns a type, based on its name
|
protected TypeMapping | getTypeMapping(List mappings, long size) - Returns the closest type mapping for a requested size, from a list
of
Mapping s.
|
TypeMapping | getTypeMapping(String name, long size) - Returns the first type matching the requested type name and size
|
List | getTypes() - Returns all types
|
TypeMapping | promote(String fromName, String toName, long size) - Promote a type to another type
|
TypeMapping | promote(String name, long size) - Promote a type to that supported by the database provider.
|
protected TypeMapping | promote(String name, long size, String[] types) - Promote a type to that supported by the database provider.
|
protected TypeMapping | promote(String name, long size, String[] types, String defaultName) - Promote a type to that supported by the database provider.
|
Types
public Types()
Construct a new empty Types
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.
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.
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
getAutoIncrementMapping
public TypeMapping getAutoIncrementMapping(String name,
long size)
Returns the closest auto-increment type mapping matching the requested
type name and size
name
- the JDBC type namesize
- the requested size. A size <= 0 indicates that the type
has no size
- the closest matching mapping, or
null
if none
exists
getAutoIncrementMappings
public List getAutoIncrementMappings()
Returns all auto-increment mappings
getMappings
public List getMappings()
Returns all mappings that the database supports
getSQLType
public String getSQLType(Column column)
Helper to return the SQL type for a column
getType
public Type getType(String sqlName)
Returns a type, based on its name
sqlName
- the name of the type
- the type corresponding to
sqlName
, or
null
if no such type exists
getTypeMapping
protected TypeMapping getTypeMapping(List mappings,
long size)
Returns the closest type mapping for a requested size, from a list
of Mapping
s.
Note that the returned mapping may specify a size less than that
requested.
mappings
- a list of Mappings
size
- the requested size
getTypeMapping
public TypeMapping getTypeMapping(String name,
long size)
Returns the first type matching the requested type name and size
name
- the JDBC type namesize
- the requested size. A size of 0 indicates that the type
has no size
- the closest matching type, or
null
if none exists
getTypes
public List getTypes()
Returns all types
promote
public TypeMapping promote(String fromName,
String toName,
long size)
Promote a type to another type
fromName
- the JDBC type name to promotetoName
- the JDBC type name to promote tosize
- the requested size
- the promoted type mapping, or
null
if the
promotion is invalid, or isn't supported by the database provider
promote
public TypeMapping promote(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.
name
- the JDBC type namesize
- the requested size
- the promoted type mapping, or
null
if the type
can't be promoted
promote
protected TypeMapping promote(String name,
long size,
String[] types)
Promote a type to that supported by the database provider.
name
- the JDBC type namesize
- the requested sizetypes
- the set of JDBC types that name
may be
promoted to
- the promoted type mapping, or
null
if the type
can't be promoted
promote
protected TypeMapping promote(String name,
long size,
String[] types,
String defaultName)
Promote a type to that supported by the database provider.
name
- the JDBC type namesize
- the requested sizetypes
- the set of JDBC types that name
may be
promoted todefaultName
- the default type name to promote to. If non-null,
this is used in preference to those listed by types
- the promoted type mapping, or
null
if the type
can't be promoted