Changeset 3210


Ignore:
Timestamp:
Mar 26, 2007, 1:19:26 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #520: SpotBatcher? doesn't handle Float.NaN values

Also changed extra value tables to allow null values.

Location:
branches/2.2.3/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.3/src/core/net/sf/basedb/core/PositionExtraValueBatcher.java

    r2981 r3210  
    3131import java.sql.PreparedStatement;
    3232import java.sql.SQLException;
     33import java.sql.Types;
    3334
    3435/**
     
    218219    @param position The position coordinate
    219220    @param value The extra value
    220     @throws InvalidDataException If the value is null
    221221    @throws BaseException If there is another error
    222222  */
     
    226226    if (isClosed()) throw new ConnectionClosedException();
    227227    updateLastAccess();
    228     if (value == null) throw new InvalidUseOfNullException("value");
     228   
     229    if (sqlType == Types.FLOAT && value != null && ((Float)value).isNaN())
     230    {
     231      // Convert Float.NaN to NULL
     232      value = null;
     233    }
    229234
    230235    // TODO - should we verify max position?
     
    235240      extraSql.setObject(2, value, sqlType);
    236241      extraSql.addBatch();
    237       bytes += bytesPerRow + (valueType == Type.STRING ? value.toString().length() : 0);
     242      bytes += bytesPerRow + (valueType == Type.STRING && value != null ? value.toString().length() : 0);
    238243      totalInsertCount++;
    239244    }
  • branches/2.2.3/src/core/net/sf/basedb/core/SpotBatcher.java

    r2669 r3210  
    3131import java.sql.PreparedStatement;
    3232import java.sql.SQLException;
     33import java.sql.Types;
    3334
    3435/**
     
    228229      for (float intensity : intensities)
    229230      {
    230         spotSql.setFloat(i, intensity);
     231        if (Float.isNaN(intensity))
     232        {
     233          spotSql.setNull(i, Types.FLOAT);
     234        }
     235        else
     236        {
     237          spotSql.setFloat(i, intensity);
     238        }
    231239        i++;
    232240      }
  • branches/2.2.3/src/core/net/sf/basedb/core/SpotExtraValueBatcher.java

    r2981 r3210  
    3131import java.sql.PreparedStatement;
    3232import java.sql.SQLException;
     33import java.sql.Types;
    3334
    3435/**
     
    209210    @param position The position coordinate
    210211    @param value The extra value
    211     @throws InvalidDataException If the value is null
    212212    @throws BaseException If there is another error
    213213  */
     
    217217    if (isClosed()) throw new ConnectionClosedException();
    218218    updateLastAccess();
    219     if (value == null) throw new InvalidUseOfNullException("value");
     219
     220    if (sqlType == Types.FLOAT && value != null && ((Float)value).isNaN())
     221    {
     222      // Convert Float.NaN to NULL
     223      value = null;
     224    }
    220225
    221226    // TODO - should we verify max column and position?
     
    227232      extraSql.setObject(3, value, sqlType);
    228233      extraSql.addBatch();
    229       bytes += bytesPerRow + (valueType == Type.STRING ? value.toString().length() : 0);
     234      bytes += bytesPerRow + (valueType == Type.STRING && value != null ? value.toString().length() : 0);
    230235      totalInsertCount++;
    231236    }
  • branches/2.2.3/src/core/net/sf/basedb/core/VirtualColumn.java

    r2304 r3210  
    130130  */
    131131  public static final VirtualColumn EXTRA_INT =
    132     new VirtualColumn("extraInt", "value", Hibernate.INTEGER, 0, !INDEXED, !NULLABLE, !PRIMARY_KEY);
     132    new VirtualColumn("extraInt", "value", Hibernate.INTEGER, 0, !INDEXED, NULLABLE, !PRIMARY_KEY);
    133133
    134134  /**
     
    136136  */
    137137  public static final VirtualColumn EXTRA_FLOAT =
    138     new VirtualColumn("extraFloat", "value", Hibernate.FLOAT, 0, !INDEXED, !NULLABLE, !PRIMARY_KEY);
     138    new VirtualColumn("extraFloat", "value", Hibernate.FLOAT, 0, !INDEXED, NULLABLE, !PRIMARY_KEY);
    139139
    140140  /**
     
    142142  */
    143143  public static final VirtualColumn EXTRA_STRING =
    144     new VirtualColumn("extraString", "value", Hibernate.STRING, 255, !INDEXED, !NULLABLE, !PRIMARY_KEY);
     144    new VirtualColumn("extraString", "value", Hibernate.STRING, 255, !INDEXED, NULLABLE, !PRIMARY_KEY);
    145145
    146146  /**
  • branches/2.2.3/src/test/TestExperiment.java

    r2993 r3210  
    791791        numSpots++;
    792792        SqlResult r = spots.next();
    793         if (intBatcher != null) intBatcher.insert(r.getShort(column), r.getInt(position), numSpots);
    794         if (floatBatcher != null) floatBatcher.insert(r.getShort(column), r.getInt(position), r.getFloat(ch1) * r.getFloat(ch2));
    795         if (stringBatcher != null) stringBatcher.insert(r.getShort(column), r.getInt(position), "Spot number " + numSpots);
     793       
     794        if (numSpots == 1)
     795        {
     796          // Test NULL and Float.NaN
     797          if (intBatcher != null) intBatcher.insert(r.getShort(column), r.getInt(position), null);
     798          if (floatBatcher != null) floatBatcher.insert(r.getShort(column), r.getInt(position), Float.NaN);
     799          if (stringBatcher != null) stringBatcher.insert(r.getShort(column), r.getInt(position), null);
     800        }
     801        else
     802        {
     803          if (intBatcher != null) intBatcher.insert(r.getShort(column), r.getInt(position), numSpots);
     804          if (floatBatcher != null) floatBatcher.insert(r.getShort(column), r.getInt(position), r.getFloat(ch1) * r.getFloat(ch2));
     805          if (stringBatcher != null) stringBatcher.insert(r.getShort(column), r.getInt(position), "Spot number " + numSpots);
     806        }
    796807      }
    797808
     
    873884        numSpots++;
    874885        SqlResult r = spots.next();
    875         if (intBatcher != null) intBatcher.insert(r.getInt(position), numSpots);
    876         if (floatBatcher != null) floatBatcher.insert(r.getInt(position), r.getFloat(prod));
    877         if (stringBatcher != null) stringBatcher.insert(r.getInt(position), "Spot number " + numSpots);
     886        if (numSpots == 1)
     887        {
     888          if (intBatcher != null) intBatcher.insert(r.getInt(position), null);
     889          if (floatBatcher != null) floatBatcher.insert(r.getInt(position), Float.NaN);
     890          if (stringBatcher != null) stringBatcher.insert(r.getInt(position), null);
     891        }
     892        else
     893        {
     894          if (intBatcher != null) intBatcher.insert(r.getInt(position), numSpots);
     895          if (floatBatcher != null) floatBatcher.insert(r.getInt(position), r.getFloat(prod));
     896          if (stringBatcher != null) stringBatcher.insert(r.getInt(position), "Spot number " + numSpots);
     897        }
    878898      }
    879899
Note: See TracChangeset for help on using the changeset viewer.