Пример #1
0
 /*
  * Returns the number of rows in the file. <i>Side effect:</i> Moves the row pointer to the first row
  */
 @Override
 public int getTotalRows() throws DataAccessObjectException {
   if (totalRows == 0) {
     if (!isOpen) {
       throw new IllegalStateException("File is not open");
     }
     totalRows = DAORowUtil.calculateTotalRows(this);
   }
   return totalRows;
 }
Пример #2
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;
     }
   }
 }
Пример #3
0
  /**
   * Gets the next row from the current data access object data source. <i>Side effect:</i> Updates
   * the current record number
   */
  @Override
  public Row readRow() throws DataAccessObjectException {
    if (!isOpen) {
      open();
    }

    List<String> record;
    synchronized (lock) {
      try {
        record = csvReader.nextRecord();
      } catch (IOException e) {
        throw new DataAccessObjectException(e);
      }
    }

    if (!DAORowUtil.isValidRow(record)) {
      return null;
    }

    if (record.size() > headerRow.size()) {
      String errMsg =
          Messages.getFormattedString(
              "CSVFileDAO.errorRowTooLarge",
              new String[] {
                String.valueOf(currentRowNumber),
                String.valueOf(record.size()),
                String.valueOf(headerRow.size())
              });
      throw new DataAccessRowException(errMsg);
    }

    Row row = new Row(record.size());

    for (int i = 0; i < headerRow.size(); i++) {
      String value = record.get(i);
      if (value == null) {
        value = "";
      }
      row.put(headerRow.get(i), value);
    }
    currentRowNumber++;
    return row;
  }