org.dbunit.dataset.datatype
Class AbstractDataType

java.lang.Object
  extended by org.dbunit.dataset.datatype.DataType
      extended by org.dbunit.dataset.datatype.AbstractDataType
Direct Known Subclasses:
BooleanDataType, BytesDataType, DateDataType, DoubleDataType, FloatDataType, IntegerDataType, LongDataType, NumberDataType, StringDataType, TimeDataType, TimestampDataType, UnknownDataType

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: 909 $ $Date: 2008-12-04 21:20:00 +0100 (Thu, 04 Dec 2008) $
Author:
Manuel Laflamme, Last changed by: $Author: gommma $

Field Summary
 
Fields inherited from class org.dbunit.dataset.datatype.DataType
BIGINT, BINARY, BIT, BLOB, BOOLEAN, CHAR, CLOB, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, LONGVARBINARY, LONGVARCHAR, NUMERIC, REAL, SMALLINT, TIME, TIMESTAMP, TINYINT, UNKNOWN, VARBINARY, VARCHAR
 
Constructor Summary
AbstractDataType(String name, int sqlType, Class classType, boolean isNumber)
           
 
Method Summary
protected  boolean areObjectsEqual(Object o1, Object o2)
          Checks whether the given objects are equal or not.
 int compare(Object o1, Object o2)
          Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
protected  int compareNonNulls(Object value1, Object value2)
          Compares non-null values to each other.
 int getSqlType()
          Returns the corresponding Types.
 Object getSqlValue(int column, ResultSet resultSet)
          Returns the specified column value from the specified resultset object.
 Class getTypeClass()
          Returns the runtime class of the typecast result.
 boolean isDateTime()
          Returns true if this DataType represents a date and/or time.
 boolean isNumber()
          Returns true if this DataType represents a number.
protected  Class loadClass(String clazz, ClassLoader classLoader)
           
protected  Class loadClass(String clazz, Connection connection)
           
 void setSqlValue(Object value, int column, PreparedStatement statement)
          Set the specified value to the specified prepared statement object.
 String toString()
           
 
Methods inherited from class org.dbunit.dataset.datatype.DataType
asString, forObject, forSqlType, forSqlTypeName, typeCast
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDataType

public AbstractDataType(String name,
                        int sqlType,
                        Class classType,
                        boolean isNumber)
Method Detail

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
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

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

getTypeClass

public Class getTypeClass()
Description copied from class: DataType
Returns the runtime class of the typecast result.

Specified by:
getTypeClass in class DataType

isNumber

public boolean isNumber()
Description copied from class: DataType
Returns true if this DataType represents a number.

Specified by:
isNumber in class DataType

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

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
Throws:
SQLException
TypeCastException

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
Throws:
SQLException
TypeCastException

loadClass

protected final Class loadClass(String clazz,
                                Connection connection)
                         throws ClassNotFoundException
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

loadClass

protected final Class loadClass(String clazz,
                                ClassLoader classLoader)
                         throws ClassNotFoundException
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

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2002-2012. All Rights Reserved.