org.exolab.castor.jdo.engine

Class SQLTypes


public final class SQLTypes
extends java.lang.Object

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

Nested Class Summary

(package private) static class
SQLTypes.TypeConvertorInfo
Information used to locate a type convertor.
(package private) static class
SQLTypes.TypeInfo

Field Summary

(package private) static SQLTypes.TypeConvertorInfo[]
_typeConvertors
List of all the default convertors between Java types.
(package private) static SQLTypes.TypeInfo[]
_typeInfos
List of all the SQL types supported by Castor JDO.

Method Summary

static TypeConvertor
getConvertor(Class fromType, Class toType)
Returns a type convertor.
static Object
getObject(ResultSet rs, int index, int sqlType)
static int
getSQLType(Class javaType)
Returns the SQL type from the specified Java type.
static String
javaToSqlName(String javaName)
Convert from Java name to SQL name.
static String
paramFromName(String sqlTypeName)
Extracts parameter for type convertor from the name of the SQL type of the form "SQL_type.domain".
static void
setObject(PreparedStatement stmt, int index, Object value, int sqlType)
static String
sqlToJavaName(String sqlName, boolean className, String scope)
Convert from SQL name to Java name.
static int
sqlTypeFromName(String sqlTypeName)
Returns the Java type from the SQL type name.
static Class
typeFromName(String sqlTypeName)
Returns the Java type from the SQL type name.
static Class
typeFromSQLType(int sqlType)
Returns the Java type from the SQL type.

Field Details

_typeConvertors

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

_typeInfos

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

Method Details

getConvertor

public static TypeConvertor getConvertor(Class fromType,
                                         Class toType)
            throws MappingException
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)
            throws SQLException

getSQLType

public static int getSQLType(Class javaType)
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)
                throws SQLException

    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)
                throws MappingException
    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)
                throws MappingException
    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)
                throws MappingException
    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