@Override public StudentDTO mapRow(RowSet rowSet) throws Exception { StudentDTO student = new StudentDTO(); student.setName(rowSet.getColumnValue(0)); student.setEmailAddress(rowSet.getColumnValue(1)); student.setPurchasedPackage(rowSet.getColumnValue(2)); return student; } }
@Override public String[] mapRow(final RowSet rs) throws Exception { return rs.getCurrentRow(); }
/** * @return string corresponding to logical record according to * {@link #setRowMapper(RowMapper)} (might span multiple rows in file). */ @Override protected T doRead() throws Exception { if (this.noInput || this.rs == null) { return null; } if (rs.next()) { try { return this.rowMapper.mapRow(rs); } catch (final Exception e) { throw new ExcelFileParseException("Exception parsing Excel file.", e, this.resource.getDescription(), rs.getMetaData().getSheetName(), rs.getCurrentRowIndex(), rs.getCurrentRow()); } } else { this.currentSheet++; if (this.currentSheet >= this.getNumberOfSheets()) { if (logger.isDebugEnabled()) { logger.debug("No more sheets in '" + this.resource.getDescription() + "'."); } return null; } else { this.openSheet(); return this.doRead(); } } }
private void openSheet() { final Sheet sheet = this.getSheet(this.currentSheet); this.rs =rowSetFactory.create(sheet); if (logger.isDebugEnabled()) { logger.debug("Opening sheet " + sheet.getName() + "."); } for (int i = 0; i < this.linesToSkip; i++) { if (rs.next() && this.skippedRowsCallback != null) { this.skippedRowsCallback.handleRow(rs); } } if (logger.isDebugEnabled()) { logger.debug("Openend sheet " + sheet.getName() + ", with " + sheet.getNumberOfRows() + " rows."); } }
/** * Map the {@link org.springframework.batch.item.file.transform.FieldSet} to an object retrieved from the enclosing Spring * context, or to a new instance of the required type if no prototype is * available. * * @throws org.springframework.validation.BindException if there is a type conversion or other error (if * the {@link org.springframework.validation.DataBinder} from {@link #createBinder(Object)} has errors * after binding). * @throws org.springframework.beans.NotWritablePropertyException if the {@link org.springframework.batch.item.file.transform.FieldSet} contains a * field that cannot be mapped to a bean property. * @see org.springframework.batch.item.file.mapping.FieldSetMapper#mapFieldSet(org.springframework.batch.item.file.transform.FieldSet) */ @Override public T mapRow(RowSet rs) throws BindException { T copy = getBean(); DataBinder binder = createBinder(copy); binder.bind(new MutablePropertyValues(getBeanProperties(copy, rs.getProperties()))); if (binder.getBindingResult().hasErrors()) { throw new BindException(binder.getBindingResult()); } return copy; }
@Override public StudentDTO mapRow(RowSet rowSet) throws Exception { StudentDTO student = new StudentDTO(); student.setName(rowSet.getColumnValue(0)); student.setEmailAddress(rowSet.getColumnValue(1)); student.setPurchasedPackage(rowSet.getColumnValue(2)); return student; } }