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/util SqlHelper.java
Date Wed, 13 Aug 2003 19:57:36 GMT
arminw      2003/08/13 12:57:36

  Modified:    src/java/org/apache/ojb/broker/util SqlHelper.java
  Log:
  use SqlTypeHelper to resolve
  sql/jave type mapping
  
  Revision  Changes    Path
  1.15      +5 -458    db-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java
  
  Index: SqlHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/SqlHelper.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SqlHelper.java	25 May 2003 12:06:31 -0000	1.14
  +++ SqlHelper.java	13 Aug 2003 19:57:36 -0000	1.15
  @@ -1,12 +1,10 @@
   package org.apache.ojb.broker.util;
   
  -import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   
   import java.sql.ResultSet;
   import java.sql.SQLException;
  -import java.sql.Types;
   
   /* ====================================================================
    * The Apache Software License, Version 1.1
  @@ -166,304 +164,13 @@
        */
       public static Object getObjectFromColumn(ResultSet rs, FieldDescriptor fld) throws
SQLException
       {
  -        return getObjectFromColumn(rs, fld.getColumnJdbcType(), fld.getColumnName());
  -    }
  -
  -    public static Object getObjectFromColumn(ResultSet rs, int jdbcType, String columnId)
throws SQLException
  -    {
  -        Object result = null;
  -        /**
  -         * we use these to avoid building an object for a null result column
  -         */
  -        long longVal;
  -        int intVal;
  -        boolean boolVal;
  -        double doubleVal;
  -        float floatVal;
  -        short shortVal;
  -        byte byteVal;
  -
  -        switch (jdbcType)
  -        {
  -            case Types.BIT:
  -                {
  -                    boolVal = rs.getBoolean(columnId);
  -                    result = (rs.wasNull() ? null : new Boolean(boolVal));
  -                    break;
  -                }
  -            case Types.TINYINT:
  -                {
  -                    byteVal = rs.getByte(columnId);
  -                    result = (rs.wasNull() ? null : new Byte(byteVal));
  -                    break;
  -                }
  -            case Types.SMALLINT:
  -                {
  -                    shortVal = rs.getShort(columnId);
  -                    result = (rs.wasNull() ? null : new Short(shortVal));
  -                    break;
  -                }
  -            case Types.INTEGER:
  -                {
  -                    intVal = rs.getInt(columnId);
  -                    result = (rs.wasNull() ? null : new Integer(intVal));
  -                    break;
  -                }
  -            case Types.BIGINT:
  -                {
  -                    longVal = rs.getLong(columnId);
  -                    result = (rs.wasNull() ? null : new Long(longVal));
  -                    break;
  -                }
  -            case Types.DOUBLE:
  -            case Types.FLOAT:
  -                {
  -                    doubleVal = rs.getDouble(columnId);
  -                    result = (rs.wasNull() ? null : new Double(doubleVal));
  -                    break;
  -                }
  -            case Types.REAL:
  -                {
  -                    floatVal = rs.getFloat(columnId);
  -                    result = (rs.wasNull() ? null : new Float(floatVal));
  -                    break;
  -                }
  -            case Types.NUMERIC:
  -                {
  -                    result = rs.getBigDecimal(columnId);
  -                    break;
  -                }
  -            case Types.DECIMAL:
  -                {
  -                    result = rs.getBigDecimal(columnId);
  -                    break;
  -                }
  -
  -            case Types.CHAR:
  -                {
  -                    result = rs.getString(columnId);
  -                    break;
  -                }
  -            case Types.VARCHAR:
  -                {
  -                    result = rs.getString(columnId);
  -                    break;
  -                }
  -            case Types.LONGVARCHAR:
  -                {
  -                    result = rs.getString(columnId);
  -                    break;
  -                }
  -
  -            case Types.DATE:
  -                {
  -                    result = rs.getDate(columnId);
  -                    break;
  -                }
  -            case Types.TIME:
  -                {
  -                    result = rs.getTime(columnId);
  -                    break;
  -                }
  -            case Types.TIMESTAMP:
  -                {
  -                    result = rs.getTimestamp(columnId);
  -                    break;
  -                }
  -
  -            case Types.BINARY:
  -                {
  -                    result = rs.getBytes(columnId);
  -                    break;
  -                }
  -            case Types.VARBINARY:
  -                {
  -                    result = rs.getBytes(columnId);
  -                    break;
  -                }
  -            case Types.LONGVARBINARY:
  -                {
  -                    result = rs.getBytes(columnId);
  -                    break;
  -                }
  -            case Types.CLOB:
  -                {
  -                    java.sql.Clob aClob = rs.getClob(columnId);
  -                    result = (rs.wasNull() ? null : aClob.getSubString(1L, (int) aClob.length()));
  -                    break;
  -                }
  -            case Types.BLOB:
  -                {
  -                    java.sql.Blob aBlob = rs.getBlob(columnId);
  -                    result = (rs.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length()));
  -                    break;
  -                }
  -            case Types.STRUCT:
  -                {
  -                    java.sql.Struct aStruct = (java.sql.Struct) rs.getObject(columnId);
  -                    result = (rs.wasNull() ? null : aStruct);
  -                    break;
  -                }
  -
  -            default :
  -                {
  -                    throw new OJBRuntimeException(
  -                            "The type "
  -                            + jdbcType
  -                            + " for attribute "
  -                            + columnId
  -                            + " can not be handled by OJB. Please specify only types as
defined by java.sql.Types.");
  -                }
  -        }
  -        return result;
  +        // return getObjectFromColumn(rs, fld.getColumnJdbcType(), fld.getColumnName());
  +        return SqlTypeHelper.getObjectFromColumn(rs, fld.getColumnJdbcType(), fld.getColumnName());
       }
   
       public static Object getObjectFromColumn(ResultSet rs, int jdbcType, int columnId)
throws SQLException
       {
  -        Object result = null;
  -        /**
  -         * we use these to avoid building an object for a null result column
  -         */
  -        long longVal;
  -        int intVal;
  -        boolean boolVal;
  -        double doubleVal;
  -        float floatVal;
  -        short shortVal;
  -        byte byteVal;
  -
  -        switch (jdbcType)
  -        {
  -            case Types.BIT:
  -                {
  -                    boolVal = rs.getBoolean(columnId);
  -                    result = (rs.wasNull() ? null : new Boolean(boolVal));
  -                    break;
  -                }
  -            case Types.TINYINT:
  -                {
  -                    byteVal = rs.getByte(columnId);
  -                    result = (rs.wasNull() ? null : new Byte(byteVal));
  -                    break;
  -                }
  -            case Types.SMALLINT:
  -                {
  -                    shortVal = rs.getShort(columnId);
  -                    result = (rs.wasNull() ? null : new Short(shortVal));
  -                    break;
  -                }
  -            case Types.INTEGER:
  -                {
  -                    intVal = rs.getInt(columnId);
  -                    result = (rs.wasNull() ? null : new Integer(intVal));
  -                    break;
  -                }
  -            case Types.BIGINT:
  -                {
  -                    longVal = rs.getLong(columnId);
  -                    result = (rs.wasNull() ? null : new Long(longVal));
  -                    break;
  -                }
  -            case Types.DOUBLE:
  -            case Types.FLOAT:
  -                {
  -                    doubleVal = rs.getDouble(columnId);
  -                    result = (rs.wasNull() ? null : new Double(doubleVal));
  -                    break;
  -                }
  -            case Types.REAL:
  -                {
  -                    floatVal = rs.getFloat(columnId);
  -                    result = (rs.wasNull() ? null : new Float(floatVal));
  -                    break;
  -                }
  -            case Types.NUMERIC:
  -                {
  -                    result = rs.getBigDecimal(columnId);
  -                    break;
  -                }
  -            case Types.DECIMAL:
  -                {
  -                    result = rs.getBigDecimal(columnId);
  -                    break;
  -                }
  -
  -            case Types.CHAR:
  -                {
  -                    result = rs.getString(columnId);
  -                    break;
  -                }
  -            case Types.VARCHAR:
  -                {
  -                    result = rs.getString(columnId);
  -                    break;
  -                }
  -            case Types.LONGVARCHAR:
  -                {
  -                    result = rs.getString(columnId);
  -                    break;
  -                }
  -
  -            case Types.DATE:
  -                {
  -                    result = rs.getDate(columnId);
  -                    break;
  -                }
  -            case Types.TIME:
  -                {
  -                    result = rs.getTime(columnId);
  -                    break;
  -                }
  -            case Types.TIMESTAMP:
  -                {
  -                    result = rs.getTimestamp(columnId);
  -                    break;
  -                }
  -
  -            case Types.BINARY:
  -                {
  -                    result = rs.getBytes(columnId);
  -                    break;
  -                }
  -            case Types.VARBINARY:
  -                {
  -                    result = rs.getBytes(columnId);
  -                    break;
  -                }
  -            case Types.LONGVARBINARY:
  -                {
  -                    result = rs.getBytes(columnId);
  -                    break;
  -                }
  -            case Types.CLOB:
  -                {
  -                    java.sql.Clob aClob = rs.getClob(columnId);
  -                    result = (rs.wasNull() ? null : aClob.getSubString(1L, (int) aClob.length()));
  -                    break;
  -                }
  -            case Types.BLOB:
  -                {
  -                    java.sql.Blob aBlob = rs.getBlob(columnId);
  -                    result = (rs.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length()));
  -                    break;
  -                }
  -            case Types.STRUCT:
  -                {
  -                    java.sql.Struct aStruct = (java.sql.Struct) rs.getObject(columnId);
  -                    result = (rs.wasNull() ? null : aStruct);
  -                    break;
  -                }
  -            default :
  -                {
  -                    throw new OJBRuntimeException(
  -                            "The type "
  -                            + jdbcType
  -                            + " for attribute "
  -                            + columnId
  -                            + " can not be handled by OJB. Please specify only types as
defined by java.sql.Types.");
  -                }
  -        }
  -        return result;
  +        return SqlTypeHelper.getObjectFromColumn(rs, jdbcType, columnId);
       }
   
       /**
  @@ -530,167 +237,7 @@
        */
       public static int getSqlTypeByValue(Object value)
       {
  -        if (value instanceof Integer)
  -        {
  -            return Types.INTEGER;
  -        }
  -        else if (value instanceof java.math.BigDecimal)
  -        {
  -            return Types.NUMERIC;
  -        }
  -        else if (value instanceof String)
  -        {
  -            return Types.VARCHAR;
  -        }
  -        else if (value instanceof Byte)
  -        {
  -            return Types.TINYINT;
  -        }
  -        else if (value instanceof Short)
  -        {
  -            return Types.SMALLINT;
  -        }
  -        else if (value instanceof Long)
  -        {
  -            return Types.BIGINT;
  -        }
  -        else if (value instanceof Float)
  -        {
  -            return Types.REAL;
  -        }
  -        else if (value instanceof Double)
  -        {
  -            return Types.DOUBLE;
  -        }
  -        else if (value instanceof byte[])
  -        {
  -            return Types.VARBINARY;
  -        }
  -        else if (value instanceof java.sql.Date)
  -        {
  -            return Types.DATE;
  -        }
  -        else if (value instanceof java.sql.Time)
  -        {
  -            return Types.TIME;
  -        }
  -        else if (value instanceof java.sql.Timestamp)
  -        {
  -            return Types.TIMESTAMP;
  -        }
  -        else if (value instanceof Boolean)
  -        {
  -            return Types.BIT;
  -        }
  -        else if (value instanceof java.sql.Struct)
  -        {
  -            return Types.STRUCT;
  -        }
  -        else
  -        {
  -            return Types.OTHER;
  -        }
  +        return SqlTypeHelper.getSqlTypeByValue(value);
       }
   
  -
  -    public static Object getJdbcTypeAsString(int jdbcType)
  -    {
  -        switch (jdbcType)
  -        {
  -            case Types.BIT:
  -                {
  -                    return "Types.BIT";
  -                }
  -            case Types.TINYINT:
  -                {
  -                    return "Types.TINYINT";
  -                }
  -            case Types.SMALLINT:
  -                {
  -                    return "Types.SMALLINT";
  -                }
  -            case Types.INTEGER:
  -                {
  -                    return "Types.INTEGER";
  -                }
  -            case Types.BIGINT:
  -                {
  -                    return "Types.BIGINT";
  -                }
  -            case Types.DOUBLE:
  -                {
  -                    return "Types.DOUBLE";
  -                }
  -            case Types.FLOAT:
  -                {
  -                    return "Types.FLOAT";
  -                }
  -            case Types.REAL:
  -                {
  -                    return "Types.REAL";
  -                }
  -            case Types.NUMERIC:
  -                {
  -                    return "Types.NUMERIC";
  -                }
  -            case Types.DECIMAL:
  -                {
  -                    return "Types.DECIMAL";
  -                }
  -
  -            case Types.CHAR:
  -                {
  -                    return "Types.CHAR";
  -                }
  -            case Types.VARCHAR:
  -                {
  -                    return "Types.VARCHAR";
  -                }
  -            case Types.LONGVARCHAR:
  -                {
  -                    return "Types.LONGVARCHAR";
  -                }
  -
  -            case Types.DATE:
  -                {
  -                    return "Types.DATE";
  -                }
  -            case Types.TIME:
  -                {
  -                    return "Types.TIME";
  -                }
  -            case Types.TIMESTAMP:
  -                {
  -                    return "Types.TIMESTAMP";
  -                }
  -            case Types.BINARY:
  -                {
  -                    return "Types.BINARY";
  -                }
  -            case Types.VARBINARY:
  -                {
  -                    return "Types.VARBINARY";
  -                }
  -            case Types.LONGVARBINARY:
  -                {
  -                    return "Types.LONGVARBINARY";
  -                }
  -            case Types.CLOB:
  -                {
  -                    return "Types.CLOB";
  -                }
  -            case Types.BLOB:
  -                {
  -                    return "Types.BLOB";
  -                }
  -            case Types.STRUCT:
  -                {
  -                    return "Types.STRUCT";
  -                }
  -            default :
  -                {
  -                    return "UNKOWN Type";
  -                }
  -        }
  -    }
   }
  
  
  

---------------------------------------------------------------------
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