Package org.dbunit.dataset.datatype
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
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$
-
Field Summary
Fields inherited from class org.dbunit.dataset.datatype.DataType
BIGINT, BIGINT_AUX_LONG, BINARY, BIT, BLOB, BOOLEAN, CHAR, CLOB, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, LONGNVARCHAR, LONGVARBINARY, LONGVARCHAR, NCHAR, NUMERIC, NVARCHAR, REAL, RELATIVE_DATE_TIME_PARSER, SMALLINT, TIME, TIMESTAMP, TINYINT, UNKNOWN, VARBINARY, VARCHAR -
Constructor Summary
ConstructorsConstructorDescriptionAbstractDataType(String name, int sqlType, Class classType, boolean isNumber) Constructs a data type with the given SQL type mapping. -
Method Summary
Modifier and TypeMethodDescriptionprotected final booleanareObjectsEqual(Object o1, Object o2) Checks whether the given objects are equal or not.intReturns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.protected intcompareNonNulls(Object value1, Object value2) Compares non-null values to each other.intReturns the correspondingTypes.getSqlValue(int column, ResultSet resultSet) Returns the specified column value from the specified resultset object.Returns the runtime class of the typecast result.booleanReturnstrueif thisDataTyperepresents a date and/or time.booleanisNumber()Returnstrueif thisDataTyperepresents a number.protected final ClassloadClass(String clazz, ClassLoader classLoader) Loads the given class using the given class loader.protected final ClassloadClass(String clazz, Connection connection) Loads the given class using the class loader of the given connection.voidsetSqlValue(Object value, int column, PreparedStatement statement) Set the specified value to the specified prepared statement object.toString()Methods inherited from class org.dbunit.dataset.datatype.DataType
asString, forObject, forSqlType, forSqlTypeName, getSqlTypeName, isExtendedSyntax, typeCast
-
Constructor Details
-
AbstractDataType
Constructs a data type with the given SQL type mapping.- Parameters:
name- the data type name.sqlType- theTypesconstant this data type maps to.classType- the Java class representing this data type's values.isNumber-trueif this data type represents a number.
-
-
Method Details
-
compare
Description copied from class:DataTypeReturns 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:
comparein classDataType- Parameters:
o1- the first value to compare.o2- the second value to compare.- Returns:
- a negative integer, zero, or a positive integer as
o1is less than, equal to, or greater thano2. - Throws:
TypeCastException- if the arguments' types prevent them from being compared by this Comparator.
-
compareNonNulls
Compares non-null values to each other. Both objects are guaranteed to be not null and to implement the interfaceComparable. The two given objects are the results of theDataType.typeCast(Object)method call which is usually implemented by a specializedDataTypeimplementation.- Parameters:
value1- First value resulting from theDataType.typeCast(Object)method callvalue2- Second value resulting from theDataType.typeCast(Object)method call- Returns:
- The result of the
Comparable.compareTo(Object)invocation. - Throws:
TypeCastException- if either value cannot be cast to aComparable.
-
areObjectsEqual
Checks whether the given objects are equal or not.- Parameters:
o1- first objecto2- second object- Returns:
trueif both objects arenull(and hence equal) or if theo1.equals(o2)istrue.
-
getSqlType
public int getSqlType()Description copied from class:DataTypeReturns the correspondingTypes.- Specified by:
getSqlTypein classDataType- Returns:
- the corresponding
Typesconstant.
-
getTypeClass
Description copied from class:DataTypeReturns the runtime class of the typecast result.- Specified by:
getTypeClassin classDataType- Returns:
- the runtime class of the typecast result.
-
isNumber
public boolean isNumber()Description copied from class:DataTypeReturnstrueif thisDataTyperepresents a number. -
isDateTime
public boolean isDateTime()Description copied from class:DataTypeReturnstrueif thisDataTyperepresents a date and/or time.- Specified by:
isDateTimein classDataType- Returns:
trueif thisDataTyperepresents a date and/or time.
-
getSqlValue
Description copied from class:DataTypeReturns the specified column value from the specified resultset object.- Specified by:
getSqlValuein classDataType- 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 thisDataType.
-
setSqlValue
public void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException Description copied from class:DataTypeSet the specified value to the specified prepared statement object.- Specified by:
setSqlValuein classDataType- 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 thisDataType.
-
loadClass
Loads the given class using the class loader of the given connection.- Parameters:
clazz- The fully qualified name of the class to be loadedconnection- 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 loadedclassLoader- 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
-