db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata JdbcTypesHelper.java
Date Wed, 14 Dec 2005 19:02:50 GMT
brj         2005/12/14 11:02:50

  Modified:    src/java/org/apache/ojb/broker/metadata JdbcTypesHelper.java
  Log:
  setJdbcType-Methods are public to allow users to add their own types
  
  Revision  Changes    Path
  1.4       +67 -60    db-ojb/src/java/org/apache/ojb/broker/metadata/JdbcTypesHelper.java
  
  Index: JdbcTypesHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/JdbcTypesHelper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JdbcTypesHelper.java	1 Oct 2005 13:48:49 -0000	1.3
  +++ JdbcTypesHelper.java	14 Dec 2005 19:02:50 -0000	1.4
  @@ -53,73 +53,58 @@
       private static Map jdbcObjectTypesFromType = new HashMap();
       private static Map jdbcObjectTypesFromName = new HashMap();
   
  -    /*
  -    Hold out all JdbcType in a static maps
  -    */
  +    /**
  +     * Hold out all JdbcType in a static maps
  +     */
       static
       {
  -        jdbcObjectTypesFromType.put(new Integer(Types.ARRAY), new T_Array());
  -        jdbcObjectTypesFromType.put(new Integer(Types.BIGINT), new T_BigInt());
  -        jdbcObjectTypesFromType.put(new Integer(Types.BINARY), new T_Binary());
  -        jdbcObjectTypesFromType.put(new Integer(Types.BIT), new T_Bit());
  -        jdbcObjectTypesFromType.put(new Integer(Types.BLOB), new T_Blob());
  -        jdbcObjectTypesFromType.put(new Integer(Types.CHAR), new T_Char());
  -        jdbcObjectTypesFromType.put(new Integer(Types.CLOB), new T_Clob());
  -        jdbcObjectTypesFromType.put(new Integer(Types.DATE), new T_Date());
  -        jdbcObjectTypesFromType.put(new Integer(Types.DECIMAL), new T_Decimal());
  -        jdbcObjectTypesFromType.put(new Integer(Types.DOUBLE), new T_Double());
  -        jdbcObjectTypesFromType.put(new Integer(Types.FLOAT), new T_Float());
  -        jdbcObjectTypesFromType.put(new Integer(Types.INTEGER), new T_Integer());
  -        jdbcObjectTypesFromType.put(new Integer(Types.LONGVARBINARY), new T_LongVarBinary());
  -        jdbcObjectTypesFromType.put(new Integer(Types.LONGVARCHAR), new T_LongVarChar());
  -        jdbcObjectTypesFromType.put(new Integer(Types.NUMERIC), new T_Numeric());
  -        jdbcObjectTypesFromType.put(new Integer(Types.REAL), new T_Real());
  -        jdbcObjectTypesFromType.put(new Integer(Types.REF), new T_Ref());
  -        jdbcObjectTypesFromType.put(new Integer(Types.SMALLINT), new T_SmallInt());
  -        jdbcObjectTypesFromType.put(new Integer(Types.STRUCT), new T_Struct());
  -        jdbcObjectTypesFromType.put(new Integer(Types.TIME), new T_Time());
  -        jdbcObjectTypesFromType.put(new Integer(Types.TIMESTAMP), new T_Timestamp());
  -        jdbcObjectTypesFromType.put(new Integer(Types.TINYINT), new T_TinyInt());
  -        jdbcObjectTypesFromType.put(new Integer(Types.VARBINARY), new T_VarBinary());
  -        jdbcObjectTypesFromType.put(new Integer(Types.VARCHAR), new T_Varchar());
  +        setJdbcType("array", Types.ARRAY, new T_Array());
  +        setJdbcType("bigint", Types.BIGINT, new T_BigInt());
  +        setJdbcType("binary", Types.BINARY, new T_Binary());
  +        setJdbcType("bit", Types.BIT, new T_Bit());
  +        setJdbcType("blob", Types.BLOB, new T_Blob());
  +        setJdbcType("char", Types.CHAR, new T_Char());
  +        setJdbcType("clob", Types.CLOB, new T_Clob());
  +        setJdbcType("date", Types.DATE, new T_Date());
  +        setJdbcType("decimal", Types.DECIMAL, new T_Decimal());
  +        setJdbcType("double", Types.DOUBLE, new T_Double());
  +        setJdbcType("float", Types.FLOAT, new T_Float());
  +        setJdbcType("integer", Types.INTEGER, new T_Integer());
  +        setJdbcType("longvarbinary", Types.LONGVARBINARY, new T_LongVarBinary());
  +        setJdbcType("longvarchar", Types.LONGVARCHAR, new T_LongVarChar());
  +        setJdbcType("numeric", Types.NUMERIC, new T_Numeric());
  +        setJdbcType("real", Types.REAL, new T_Real());
  +        setJdbcType("ref", Types.REF, new T_Ref());
  +        setJdbcType("smallint", Types.SMALLINT, new T_SmallInt());
  +        setJdbcType("struct", Types.STRUCT, new T_Struct());
  +        setJdbcType("time", Types.TIME, new T_Time());
  +        setJdbcType("timestamp", Types.TIMESTAMP, new T_Timestamp());
  +        setJdbcType("tinyint", Types.TINYINT, new T_TinyInt());
  +        setJdbcType("varbinary", Types.VARBINARY, new T_VarBinary());
  +        setJdbcType("varchar", Types.VARCHAR, new T_Varchar());
  +        
   //#ifdef JDBC30
  -        jdbcObjectTypesFromType.put(new Integer(Types.BOOLEAN), new T_Boolean());
  -        jdbcObjectTypesFromType.put(new Integer(Types.DATALINK), new T_Datalink());
  +        setJdbcType("boolean", Types.BOOLEAN, new T_Boolean());
  +        setJdbcType("datalink", Types.DATALINK, new T_Datalink());
   //#endif
  +       
  +    }
   
  -
  -        jdbcObjectTypesFromName.put("array", jdbcObjectTypesFromType.get(new Integer(Types.ARRAY)));
  -        jdbcObjectTypesFromName.put("bigint", jdbcObjectTypesFromType.get(new Integer(Types.BIGINT)));
  -        jdbcObjectTypesFromName.put("binary", jdbcObjectTypesFromType.get(new Integer(Types.BINARY)));
  -        jdbcObjectTypesFromName.put("bit", jdbcObjectTypesFromType.get(new Integer(Types.BIT)));
  -        jdbcObjectTypesFromName.put("blob", jdbcObjectTypesFromType.get(new Integer(Types.BLOB)));
  -        jdbcObjectTypesFromName.put("char", jdbcObjectTypesFromType.get(new Integer(Types.CHAR)));
  -        jdbcObjectTypesFromName.put("clob", jdbcObjectTypesFromType.get(new Integer(Types.CLOB)));
  -        jdbcObjectTypesFromName.put("date", jdbcObjectTypesFromType.get(new Integer(Types.DATE)));
  -        jdbcObjectTypesFromName.put("decimal", jdbcObjectTypesFromType.get(new Integer(Types.DECIMAL)));
  -        jdbcObjectTypesFromName.put("double", jdbcObjectTypesFromType.get(new Integer(Types.DOUBLE)));
  -        jdbcObjectTypesFromName.put("float", jdbcObjectTypesFromType.get(new Integer(Types.FLOAT)));
  -        jdbcObjectTypesFromName.put("integer", jdbcObjectTypesFromType.get(new Integer(Types.INTEGER)));
  -        jdbcObjectTypesFromName.put("longvarbinary", jdbcObjectTypesFromType.get(new Integer(Types.LONGVARBINARY)));
  -        jdbcObjectTypesFromName.put("longvarchar", jdbcObjectTypesFromType.get(new Integer(Types.LONGVARCHAR)));
  -        jdbcObjectTypesFromName.put("numeric", jdbcObjectTypesFromType.get(new Integer(Types.NUMERIC)));
  -        jdbcObjectTypesFromName.put("real", jdbcObjectTypesFromType.get(new Integer(Types.REAL)));
  -        jdbcObjectTypesFromName.put("ref", jdbcObjectTypesFromType.get(new Integer(Types.REF)));
  -        jdbcObjectTypesFromName.put("smallint", jdbcObjectTypesFromType.get(new Integer(Types.SMALLINT)));
  -        jdbcObjectTypesFromName.put("struct", jdbcObjectTypesFromType.get(new Integer(Types.STRUCT)));
  -        jdbcObjectTypesFromName.put("time", jdbcObjectTypesFromType.get(new Integer(Types.TIME)));
  -        jdbcObjectTypesFromName.put("timestamp", jdbcObjectTypesFromType.get(new Integer(Types.TIMESTAMP)));
  -        jdbcObjectTypesFromName.put("tinyint", jdbcObjectTypesFromType.get(new Integer(Types.TINYINT)));
  -        jdbcObjectTypesFromName.put("varbinary", jdbcObjectTypesFromType.get(new Integer(Types.VARBINARY)));
  -        jdbcObjectTypesFromName.put("varchar", jdbcObjectTypesFromType.get(new Integer(Types.VARCHAR)));
  -//#ifdef JDBC30
  -        jdbcObjectTypesFromName.put("boolean", jdbcObjectTypesFromType.get(new Integer(Types.BOOLEAN)));
  -        jdbcObjectTypesFromName.put("datalink", jdbcObjectTypesFromType.get(new Integer(Types.DATALINK)));
  -//#endif
  +    private JdbcTypesHelper()
  +    {
  +        // no constructor needed
       }
   
  -    public JdbcTypesHelper()
  +    /**
  +     * Set the {@link JdbcType} by name and index.
  +     * @param typeName Name of the type
  +     * @param typeIndex index of the type
  +     * @param type the type
  +     */
  +    public static void setJdbcType(String typeName, int typeIndex, JdbcType type)
       {
  +        setJdbcTypeByName(typeName, type);
  +        setJdbcTypeByTypesIndex(typeIndex, type);
       }
   
       /**
  @@ -131,6 +116,16 @@
       }
   
       /**
  +     * Set the {@link JdbcType} by index.
  +     * @param typeIndex index of the type
  +     * @param type the type
  +     */
  +    public static void setJdbcTypeByTypesIndex(int typeIndex, JdbcType type)
  +    {
  +        jdbcObjectTypesFromType.put(new Integer(typeIndex), type);
  +    }
  +
  +    /**
        * Lookup the {@link JdbcType} by name. If name was not found an exception
        * is thrown.
        */
  @@ -147,6 +142,16 @@
       }
   
       /**
  +     * Set the {@link JdbcType} by name.
  +     * @param typeName Name of the type
  +     * @param type the type
  +     */
  +    public static void setJdbcTypeByName(String typeName, JdbcType type)
  +    {
  +        jdbcObjectTypesFromName.put(typeName, type);
  +    }
  +
  +    /**
        * Try to automatically assign a jdbc type for the given
        * java type name. This method is used if e.g. in metadata a
        * column type was not set.
  @@ -156,6 +161,7 @@
       public static JdbcType getJdbcTypeByReflection(String fieldType)
       {
           JdbcType result;
  +        
           if (fieldType.equalsIgnoreCase(Character.class.getName()) || fieldType.equalsIgnoreCase("char"))
               result = getJdbcTypeByName("char");
           else if (fieldType.equalsIgnoreCase(Short.class.getName()) || fieldType.equalsIgnoreCase("short"))
  @@ -245,6 +251,7 @@
           }
           catch (Exception ignore)
           {
  +            // ignore it
           }
           return statusName;
       }
  
  
  

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