Changeset 3634


Ignore:
Timestamp:
Aug 6, 2007, 2:48:44 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #573: Trim whitespace when checking for unique values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/migrate/net/sf/basedb/clients/migrate/ReporterTransfer.java

    r3532 r3634  
    7171 
    7272  /**
     73    Maps BASE 1 reporters that are considered duplicate by BASE 2 after
     74    whitespace has been trimmed from the external ID. Only used temporary until the
     75    reporterMap is generated. Map contain BASE 1 ID --> Base 1 ID where the value
     76    is the "real" reporter that is migrated to BASE 2.
     77  */
     78  private Map<Integer, Integer> duplicates = null;
     79 
     80  /**
    7381    Used for inserting reporter into Base 2.
    7482  */
     
    102110
    103111    externalIdMap = new HashMap<String, Integer>(count);
     112    duplicates = new HashMap<Integer, Integer>();
    104113    DbControl dc = newDbControl();
    105114    try
     
    120129      if (dc != null) dc.close();
    121130      externalIdMap.clear();
     131      duplicates.clear();
    122132      progress.stop();
    123133    }
     
    152162        rowCount++;
    153163        ReporterData item = createDataItem(rs);
    154         batcher.insert(item);
     164        if (item != null) batcher.insert(item);
    155165        progress.increase();
    156166        if (log.isDebugEnabled())
     
    195205      {
    196206        ReporterData reporter = result.next();
    197         reporterMap.put(externalIdMap.get(reporter.getExternalId()), new ReporterProxy(reporter));
     207        Integer base1Id = externalIdMap.get(reporter.getExternalId());
     208        reporterMap.put(base1Id, new ReporterProxy(reporter));
    198209        rowCount++;
    199210        progress.increase();
    200211        if (log.isDebugEnabled())
    201212        {
    202           log.debug("Reporter: " + reporter.getExternalId() + " has been mapped");
     213          log.debug("Reporter: " + reporter.getExternalId() +
     214            " has been mapped to BASE 1 ID="+base1Id);
     215        }
     216      }
     217     
     218      // Map duplicates
     219      for (Map.Entry<Integer, Integer> entry : duplicates.entrySet())
     220      {
     221        Integer base1Id = entry.getKey();
     222        Integer migratedBase1Id = entry.getValue();
     223        ReporterData migratedReporter = reporterMap.get(migratedBase1Id);
     224        reporterMap.put(base1Id, migratedReporter);
     225        if (log.isDebugEnabled())
     226        {
     227          log.debug("Reporter: " + migratedReporter.getExternalId() +
     228            " has been mapped to BASE 1 ID=" + base1Id);
    203229        }
    204230      }
     
    221247 
    222248  @param rs <code>ResultSet</code> containing the data for this item.
    223   @return <code>ReporterData</code>
     249  @return <code>ReporterData</code> or null if another reporter with same ID has already been created
    224250  @throws BaseException
    225251  @throws SQLException If current ResultSet position is invalid or number
     
    230256  {
    231257    // Populate a new ReporterData object   
    232     String externalId = rs.getString(2);
    233     ReporterData rd = Reporter.getNew(externalId);
    234     if (log.isDebugEnabled())
    235     {
    236       log.debug("Transfering Reporter BASE1 id(" + rs.getInt(1) + ")\texternal Id(" + externalId + ")");
    237     }
    238     externalIdMap.put(externalId, rs.getInt(1));
    239     if (!QUICK_TRANSFER)
    240     {
    241       String name = rs.getString(3);
    242       if (name == null || "".equals(name)) name = externalId;
    243       rd.setName(name);
    244       rd.setSymbol(rs.getString(4));
    245       int columnIndex = 5;
    246       for (String property : stringProperties)
    247       {
    248         rd.setExtended(property, rs.getString(columnIndex));
    249         columnIndex++;
    250       }
    251       // Set integer properties, integer properties should be listed
    252       // last(after the string properties) in the select statement
    253       String[] intProperties = { "length" };
    254       for (String property : intProperties)
    255       {
    256         rd.setExtended(property, rs.getInt(columnIndex));
    257         columnIndex++;
    258       }
    259     }   
     258    String externalId = rs.getString(2).trim();
     259    int base1Id = rs.getInt(1);
     260    ReporterData rd = null;
     261    if (externalIdMap.containsKey(externalId))
     262    {
     263      Integer migratedBase1Id = externalIdMap.get(externalId);
     264      log.warn("Duplicate reporter found in BASE 1 after trimming whitespace: id=" +
     265        base1Id + "; externald ID=" + externalId + "; Merging this reporter with reporter id="+
     266        migratedBase1Id);
     267      duplicates.put(base1Id, migratedBase1Id);
     268    }
     269    else
     270    {
     271      externalIdMap.put(externalId, base1Id);
     272      if (log.isDebugEnabled())
     273      {
     274        log.debug("Transfering Reporter BASE1 id(" + base1Id + ")\texternal Id(" + externalId + ")");
     275      }
     276      rd = Reporter.getNew(externalId);
     277      if (!QUICK_TRANSFER)
     278      {
     279        String name = rs.getString(3);
     280        if (name == null || "".equals(name)) name = externalId;
     281        rd.setName(name);
     282        rd.setSymbol(rs.getString(4));
     283        int columnIndex = 5;
     284        for (String property : stringProperties)
     285        {
     286          rd.setExtended(property, rs.getString(columnIndex));
     287          columnIndex++;
     288        }
     289        // Set integer properties, integer properties should be listed
     290        // last(after the string properties) in the select statement
     291        String[] intProperties = { "length" };
     292        for (String property : intProperties)
     293        {
     294          rd.setExtended(property, rs.getInt(columnIndex));
     295          columnIndex++;
     296        }
     297      }
     298    }
    260299    return rd;
    261300  }
Note: See TracChangeset for help on using the changeset viewer.