db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata FieldDescriptor.java
Date Wed, 13 Aug 2003 18:18:37 GMT
arminw      2003/08/13 11:18:37

  Modified:    src/java/org/apache/ojb/broker/metadata FieldDescriptor.java
  Log:
  use SqlTypeHelper to do sql/java type
  mapping
  
  Revision  Changes    Path
  1.30      +13 -109   db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
  
  Index: FieldDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- FieldDescriptor.java	10 Aug 2003 09:49:38 -0000	1.29
  +++ FieldDescriptor.java	13 Aug 2003 18:18:37 -0000	1.30
  @@ -62,11 +62,9 @@
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversionDefaultImpl;
   import org.apache.ojb.broker.util.ClassHelper;
  +import org.apache.ojb.broker.util.SqlTypeHelper;
   
   import java.io.Serializable;
  -import java.math.BigDecimal;
  -import java.sql.Timestamp;
  -import java.sql.Types;
   import java.util.Comparator;
   
   /**
  @@ -193,7 +191,7 @@
       {
           if (m_ColumnTypeId == -99999)
           {
  -            m_ColumnTypeId = getJdbcType();
  +            m_ColumnTypeId = getSqlType();
           }
           return m_ColumnTypeId;
       }
  @@ -202,117 +200,23 @@
       /**
        * determines the JDBC type (represented as an int value as specified
        * by java.sql.Types) of a FIELDDESCRIPTOR.
  -     * @param fld The FIELDDESCRIPTOR which JDBC type is to be determined.
  +     *
        * @return int the int value representing the Type according to
  -     * java.sql.Types
  +     * java.sql.Types.
        */
  -    private int getJdbcType()
  +    private int getSqlType()
       {
  -        int result;
  +        int result = Integer.MIN_VALUE;
           String columnType = this.getColumnType();
  +        // if sql type was not set in metadata we use reflection
  +        // to determine sql type by reflection
           if (columnType == null)
           {
  -            // if the user did not specify the type use reflection to determine the appropriate
JDBC type
  -            columnType = this.m_PersistentField.getType().getName();
  -//#ifdef JDBC30
  -            if (columnType.equals(Boolean.class.getName()) || columnType.equals("boolean"))
  -                result = Types.BOOLEAN;
  -            else 
  -//#endif            
  -            if (columnType.equals(Character.class.getName()) || columnType.equals("char"))
  -                result = Types.CHAR;
  -            else if (columnType.equals(Short.class.getName()) || columnType.equals("short"))
  -                result = Types.SMALLINT;
  -            else if (columnType.equals(Integer.class.getName()) || columnType.equals("int"))
  -                result = Types.INTEGER;
  -            else if (columnType.equals(Long.class.getName()) || columnType.equals("long"))
  -                result = Types.BIGINT;
  -            else if (columnType.equals(Byte.class.getName()) || columnType.equals("byte"))
  -                result = Types.CHAR;
  -            else if (columnType.equals(Float.class.getName()) || columnType.equals("float"))
  -                result = Types.FLOAT;
  -            else if (columnType.equals(Double.class.getName()) || columnType.equals("double"))
  -                result = Types.DOUBLE;
  -            else if (columnType.equals(String.class.getName()))
  -                result = Types.VARCHAR;
  -            else if (columnType.equals(java.util.Date.class.getName()))
  -                result = Types.DATE;
  -            else if (columnType.equals(java.sql.Time.class.getName()))
  -                result = Types.TIME;
  -            else if (columnType.equals(Timestamp.class.getName()))
  -                result = Types.TIMESTAMP;
  -            else if (columnType.equals(java.sql.Date.class.getName()))
  -                result = Types.DATE;
  -            else if (columnType.equals(BigDecimal.class.getName()))
  -                result = Types.DECIMAL;
  -            else
  -                throw new OJBRuntimeException(
  -                    "The type for attribute "
  -                        + getColumnName()
  -                        + " can not be handled by OJB automatically. Please specify a type
as defined by java.sql.Types.");
  -
  +            result = SqlTypeHelper.getSqlTypeByReflection(m_PersistentField.getType().getName());
           }
           else
           {
  -            String type = columnType.toLowerCase();
  -
  -            if (type.equals("bit"))
  -                result = Types.BIT;
  -            else if (type.equals("tinyint"))
  -                result = Types.TINYINT;
  -            else if (type.equals("smallint"))
  -                result = Types.SMALLINT;
  -            else if (type.equals("integer"))
  -                result = Types.INTEGER;
  -            else if (type.equals("bigint"))
  -                result = Types.BIGINT;
  -
  -            else if (type.equals("float"))
  -                result = Types.FLOAT;
  -            else if (type.equals("real"))
  -                result = Types.REAL;
  -            else if (type.equals("double"))
  -                result = Types.DOUBLE;
  -
  -            else if (type.equals("numeric"))
  -                result = Types.NUMERIC;
  -            else if (type.equals("decimal"))
  -                result = Types.DECIMAL;
  -
  -            else if (type.equals("char"))
  -                result = Types.CHAR;
  -            else if (type.equals("varchar"))
  -                result = Types.VARCHAR;
  -            else if (type.equals("longvarchar"))
  -                result = Types.LONGVARCHAR;
  -
  -            else if (type.equals("date"))
  -                result = Types.DATE;
  -            else if (type.equals("time"))
  -                result = Types.TIME;
  -            else if (type.equals("timestamp"))
  -                result = Types.TIMESTAMP;
  -
  -            else if (type.equals("binary"))
  -                result = Types.BINARY;
  -            else if (type.equals("varbinary"))
  -                result = Types.VARBINARY;
  -            else if (type.equals("longvarbinary"))
  -                result = Types.LONGVARBINARY;
  -
  -            else if (type.equals("clob"))
  -                result = Types.CLOB;
  -            else if (type.equals("blob"))
  -                result = Types.BLOB;
  -            else if (type.equals("struct"))
  -                result = Types.STRUCT;
  -            else
  -                throw new OJBRuntimeException(
  -                    "The type "
  -                        + getColumnType()
  -                        + " for attribute "
  -                        + getColumnName()
  -                        + " can not be handled by OJB. Please specify only types as defined
by java.sql.Types.");
  +            result = SqlTypeHelper.getSqlTypeByName(columnType);
           }
           return result;
       }
  @@ -342,7 +246,7 @@
           // if no conversion is specified use the default conversion
           if (fieldConversion == null)
           {
  -            setFieldConversion(new FieldConversionDefaultImpl());
  +            fieldConversion = new FieldConversionDefaultImpl();
           }
           return fieldConversion;
       }
  @@ -359,7 +263,7 @@
   
       /**
        * Sets the fieldConversion.
  -     * @param fieldConversion The fieldConversion to set
  +     * @param fieldConversionClassName The fieldConversion to set
        */
       public void setFieldConversionClassName(String fieldConversionClassName)
       {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message