Package org.dbunit.dataset.datatype
Class DataType
java.lang.Object
org.dbunit.dataset.datatype.DataType
- Direct Known Subclasses:
AbstractDataType
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final DataTypeMaps the SQL BIGINT type.static final DataTypeAuxiliary for the BIGINT type using a long.static final DataTypeMaps the SQL BINARY type.static final DataTypeMaps the SQL BIT type.static final DataTypeMaps the SQL BLOB type.static final DataTypeMaps the SQL BOOLEAN type.static final DataTypeMaps the SQL CHAR type.static final DataTypeMaps the SQL CLOB type.static final DataTypeMaps the SQL DATE type.static final DataTypeMaps the SQL DECIMAL type.static final DataTypeMaps the SQL DOUBLE type.static final DataTypeMaps the SQL FLOAT type.static final DataTypeMaps the SQL INTEGER type.static final DataTypeMaps the SQL LONGNVARCHAR type.static final DataTypeMaps the SQL LONGVARBINARY type.static final DataTypeMaps the SQL LONGVARCHAR type.static final DataTypeMaps the SQL NCHAR type.static final DataTypeMaps the SQL NUMERIC type.static final DataTypeMaps the SQL NVARCHAR type.static final DataTypeMaps the SQL REAL type.static final RelativeDateTimeParserParser used to calculate consistent relative date and time values.static final DataTypeMaps the SQL SMALLINT type.static final DataTypeMaps the SQL TIME type.static final DataTypeMaps the SQL TIMESTAMP type.static final DataTypeMaps the SQL TINYINT type.static final DataTypeThe unrecognized/unmapped data type.static final DataTypeMaps the SQL VARBINARY type.static final DataTypeMaps the SQL VARCHAR type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringTypecast the specified value to string.abstract intReturns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.static DataTypeReturns theDataTypecorresponding to the specified value runtime class.static DataTypeforSqlType(int sqlType) Returns theDataTypecorresponding to the specified Sql type.static DataTypeforSqlTypeName(String sqlTypeName) Deprecated.Should not be used anymoreabstract intReturns the correspondingTypes.Returns the SQL type name for user types (null for basic SQL types)abstract ObjectgetSqlValue(int column, ResultSet resultSet) Returns the specified column value from the specified resultset object.abstract ClassReturns the runtime class of the typecast result.abstract booleanReturnstrueif thisDataTyperepresents a date and/or time.protected static booleanisExtendedSyntax(String input) Performs a quick check to test if the specified string uses extended syntax.abstract booleanisNumber()Returnstrueif thisDataTyperepresents a number.abstract voidsetSqlValue(Object value, int column, PreparedStatement statement) Set the specified value to the specified prepared statement object.abstract ObjectReturns the specified value typecasted to thisDataType
-
Field Details
-
UNKNOWN
The unrecognized/unmapped data type. -
CHAR
Maps the SQL CHAR type. -
VARCHAR
Maps the SQL VARCHAR type. -
LONGVARCHAR
Maps the SQL LONGVARCHAR type. -
CLOB
Maps the SQL CLOB type. -
NUMERIC
Maps the SQL NUMERIC type. -
DECIMAL
Maps the SQL DECIMAL type. -
BOOLEAN
Maps the SQL BOOLEAN type. -
BIT
Maps the SQL BIT type. -
TINYINT
Maps the SQL TINYINT type. -
SMALLINT
Maps the SQL SMALLINT type. -
INTEGER
Maps the SQL INTEGER type. -
BIGINT
Maps the SQL BIGINT type. -
BIGINT_AUX_LONG
Auxiliary for the BIGINT type using a long. Is currently only needed for methodforObject(Object). -
REAL
Maps the SQL REAL type. -
FLOAT
Maps the SQL FLOAT type. -
DOUBLE
Maps the SQL DOUBLE type. -
RELATIVE_DATE_TIME_PARSER
Parser used to calculate consistent relative date and time values. -
DATE
Maps the SQL DATE type. -
TIME
Maps the SQL TIME type. -
TIMESTAMP
Maps the SQL TIMESTAMP type. -
BINARY
Maps the SQL BINARY type. -
VARBINARY
Maps the SQL VARBINARY type. -
LONGVARBINARY
Maps the SQL LONGVARBINARY type. -
BLOB
Maps the SQL BLOB type. -
NCHAR
Maps the SQL NCHAR type. -
NVARCHAR
Maps the SQL NVARCHAR type. -
LONGNVARCHAR
Maps the SQL LONGNVARCHAR type.
-
-
Constructor Details
-
DataType
public DataType()
-
-
Method Details
-
typeCast
Returns the specified value typecasted to thisDataType- Parameters:
value- the value to typecast.- Returns:
- the typecast value.
- Throws:
TypeCastException- if the value cannot be typecast to thisDataType.
-
compare
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
o1is less than, equal to, or greater thano2. - Throws:
TypeCastException- if the arguments' types prevent them from being compared by this Comparator.
-
getSqlType
public abstract int getSqlType()Returns the correspondingTypes.- Returns:
- the corresponding
Typesconstant.
-
getTypeClass
Returns the runtime class of the typecast result.- Returns:
- the runtime class of the typecast result.
-
getSqlTypeName
Returns the SQL type name for user types (null for basic SQL types)- Returns:
- the SQL type name for user types, or
nullfor basic SQL types.
-
isNumber
public abstract boolean isNumber()Returnstrueif thisDataTyperepresents a number.- Returns:
trueif thisDataTyperepresents a number.
-
isDateTime
public abstract boolean isDateTime()Returnstrueif thisDataTyperepresents a date and/or time.- Returns:
trueif thisDataTyperepresents 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 thisDataType.
-
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 thisDataType.
-
asString
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
Returns theDataTypecorresponding to the specified Sql type. SeeTypes.- Parameters:
sqlType- theTypesconstant to look up.- Returns:
- the corresponding
DataType, orDataType.UNKNOWNif not recognized. - Throws:
DataTypeException- if the correspondingDataTypecannot be determined.
-
forSqlTypeName
Deprecated.Should not be used anymoreReturns theDataTypecorresponding to the specified Sql type name.- Parameters:
sqlTypeName- the Sql type name to look up.- Returns:
- the corresponding
DataType, orDataType.UNKNOWNif not recognized. - Throws:
DataTypeException- if the correspondingDataTypecannot be determined.
-
forObject
Returns theDataTypecorresponding to the specified value runtime class. This method returnsDataType.UNKNOWNif the value isnullor runtime class not recognized.- Parameters:
value- the value whose runtime class is to be mapped.- Returns:
- the corresponding
DataType, orDataType.UNKNOWNif not recognized.
-
isExtendedSyntax
Performs a quick check to test if the specified string uses extended syntax.- Parameters:
input- a string to check.- Returns:
trueif the input uses extended syntax;falseotherwise.
-