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
      The unrecognized/unmapped data type.
    • CHAR

      public static final DataType CHAR
      Maps the SQL CHAR type.
    • VARCHAR

      public static final DataType VARCHAR
      Maps the SQL VARCHAR type.
    • LONGVARCHAR

      public static final DataType LONGVARCHAR
      Maps the SQL LONGVARCHAR type.
    • CLOB

      public static final DataType CLOB
      Maps the SQL CLOB type.
    • NUMERIC

      public static final DataType NUMERIC
      Maps the SQL NUMERIC type.
    • DECIMAL

      public static final DataType DECIMAL
      Maps the SQL DECIMAL type.
    • BOOLEAN

      public static final DataType BOOLEAN
      Maps the SQL BOOLEAN type.
    • BIT

      public static final DataType BIT
      Maps the SQL BIT type.
    • TINYINT

      public static final DataType TINYINT
      Maps the SQL TINYINT type.
    • SMALLINT

      public static final DataType SMALLINT
      Maps the SQL SMALLINT type.
    • INTEGER

      public static final DataType INTEGER
      Maps the SQL INTEGER type.
    • BIGINT

      public static final DataType BIGINT
      Maps the SQL BIGINT type.
    • 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
      Maps the SQL REAL type.
    • FLOAT

      public static final DataType FLOAT
      Maps the SQL FLOAT type.
    • DOUBLE

      public static final DataType DOUBLE
      Maps the SQL DOUBLE type.
    • RELATIVE_DATE_TIME_PARSER

      public static final RelativeDateTimeParser RELATIVE_DATE_TIME_PARSER
      Parser used to calculate consistent relative date and time values.
    • DATE

      public static final DataType DATE
      Maps the SQL DATE type.
    • TIME

      public static final DataType TIME
      Maps the SQL TIME type.
    • TIMESTAMP

      public static final DataType TIMESTAMP
      Maps the SQL TIMESTAMP type.
    • BINARY

      public static final DataType BINARY
      Maps the SQL BINARY type.
    • VARBINARY

      public static final DataType VARBINARY
      Maps the SQL VARBINARY type.
    • LONGVARBINARY

      public static final DataType LONGVARBINARY
      Maps the SQL LONGVARBINARY type.
    • BLOB

      public static final DataType BLOB
      Maps the SQL BLOB type.
    • NCHAR

      public static final DataType NCHAR
      Maps the SQL NCHAR type.
    • NVARCHAR

      public static final DataType NVARCHAR
      Maps the SQL NVARCHAR type.
    • LONGNVARCHAR

      public static final DataType LONGNVARCHAR
      Maps the SQL LONGNVARCHAR type.
  • Constructor Details

    • DataType

      public DataType()
  • Method Details

    • typeCast

      public abstract Object typeCast(Object value) throws TypeCastException
      Returns the specified value typecasted to this DataType
      Parameters:
      value - the value to typecast.
      Returns:
      the typecast value.
      Throws:
      TypeCastException - if the value cannot be typecast to this DataType.
    • 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.

      Parameters:
      o1 - the first value to compare.
      o2 - the second value to compare.
      Returns:
      a negative integer, zero, or a positive integer as o1 is less than, equal to, or greater than o2.
      Throws:
      TypeCastException - if the arguments' types prevent them from being compared by this Comparator.
    • getSqlType

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

      public abstract Class getTypeClass()
      Returns the runtime class of the typecast result.
      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)
      Returns:
      the SQL type name for user types, or null for basic SQL types.
    • isNumber

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

      public abstract boolean isDateTime()
      Returns true if this DataType represents a date and/or time.
      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.
      Parameters:
      column - the column index to read, starting at 1.
      resultSet - the result set to read the column value from.
      Returns:
      the column value.
      Throws:
      SQLException - if a database access error occurs.
      TypeCastException - if the value cannot be typecast to this DataType.
    • setSqlValue

      public abstract void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException
      Set the specified value to the specified prepared statement object.
      Parameters:
      value - the value to bind.
      column - the parameter index to bind to, starting at 1.
      statement - the prepared statement to bind the value on.
      Throws:
      SQLException - if a database access error occurs.
      TypeCastException - if the value cannot be typecast to this DataType.
    • asString

      public static String asString(Object value) throws TypeCastException
      Typecast the specified value to string.
      Parameters:
      value - the value to typecast.
      Returns:
      the typecast value.
      Throws:
      TypeCastException - if the value cannot be typecast to a string.
    • forSqlType

      public static DataType forSqlType(int sqlType) throws DataTypeException
      Returns the DataType corresponding to the specified Sql type. See Types.
      Parameters:
      sqlType - the Types constant to look up.
      Returns:
      the corresponding DataType, or DataType.UNKNOWN if not recognized.
      Throws:
      DataTypeException - if the corresponding DataType cannot be determined.
    • 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.
      Parameters:
      sqlTypeName - the Sql type name to look up.
      Returns:
      the corresponding DataType, or DataType.UNKNOWN if not recognized.
      Throws:
      DataTypeException - if the corresponding DataType cannot be determined.
    • 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.
      Parameters:
      value - the value whose runtime class is to be mapped.
      Returns:
      the corresponding DataType, or DataType.UNKNOWN if 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.