db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r290415 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils/model: Column.java TypeMap.java
Date Tue, 20 Sep 2005 10:39:01 GMT
Author: tomdz
Date: Tue Sep 20 03:38:54 2005
New Revision: 290415

URL: http://svn.apache.org/viewcvs?rev=290415&view=rev
Log:
Added convenience methods to determine whether the type of a column is a numeric, text, binary
or special type

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java?rev=290415&r1=290414&r2=290415&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java Tue Sep 20 03:38:54 2005
@@ -212,6 +212,46 @@
         this.typeCode = TypeMap.getJdbcTypeCode(type);
     }
 
+    /**
+     * Determines whether this column is of a numeric type.
+     * 
+     * @return <code>true</code> if this column is of a numeric type
+     */
+    public boolean isOfNumericType()
+    {
+        return TypeMap.isNumericType(getTypeCode());
+    }
+
+    /**
+     * Determines whether this column is of a text type.
+     * 
+     * @return <code>true</code> if this column is of a text type
+     */
+    public boolean isOfTextType()
+    {
+        return TypeMap.isTextType(getTypeCode());
+    }
+
+    /**
+     * Determines whether this column is of a binary type.
+     * 
+     * @return <code>true</code> if this column is of a binary type
+     */
+    public boolean isOfBinaryType()
+    {
+        return TypeMap.isBinaryType(getTypeCode());
+    }
+
+    /**
+     * Determines whether this column is of a special type.
+     * 
+     * @return <code>true</code> if this column is of a special type
+     */
+    public boolean isOfSpecialType()
+    {
+        return TypeMap.isSpecialType(getTypeCode());
+    }
+    
     public String getSize()
     {
         return size;

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java?rev=290415&r1=290414&r2=290415&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java Tue Sep 20 03:38:54
2005
@@ -17,7 +17,8 @@
  */
 
 import java.sql.Types;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.HashSet;
 
 import org.apache.ddlutils.util.Jdbc3Utils;
 
@@ -63,47 +64,49 @@
     public static final String VARBINARY     = "VARBINARY";
     public static final String VARCHAR       = "VARCHAR";
 
-    private static Hashtable sqlTypeNameToTypeID = new Hashtable();
-    private static Hashtable typeIdToSqlTypeName = new Hashtable();
-
-
+    private static HashMap _sqlTypeNameToTypeID = new HashMap();
+    private static HashMap _typeIdToSqlTypeName = new HashMap();
+    private static HashSet _numericTypes        = new HashSet();
+    private static HashSet _textTypes           = new HashSet();
+    private static HashSet _binaryTypes         = new HashSet();
+    private static HashSet _specialTypes        = new HashSet();
 
     static
     {
-        registerSqlTypeID(Types.ARRAY,         ARRAY);
-        registerSqlTypeID(Types.BIGINT,        BIGINT);
-        registerSqlTypeID(Types.BINARY,        BINARY);
-        registerSqlTypeID(Types.BIT,           BIT);
-        registerSqlTypeID(Types.BLOB,          BLOB);
-        registerSqlTypeID(Types.CHAR,          CHAR);
-        registerSqlTypeID(Types.CLOB,          CLOB);
-        registerSqlTypeID(Types.DATE,          DATE);
-        registerSqlTypeID(Types.DECIMAL,       DECIMAL);
-        registerSqlTypeID(Types.DISTINCT,      DISTINCT);
-        registerSqlTypeID(Types.DOUBLE,        DOUBLE);
-        registerSqlTypeID(Types.FLOAT,         FLOAT);
-        registerSqlTypeID(Types.INTEGER,       INTEGER);
-        registerSqlTypeID(Types.JAVA_OBJECT,   JAVA_OBJECT);
-        registerSqlTypeID(Types.LONGVARBINARY, LONGVARBINARY);
-        registerSqlTypeID(Types.LONGVARCHAR,   LONGVARCHAR);
-        registerSqlTypeID(Types.NULL,          NULL);
-        registerSqlTypeID(Types.NUMERIC,       NUMERIC);
-        registerSqlTypeID(Types.OTHER,         OTHER);
-        registerSqlTypeID(Types.REAL,          REAL);
-        registerSqlTypeID(Types.REF,           REF);
-        registerSqlTypeID(Types.SMALLINT,      SMALLINT);
-        registerSqlTypeID(Types.STRUCT,        STRUCT);
-        registerSqlTypeID(Types.TIME,          TIME);
-        registerSqlTypeID(Types.TIMESTAMP,     TIMESTAMP);
-        registerSqlTypeID(Types.TINYINT,       TINYINT);
-        registerSqlTypeID(Types.VARBINARY,     VARBINARY);
-        registerSqlTypeID(Types.VARCHAR,       VARCHAR);
+        registerSqlTypeID(Types.ARRAY,         ARRAY,         false, false, false, true);
+        registerSqlTypeID(Types.BIGINT,        BIGINT,        true,  false, false, false);
+        registerSqlTypeID(Types.BINARY,        BINARY,        false, false, true,  false);
+        registerSqlTypeID(Types.BIT,           BIT,           true,  false, false, false);
+        registerSqlTypeID(Types.BLOB,          BLOB,          false, false, true,  false);
+        registerSqlTypeID(Types.CHAR,          CHAR,          false, true,  false, false);
+        registerSqlTypeID(Types.CLOB,          CLOB,          false, true,  false, false);
+        registerSqlTypeID(Types.DATE,          DATE,          false, false, false, false);
+        registerSqlTypeID(Types.DECIMAL,       DECIMAL,       true,  false, false, false);
+        registerSqlTypeID(Types.DISTINCT,      DISTINCT,      false, false, false, true);
+        registerSqlTypeID(Types.DOUBLE,        DOUBLE,        true,  false, false, false);
+        registerSqlTypeID(Types.FLOAT,         FLOAT,         true,  false, false, false);
+        registerSqlTypeID(Types.INTEGER,       INTEGER,       true,  false, false, false);
+        registerSqlTypeID(Types.JAVA_OBJECT,   JAVA_OBJECT,   false, false, false, true);
+        registerSqlTypeID(Types.LONGVARBINARY, LONGVARBINARY, false, false, true,  false);
+        registerSqlTypeID(Types.LONGVARCHAR,   LONGVARCHAR,   false, true,  false, false);
+        registerSqlTypeID(Types.NULL,          NULL,          false, false, false, true);
+        registerSqlTypeID(Types.NUMERIC,       NUMERIC,       true,  false, false, false);
+        registerSqlTypeID(Types.OTHER,         OTHER,         false, false, false, true);
+        registerSqlTypeID(Types.REAL,          REAL,          true,  false, false, false);
+        registerSqlTypeID(Types.REF,           REF,           false, false, false, true);
+        registerSqlTypeID(Types.SMALLINT,      SMALLINT,      true,  false, false, false);
+        registerSqlTypeID(Types.STRUCT,        STRUCT,        false, false, false, true);
+        registerSqlTypeID(Types.TIME,          TIME,          false, false, false, false);
+        registerSqlTypeID(Types.TIMESTAMP,     TIMESTAMP,     false, false, false, false);
+        registerSqlTypeID(Types.TINYINT,       TINYINT,       true,  false, false, false);
+        registerSqlTypeID(Types.VARBINARY,     VARBINARY,     false, false, true,  false);
+        registerSqlTypeID(Types.VARCHAR,       VARCHAR,       false, true,  false, false);
 
         // only available in JDK 1.4 and above:
         if (Jdbc3Utils.supportsJava14JdbcTypes())
         {
-            registerSqlTypeID(Jdbc3Utils.determineBooleanTypeCode(),  BOOLEAN);
-            registerSqlTypeID(Jdbc3Utils.determineDatalinkTypeCode(), DATALINK);
+            registerSqlTypeID(Jdbc3Utils.determineBooleanTypeCode(),  BOOLEAN,  true,  false,
false, false);
+            registerSqlTypeID(Jdbc3Utils.determineDatalinkTypeCode(), DATALINK, false, false,
false, true);
         }
     }
 
@@ -114,7 +117,7 @@
      */
     public static int getJdbcTypeCode(String typeName)
     {
-        Integer answer = (Integer)sqlTypeNameToTypeID.get(typeName.toUpperCase());
+        Integer answer = (Integer)_sqlTypeNameToTypeID.get(typeName.toUpperCase());
 
         return answer != null ? answer.intValue() : Types.OTHER;
     }
@@ -125,7 +128,7 @@
      */
     public static String getJdbcTypeName(int typeCode)
     {
-        String answer = (String)typeIdToSqlTypeName.get(new Integer(typeCode));
+        String answer = (String)_typeIdToSqlTypeName.get(new Integer(typeCode));
 
         return answer == null ? OTHER : answer;
     }
@@ -133,12 +136,76 @@
     /**
      * Registers the fact that the given Integer SQL ID maps to the given SQL name
      */
-    protected static void registerSqlTypeID(int sqlTypeID, String name) 
+    protected static void registerSqlTypeID(int sqlTypeID, String name, boolean isNumericType,
boolean isTextType, boolean isBinaryType, boolean isSpecialType) 
     {
         Integer typeId = new Integer(sqlTypeID);
 
-        sqlTypeNameToTypeID.put(name, typeId);
-        typeIdToSqlTypeName.put(typeId, name);
+        _sqlTypeNameToTypeID.put(name, typeId);
+        _typeIdToSqlTypeName.put(typeId, name);
+        if (isNumericType)
+        {
+            _numericTypes.add(typeId);
+        }
+        if (isTextType)
+        {
+            _textTypes.add(typeId);
+        }
+        if (isBinaryType)
+        {
+            _binaryTypes.add(typeId);
+        }
+        if (isSpecialType)
+        {
+            _specialTypes.add(typeId);
+        }
+    }
+
+    /**
+     * Determines whether the given sql type (one of the {@link java.sql.Types} constants)
+     * is a numeric type.
+     * 
+     * @param sqlTypeID The type code
+     * @return <code>true</code> if the type is a numeric one
+     */
+    public static boolean isNumericType(int sqlTypeID)
+    {
+        return _numericTypes.contains(new Integer(sqlTypeID));
+    }
+
+    /**
+     * Determines whether the given sql type (one of the {@link java.sql.Types} constants)
+     * is a text type.
+     * 
+     * @param sqlTypeID The type code
+     * @return <code>true</code> if the type is a text one
+     */
+    public static boolean isTextType(int sqlTypeID)
+    {
+        return _textTypes.contains(new Integer(sqlTypeID));
+    }
+
+    /**
+     * Determines whether the given sql type (one of the {@link java.sql.Types} constants)
+     * is a binary type.
+     * 
+     * @param sqlTypeID The type code
+     * @return <code>true</code> if the type is a binary one
+     */
+    public static boolean isBinaryType(int sqlTypeID)
+    {
+        return _binaryTypes.contains(new Integer(sqlTypeID));
+    }
+
+    /**
+     * Determines whether the given sql type (one of the {@link java.sql.Types} constants)
+     * is a special type.
+     * 
+     * @param sqlTypeID The type code
+     * @return <code>true</code> if the type is a special one
+     */
+    public static boolean isSpecialType(int sqlTypeID)
+    {
+        return _specialTypes.contains(new Integer(sqlTypeID));
     }
 }
 



Mime
View raw message