Fwd: DefaultDataTypeFactory and NumberTolerantDataType

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: DefaultDataTypeFactory and NumberTolerantDataType

Texas_Tester

Can someone explain why the tolerance code in DefaultDataTypeFactory is set to only work on Numeric and Decimal types and not Double and Float?

    /**
     * @see org.dbunit.dataset.datatype.IDataTypeFactory#createDataType(int, java.lang.String, java.lang.String, java.lang.String)
     */
    public DataType createDataType(int sqlType, String sqlTypeName, String tableName, String columnName) throws DataTypeException
    {
        if(logger.isDebugEnabled())
            logger.debug("createDataType(sqlType={} , sqlTypeName={}, tableName={}, columnName={}) - start",
                new Object[] {new Integer(sqlType), sqlTypeName, tableName, columnName} );

        if (sqlType == Types.NUMERIC || sqlType == Types.DECIMAL)                                                                        // <-----------
        {
            // Check if the user has set a tolerance delta for this floating point field
            ToleratedDelta delta = _toleratedDeltaMap.findToleratedDelta(tableName, columnName);
            // Found a toleratedDelta object
            if(delta!=null) {
                if(logger.isDebugEnabled())
                    logger.debug("Creating NumberTolerantDataType for table={}, column={}, toleratedDelta={}",
                        new Object[]{tableName, columnName, delta.getToleratedDelta() });
               
                // Use a special data type to implement the tolerance for numbers (floating point things)
                NumberTolerantDataType type = new NumberTolerantDataType("NUMERIC_WITH_TOLERATED_DELTA",
                        sqlType, delta.getToleratedDelta());
                return type;
            }
        }
       
        // In all other cases (default) use the default data type creation
        return this.createDataType(sqlType, sqlTypeName);
    }

I extended DefaultDataTypeFactory and added checks for float and double.
@Override
   public DataType createDataType(int sqlType, String sqlTypeName, String tableName,
                                  String columnName) throws DataTypeException
   {
      DataType dataType = super.createDataType(sqlType, sqlTypeName, tableName, columnName);

      if((sqlType == Types.DOUBLE) || (sqlType == Types.FLOAT))
      {
         // Check if the user has set a tolerance delta for this floating point field
         ToleratedDeltaMap toleratedDeltaMap = getToleratedDeltaMap();
         ToleratedDelta    delta             = toleratedDeltaMap.findToleratedDelta(tableName, columnName);

         // Found a toleratedDelta object
         if(delta != null)
         {
            if(logger.isDebugEnabled())
            {
               logger.debug("Creating NumberTolerantDataType for table={}, column={}, toleratedDelta={}",
                            new Object[]{ tableName,
                                          columnName, delta.getToleratedDelta() });
            }

            // Use a special data type to implement the tolerance for numbers (floating point things)
            dataType = new NumberTolerantDataType("NUMERIC_WITH_TOLERATED_DELTA", sqlType,
                                                  delta.getToleratedDelta());
         }
      }

      return dataType;
   }

Would anyone else find this helpful?

-- Jeff Benton


------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user