Example #1
0
 /** Set the dataReader to point to the row where load has to be started */
 private void rowToStart(Config cfg, DataReader daoReader) throws DataAccessObjectException {
   // start at the correct row
   final int rowToStart;
   try {
     rowToStart = cfg.getInt(Config.LOAD_ROW_TO_START_AT);
   } catch (final ParameterLoadException e) {
     return;
   }
   if (rowToStart > 0) {
     // keep skipping over rows until we run into an invalid row or we have gotten
     // to the starting row
     while (daoReader.getCurrentRowNumber() < rowToStart) {
       if (!DAORowUtil.isValidRow(daoReader.readRow())) break;
     }
   }
 }
Example #2
0
  /**
   * Utility function for calculating the total number of rows available to current DAO instance
   *
   * @throws DataAccessObjectException
   */
  public static int calculateTotalRows(DataReader dataReader) throws DataAccessObjectException {
    try {
      // visit the rows
      DAOSizeVisitor visitor = new DAOSizeVisitor();
      for (Row row = dataReader.readRow(); isValidRow(row); row = dataReader.readRow()) {
        visitor.visit(row);
      }

      return visitor.getNumberOfRows();
    } catch (DataAccessObjectException daoe) {
      logger.error(Messages.getString("RowUtil.error"), daoe); // $NON-NLS-1$
      throw daoe;
    } finally {
      // since we've read all the rows, reopen the reader to reset the input
      dataReader.close();
      dataReader.open();
    }
  }
Example #3
0
  public void skipRowToStartOffset(
      Config cfg, DataReader rdr, ILoaderProgress mon, boolean updateProgress)
      throws LoadException {

    try {
      cfg.setValue(LastRun.LAST_LOAD_BATCH_ROW, 0);
      rowToStart(cfg, rdr);
      if (updateProgress) {
        // set the last processed value to the starting row
        int currentRow = rdr.getCurrentRowNumber();
        if (mon != null && currentRow > 0) mon.worked(currentRow);
        cfg.setValue(LastRun.LAST_LOAD_BATCH_ROW, currentRow);
        cfg.saveLastRun();
      }
    } catch (final DataAccessObjectException e) {
      handleError(e, "errorDaoStartRow");
    } catch (final IOException e) {
      handleError(e, "errorLastRun");
    }
  }