Class AbstractDataType

java.lang.Object
org.dbunit.dataset.datatype.DataType
org.dbunit.dataset.datatype.AbstractDataType
Direct Known Subclasses:
ArrayType, BigIntegerDataType, BooleanDataType, BytesDataType, CitextType, DateDataType, DateTimeOffsetType, DoubleDataType, FloatDataType, GenericEnumType, GeometryType, InetType, IntegerDataType, IntervalType, JsonType, LongDataType, NumberDataType, OracleSdoGeometryDataType, StringDataType, TimeDataType, TimestampDataType, UniqueIdentifierType, UnknownDataType, UuidType

public abstract class AbstractDataType extends DataType
Abstract data type implementation that provides generic methods that are appropriate for most data type implementations. Among those is the generic implementation of the compare(Object, Object) method.
Since:
Mar 19, 2002
Version:
$Revision$ $Date$
Author:
Manuel Laflamme, Last changed by: $Author$
  • Constructor Details

    • AbstractDataType

      public AbstractDataType(String name, int sqlType, Class classType, boolean isNumber)
      Constructs a data type with the given SQL type mapping.
      Parameters:
      name - the data type name.
      sqlType - the Types constant this data type maps to.
      classType - the Java class representing this data type's values.
      isNumber - true if this data type represents a number.
  • Method Details

    • compare

      public int compare(Object o1, Object o2) throws TypeCastException
      Description copied from class: DataType
      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.

      Specified by:
      compare in class DataType
      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.
    • compareNonNulls

      protected int compareNonNulls(Object value1, Object value2) throws TypeCastException
      Compares non-null values to each other. Both objects are guaranteed to be not null and to implement the interface Comparable. The two given objects are the results of the DataType.typeCast(Object) method call which is usually implemented by a specialized DataType implementation.
      Parameters:
      value1 - First value resulting from the DataType.typeCast(Object) method call
      value2 - Second value resulting from the DataType.typeCast(Object) method call
      Returns:
      The result of the Comparable.compareTo(Object) invocation.
      Throws:
      TypeCastException - if either value cannot be cast to a Comparable.
    • areObjectsEqual

      protected final boolean areObjectsEqual(Object o1, Object o2)
      Checks whether the given objects are equal or not.
      Parameters:
      o1 - first object
      o2 - second object
      Returns:
      true if both objects are null (and hence equal) or if the o1.equals(o2) is true.
    • getSqlType

      public int getSqlType()
      Description copied from class: DataType
      Returns the corresponding Types.
      Specified by:
      getSqlType in class DataType
      Returns:
      the corresponding Types constant.
    • getTypeClass

      public Class getTypeClass()
      Description copied from class: DataType
      Returns the runtime class of the typecast result.
      Specified by:
      getTypeClass in class DataType
      Returns:
      the runtime class of the typecast result.
    • isNumber

      public boolean isNumber()
      Description copied from class: DataType
      Returns true if this DataType represents a number.
      Specified by:
      isNumber in class DataType
      Returns:
      true if this DataType represents a number.
    • isDateTime

      public boolean isDateTime()
      Description copied from class: DataType
      Returns true if this DataType represents a date and/or time.
      Specified by:
      isDateTime in class DataType
      Returns:
      true if this DataType represents a date and/or time.
    • getSqlValue

      public Object getSqlValue(int column, ResultSet resultSet) throws SQLException, TypeCastException
      Description copied from class: DataType
      Returns the specified column value from the specified resultset object.
      Specified by:
      getSqlValue in class DataType
      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 void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException
      Description copied from class: DataType
      Set the specified value to the specified prepared statement object.
      Specified by:
      setSqlValue in class DataType
      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.
    • loadClass

      protected final Class loadClass(String clazz, Connection connection) throws ClassNotFoundException
      Loads the given class using the class loader of the given connection.
      Parameters:
      clazz - The fully qualified name of the class to be loaded
      connection - The JDBC connection needed to load the given class
      Returns:
      The loaded class
      Throws:
      ClassNotFoundException - if the class cannot be located by the class loader.
    • loadClass

      protected final Class loadClass(String clazz, ClassLoader classLoader) throws ClassNotFoundException
      Loads the given class using the given class loader.
      Parameters:
      clazz - The fully qualified name of the class to be loaded
      classLoader - The classLoader to be used to load the given class
      Returns:
      The loaded class
      Throws:
      ClassNotFoundException - if the class cannot be located by the class loader.
    • toString

      public String toString()
      Overrides:
      toString in class Object