org.exolab.castor.jdo.engine
Class SQLTypes

java.lang.Object
  extended by org.exolab.castor.jdo.engine.SQLTypes

public final class SQLTypes
extends java.lang.Object

Version:
$Revision: 1.15 $ $Date: 2005/08/22 16:29:13 $
Author:
Assaf Arkin, Bruce Snyder

Nested Class Summary
static class SQLTypes.SQLTypeConvertor
           
(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.
 
Constructor Summary
SQLTypes()
           
 
Method Summary
static TypeConvertor getConvertor(java.lang.Class fromType, java.lang.Class toType)
          Returns a type convertor.
static java.lang.Object getObject(java.sql.ResultSet rs, int index, int sqlType)
           
static int getSQLType(java.lang.Class javaType)
          Returns the SQL type from the specified Java type.
static java.lang.String javaToSqlName(java.lang.String javaName)
          Convert from Java name to SQL name.
static java.lang.String paramFromName(java.lang.String sqlTypeName)
          Extracts parameter for type convertor from the name of the SQL type of the form "SQL_type.domain".
static void setObject(java.sql.PreparedStatement stmt, int index, java.lang.Object value, int sqlType)
           
static java.lang.String sqlToJavaName(java.lang.String sqlName, boolean className, java.lang.String scope)
          Convert from SQL name to Java name.
static int sqlTypeFromName(java.lang.String sqlTypeName)
          Returns the Java type from the SQL type name.
static java.lang.Class typeFromName(java.lang.String sqlTypeName)
          Returns the Java type from the SQL type name.
static java.lang.Class typeFromSQLType(int sqlType)
          Returns the Java type from the SQL type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_typeInfos

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


_typeConvertors

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

Constructor Detail

SQLTypes

public SQLTypes()
Method Detail

typeFromName

public static java.lang.Class typeFromName(java.lang.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.

sqlTypeFromName

public static int sqlTypeFromName(java.lang.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.

paramFromName

public static java.lang.String paramFromName(java.lang.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

typeFromSQLType

public static java.lang.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.

getSQLType

public static int getSQLType(java.lang.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 typeFromSQLType(int) or typeFromName(java.lang.String).

Parameters:
javaType - The Java class of the SQL type
Returns:
SQL type from the specified Java type

javaToSqlName

public static java.lang.String javaToSqlName(java.lang.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

  • sqlToJavaName

    public static java.lang.String sqlToJavaName(java.lang.String sqlName,
                                                 boolean className,
                                                 java.lang.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

  • getObject

    public static java.lang.Object getObject(java.sql.ResultSet rs,
                                             int index,
                                             int sqlType)
                                      throws java.sql.SQLException
    Throws:
    java.sql.SQLException

    setObject

    public static void setObject(java.sql.PreparedStatement stmt,
                                 int index,
                                 java.lang.Object value,
                                 int sqlType)
                          throws java.sql.SQLException
    Throws:
    java.sql.SQLException

    getConvertor

    public static TypeConvertor getConvertor(java.lang.Class fromType,
                                             java.lang.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


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