org.exolab.castor.jdo.engine

Class SQLTypes

public final class SQLTypes extends Object

Version: $Revision: 1.1.1.1 $ $Date: 2003/03/03 07:08:21 $

Author: Assaf Arkin

Nested Class Summary
static classSQLTypes.TypeConvertorInfo
Information used to locate a type convertor.
static classSQLTypes.TypeInfo
Field Summary
static SQLTypes.TypeConvertorInfo[]_typeConvertors
List of all the default convertors between Java types.
static SQLTypes.TypeInfo[]_typeInfos
List of all the SQL types supported by Castor JDO.
Method Summary
static TypeConvertorgetConvertor(Class fromType, Class toType)
Returns a type convertor.
static ObjectgetObject(ResultSet rs, int index, int sqlType)
static intgetSQLType(Class javaType)
Returns the SQL type from the specified Java type.
static StringjavaToSqlName(String javaName)
Convert from Java name to SQL name.
static StringparamFromName(String sqlTypeName)
Extracts parameter for type convertor from the name of the SQL type of the form "SQL_type.domain".
static voidsetObject(PreparedStatement stmt, int index, Object value, int sqlType)
static StringsqlToJavaName(String sqlName, boolean className, String scope)
Convert from SQL name to Java name.
static intsqlTypeFromName(String sqlTypeName)
Returns the Java type from the SQL type name.
static ClasstypeFromName(String sqlTypeName)
Returns the Java type from the SQL type name.
static ClasstypeFromSQLType(int sqlType)
Returns the Java type from the SQL type.

Field Detail

_typeConvertors

static SQLTypes.TypeConvertorInfo[] _typeConvertors
List of all the default convertors between Java types.

_typeInfos

static SQLTypes.TypeInfo[] _typeInfos
List of all the SQL types supported by Castor JDO.

Method Detail

getConvertor

public static TypeConvertor getConvertor(Class fromType, Class toType)
Returns a type convertor. A type convertor can be used to convert an object from Java type fromType to Java type toType.

Parameters: fromType The Java type to convert from toType The Java type to convert to

Throws: MappingException No suitable convertor was found

getObject

public static Object getObject(ResultSet rs, int index, int sqlType)

getSQLType

public static int getSQLType(Class javaType)
Returns the SQL type from the specified Java type. Returns OTHER if the Java type has no suitable SQL type mapping. The argument sqlType must be the return value from a previous call to {@link #typeFromSQLType} or {@link #typeFromName}.

Parameters: javaType The Java class of the SQL type

Returns: SQL type from the specified Java type

javaToSqlName

public static String javaToSqlName(String javaName)
Convert from Java name to SQL name. Performs trivial conversion by lowering case of all letters and adding underscore between words, a word is identifier as starting with an upper case. Only the last part of the Java name (following the last period) is used.

For example:

  • prodId becomes prod_id (field -> column)
  • jdbc.ProdGroup becomes prod_group (object -> table)
  • hobbies.getALife becomes get_a_life (compound field -> column)

    Parameters: javaName The Java identifier name

    Returns: An equivalent SQL identifier name

  • paramFromName

    public static String paramFromName(String sqlTypeName)
    Extracts parameter for type convertor from the name of the SQL type of the form "SQL_type.domain". If the type is not parameterized, returns null.

    Parameters: sqlTypeName SQL type name (e.g. char[01])

    Returns: Parameter (e.g. "01") or null

    setObject

    public static void setObject(PreparedStatement stmt, int index, Object value, int sqlType)

    sqlToJavaName

    public static String sqlToJavaName(String sqlName, boolean className, String scope)
    Convert from SQL name to Java name. Performs trivial conversion by treating each underscore as a word separator and converting the first letter of each word to upper case. If a scope is specified, the scope is prepended to the Java name separated by a period.

    For example:

  • prod_id, false becomes prodId (column -> field)
  • prod_group, true becomes ProdGroup (table -> object)
  • get_a_life, false, "product" becomes product.getALife (column -> field)

    Parameters: sqlName The SQL identifier name className True if class name (first letter must be upper case) scope Optional scope preceding name (package name, compound field)

    Returns: An equivalent Java identifier name

  • sqlTypeFromName

    public static int sqlTypeFromName(String sqlTypeName)
    Returns the Java type from the SQL type name.

    Parameters: sqlTypeName SQL type name (e.g. numeric)

    Returns: The suitable Java type

    Throws: MappingException The SQL type is not recognized.

    typeFromName

    public static Class typeFromName(String sqlTypeName)
    Returns the Java type from the SQL type name.

    Parameters: sqlTypeName SQL type name (e.g. numeric)

    Returns: The suitable Java type

    Throws: MappingException The SQL type is not recognized.

    typeFromSQLType

    public static Class typeFromSQLType(int sqlType)
    Returns the Java type from the SQL type.

    Parameters: sqlType SQL type name (see JDBC API)

    Returns: The suitable Java type

    Throws: MappingException The SQL type is not recognized.

    Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com