Class DataType

java.lang.Object
org.dbunit.dataset.datatype.DataType
Direct Known Subclasses:
AbstractDataType

public abstract class DataType extends Object
Data type that maps Types objects to their java counterparts. It also provides immutable constants for the most common data types.
Version:
$Revision$
Author:
Manuel Laflamme
See Also:
  • Field Details

    • UNKNOWN

      public static final DataType UNKNOWN
    • CHAR

      public static final DataType CHAR
    • VARCHAR

      public static final DataType VARCHAR
    • LONGVARCHAR

      public static final DataType LONGVARCHAR
    • CLOB

      public static final DataType CLOB
    • NUMERIC

      public static final DataType NUMERIC
    • DECIMAL

      public static final DataType DECIMAL
    • BOOLEAN

      public static final DataType BOOLEAN
    • BIT

      public static final DataType BIT
    • TINYINT

      public static final DataType TINYINT
    • SMALLINT

      public static final DataType SMALLINT
    • INTEGER

      public static final DataType INTEGER
    • BIGINT

      public static final DataType BIGINT
    • BIGINT_AUX_LONG

      public static final DataType BIGINT_AUX_LONG
      Auxiliary for the BIGINT type using a long. Is currently only needed for method forObject(Object).
    • REAL

      public static final DataType REAL
    • FLOAT

      public static final DataType FLOAT
    • DOUBLE

      public static final DataType DOUBLE
    • RELATIVE_DATE_TIME_PARSER

      public static final RelativeDateTimeParser RELATIVE_DATE_TIME_PARSER
    • DATE

      public static final DataType DATE
    • TIME

      public static final DataType TIME
    • TIMESTAMP

      public static final DataType TIMESTAMP
    • BINARY

      public static final DataType BINARY
    • VARBINARY

      public static final DataType VARBINARY
    • LONGVARBINARY

      public static final DataType LONGVARBINARY
    • BLOB

      public static final DataType BLOB
    • NCHAR

      public static final DataType NCHAR
    • NVARCHAR

      public static final DataType NVARCHAR
    • LONGNVARCHAR

      public static final DataType LONGNVARCHAR
  • Constructor Details

    • DataType

      public DataType()
  • Method Details

    • typeCast

      public abstract Object typeCast(Object value) throws TypeCastException
      Returns the specified value typecasted to this DataType
      Throws:
      TypeCastException
    • compare

      public abstract int compare(Object o1, Object o2) throws TypeCastException
      Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

      The two values are typecast to this DataType before being compared.

      Throws:
      TypeCastException - if the arguments' types prevent them from being compared by this Comparator.
    • getSqlType

      public abstract int getSqlType()
      Returns the corresponding Types.
    • getTypeClass

      public abstract Class getTypeClass()
      Returns the runtime class of the typecast result.
    • getSqlTypeName

      public String getSqlTypeName()
      Returns the SQL type name for user types (null for basic SQL types)
    • isNumber

      public abstract boolean isNumber()
      Returns true if this DataType represents a number.
    • isDateTime

      public abstract boolean isDateTime()
      Returns true if this DataType represents a date and/or time.
    • getSqlValue

      public abstract Object getSqlValue(int column, ResultSet resultSet) throws SQLException, TypeCastException
      Returns the specified column value from the specified resultset object.
      Throws:
      SQLException
      TypeCastException
    • setSqlValue

      public abstract void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException
      Set the specified value to the specified prepared statement object.
      Throws:
      SQLException
      TypeCastException
    • asString

      public static String asString(Object value) throws TypeCastException
      Typecast the specified value to string.
      Throws:
      TypeCastException
    • forSqlType

      public static DataType forSqlType(int sqlType) throws DataTypeException
      Returns the DataType corresponding to the specified Sql type. See Types.
      Throws:
      DataTypeException
    • forSqlTypeName

      public static DataType forSqlTypeName(String sqlTypeName) throws DataTypeException
      Deprecated.
      Should not be used anymore
      Returns the DataType corresponding to the specified Sql type name.
      Throws:
      DataTypeException
    • forObject

      public static DataType forObject(Object value)
      Returns the DataType corresponding to the specified value runtime class. This method returns DataType.UNKNOWN if the value is null or runtime class not recognized.
    • isExtendedSyntax

      protected static boolean isExtendedSyntax(String input)
      Performs a quick check to test if the specified string uses extended syntax.
      Parameters:
      input - a string to check.
      Returns:
      true if the input uses extended syntax; false otherwise.