Class DataTypes

java.lang.Object
mgui.datasources.DataTypes

public class DataTypes
extends java.lang.Object
Class to provide functions for testing and comparing data types.
Author:
Andrew Reid
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int BINARY  
    static int BLOB  
    static int BOOLEAN  
    static int BYTE  
    static int CHAR  
    static int CLOB  
    static java.util.ArrayList<DataType> dataTypes  
    static int DATE  
    static int DECIMAL  
    static int DOUBLE  
    static int FLOAT  
    static int INTEGER  
    static int JAVA_OBJECT  
    static int LONG  
    static int LONGSTRING  
    static int RGB  
    static int RGBA  
    static int SHORT  
    static int SINGLE  
    static int STRING  
    static int TIMESTAMP  
    static int USHORT  
  • Constructor Summary

    Constructors
    Constructor Description
    DataTypes()  
  • Method Summary

    Modifier and Type Method Description
    static int getDataBufferType​(java.lang.String type)  
    static int getDataBufferType​(DataType type)  
    static java.lang.String getDataBufferTypeStr​(int type)  
    static java.util.ArrayList<DataType> getDataTypeList()
    Returns a sorted list of strings representing data types as specified in the setDataTypes method
    static DataType getFromDataBufferType​(int db_type)  
    static java.lang.Object getInstanceForValue​(java.lang.Object value, int data_type)
    Converts a value from a String to an instance of the specified type.
    static int getMappedSQLTypeDBMStoJDBC​(int dataType, java.lang.String driverStr)
    Return data type mapped to particular driver (for non-standard types) from DBMS type to JDBC type
    static int getMappedSQLTypeJDBCtoDBMS​(int dataType, java.lang.String driverStr)  
    static int getSize​(DataType type)
    Returns the number of bytes required to store a value of DataType type.
    static int getSizeForSQLType​(int type)
    Returns the number of bytes required to store a value of the SQL type type.
    static int getSizeForType​(int type)
    Returns the number of bytes required to store a value of DataType value type.
    static int getSQLStrValue​(java.lang.String typeStr)
    Returns the equivalent integer value (from Types for the given type string.
    static java.lang.Class getSQLTypeClass​(int dataType)
    Return the class of given data type
    static java.lang.String getSQLTypeLabel​(int SQLType)  
    static java.lang.Object getSQLTypeObject​(int dataType)  
    static java.lang.String getSQLTypeStr​(int SQLType)  
    static java.lang.String getSQLTypeStr​(int SQLType, int length)  
    static DataType getType​(int val)  
    static DataType getType​(java.lang.String type)  
    static DataType getTypeForSize​(int size)  
    static DataType getTypeForSQL​(int SQLType)
    Returns a DataType for the given SQL type (from Types).
    static DataType getTypeForSQLStr​(java.lang.String sqlType)  
    static int guessDataType​(java.lang.String token)
    Returns a best guess for the data type of the given string.
    static boolean isComparable​(int dataType)  
    static boolean isNumeric​(int sqlType)
    Determines whether a given SQL type is numeric
    static boolean isText​(int sqlType)
    Determines whether a given SQL type is text
    static boolean isText​(DataType dataType)
    Determines whether a given data type is text
    static boolean isType​(java.lang.Object obj, int type)  
    static void setSQLTypes​(java.util.HashMap<java.lang.Integer,​java.lang.String> map)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • DataTypes

      public DataTypes()
  • Method Details

    • setSQLTypes

      public static void setSQLTypes​(java.util.HashMap<java.lang.Integer,​java.lang.String> map)
    • getType

      public static DataType getType​(int val)
    • getType

      public static DataType getType​(java.lang.String type)
    • getTypeForSQLStr

      public static DataType getTypeForSQLStr​(java.lang.String sqlType)
    • getTypeForSQL

      public static DataType getTypeForSQL​(int SQLType)
      Returns a DataType for the given SQL type (from Types).
      Parameters:
      SQLType -
      Returns:
    • getSize

      public static int getSize​(DataType type)
      Returns the number of bytes required to store a value of DataType type.
      Parameters:
      type -
      Returns:
    • getSizeForType

      public static int getSizeForType​(int type)
      Returns the number of bytes required to store a value of DataType value type.
      Parameters:
      type -
      Returns:
    • getSizeForSQLType

      public static int getSizeForSQLType​(int type)
      Returns the number of bytes required to store a value of the SQL type type.
      Parameters:
      type -
      Returns:
    • getTypeForSize

      public static DataType getTypeForSize​(int size)
    • getSQLTypeObject

      public static java.lang.Object getSQLTypeObject​(int dataType)
    • getMappedSQLTypeDBMStoJDBC

      public static int getMappedSQLTypeDBMStoJDBC​(int dataType, java.lang.String driverStr)
      Return data type mapped to particular driver (for non-standard types) from DBMS type to JDBC type
      Parameters:
      dataType - DBMS type
      driverStr - The driver URL as a String
      Returns:
      dataType mapped to the JDBC type
    • getMappedSQLTypeJDBCtoDBMS

      public static int getMappedSQLTypeJDBCtoDBMS​(int dataType, java.lang.String driverStr)
    • getSQLTypeLabel

      public static java.lang.String getSQLTypeLabel​(int SQLType)
    • getSQLTypeStr

      public static java.lang.String getSQLTypeStr​(int SQLType)
    • getSQLTypeStr

      public static java.lang.String getSQLTypeStr​(int SQLType, int length)
    • getSQLStrValue

      public static int getSQLStrValue​(java.lang.String typeStr)
      Returns the equivalent integer value (from Types for the given type string.
      Parameters:
      typeStr -
      Returns:
    • isComparable

      public static boolean isComparable​(int dataType)
    • isType

      public static boolean isType​(java.lang.Object obj, int type)
    • getInstanceForValue

      public static java.lang.Object getInstanceForValue​(java.lang.Object value, int data_type) throws DataSourceException
      Converts a value from a String to an instance of the specified type.
      Parameters:
      value -
      data_type -
      Returns:
      Throws:
      DataSourceException - - If value cannot be converted to the specified type
    • guessDataType

      public static int guessDataType​(java.lang.String token)
      Returns a best guess for the data type of the given string.
      Parameters:
      token -
      Returns:
    • getSQLTypeClass

      public static java.lang.Class getSQLTypeClass​(int dataType)
      Return the class of given data type
      Parameters:
      dataType -
      Returns:
    • getDataBufferType

      public static int getDataBufferType​(DataType type)
    • getFromDataBufferType

      public static DataType getFromDataBufferType​(int db_type)
    • getDataBufferType

      public static int getDataBufferType​(java.lang.String type)
    • getDataBufferTypeStr

      public static java.lang.String getDataBufferTypeStr​(int type)
    • isNumeric

      public static boolean isNumeric​(int sqlType)
      Determines whether a given SQL type is numeric
      Parameters:
      sqlType -
      Returns:
    • isText

      public static boolean isText​(int sqlType)
      Determines whether a given SQL type is text
      Parameters:
      sqlType -
      Returns:
    • isText

      public static boolean isText​(DataType dataType)
      Determines whether a given data type is text
      Parameters:
      sqlType -
      Returns:
    • getDataTypeList

      public static java.util.ArrayList<DataType> getDataTypeList()
      Returns a sorted list of strings representing data types as specified in the setDataTypes method
      Returns:
      sorted ArrayList of strings