@Override public Game mapFieldSet(FieldSet fs) { if(fs == null){ return null; } Game game = new Game(); game.setId(fs.readString("id")); game.setYear(fs.readInt("year")); game.setTeam(fs.readString("team")); game.setWeek(fs.readInt("week")); game.setOpponent(fs.readString("opponent")); game.setCompletes(fs.readInt("completes")); game.setAttempts(fs.readInt("attempts")); game.setPassingYards(fs.readInt("passingYards")); game.setPassingTd(fs.readInt("passingTd")); game.setInterceptions(fs.readInt("interceptions")); game.setRushes(fs.readInt("rushes")); game.setRushYards(fs.readInt("rushYards")); game.setReceptions(fs.readInt("receptions", 0)); game.setReceptionYards(fs.readInt("receptionYards")); game.setTotalTd(fs.readInt("totalTd")); return game; }
@Override public Game mapFieldSet(FieldSet fs) { if(fs == null){ return null; } Game game = new Game(); game.setId(fs.readString("id")); game.setYear(fs.readInt("year")); game.setTeam(fs.readString("team")); game.setWeek(fs.readInt("week")); game.setOpponent(fs.readString("opponent")); game.setCompletes(fs.readInt("completes")); game.setAttempts(fs.readInt("attempts")); game.setPassingYards(fs.readInt("passingYards")); game.setPassingTd(fs.readInt("passingTd")); game.setInterceptions(fs.readInt("interceptions")); game.setRushes(fs.readInt("rushes")); game.setRushYards(fs.readInt("rushYards")); game.setReceptions(fs.readInt("receptions", 0)); game.setReceptionYards(fs.readInt("receptionYards")); game.setTotalTd(fs.readInt("totalTd")); return game; }
@Override public Player mapFieldSet(FieldSet fs) { if(fs == null){ return null; } Player player = new Player(); player.setId(fs.readString("ID")); player.setLastName(fs.readString("lastName")); player.setFirstName(fs.readString("firstName")); player.setPosition(fs.readString("position")); player.setDebutYear(fs.readInt("debutYear")); player.setBirthYear(fs.readInt("birthYear")); return player; }
@Override public CustomerCredit mapFieldSet(FieldSet fieldSet) { CustomerCredit trade = new CustomerCredit(); trade.setId(fieldSet.readInt(ID_COLUMN)); trade.setName(fieldSet.readString(NAME_COLUMN)); trade.setCredit(fieldSet.readBigDecimal(CREDIT_COLUMN)); return trade; } }
@Override public Player mapFieldSet(FieldSet fs) { if(fs == null){ return null; } Player player = new Player(); player.setId(fs.readString("ID")); player.setLastName(fs.readString("lastName")); player.setFirstName(fs.readString("firstName")); player.setPosition(fs.readString("position")); player.setDebutYear(fs.readInt("debutYear")); player.setBirthYear(fs.readInt("birthYear")); return player; }
@Test public void testFieldSetWithNumberFormat() throws Exception { factory.setNumberFormat(NumberFormat.getNumberInstance(Locale.GERMAN)); FieldSet fieldSet = factory.create(new String[] {"19.991.218", "bar"} ); assertEquals(19991218, fieldSet.readInt(0)); }
@Test public void testVanillaFieldSetWithNames() throws Exception { FieldSet fieldSet = factory.create(new String[] {"1", "bar"}, new String[] {"foo", "bar"} ); assertEquals(1, fieldSet.readInt("foo")); }
/** * @see org.springframework.batch.item.ItemReader#read() */ @Override public Trade read() throws Exception { Trade t = null; for (FieldSet line; (line = this.delegate.read()) != null;) { String prefix = line.readString(0); if (prefix.equals("BEGIN")) { t = new Trade(); // Record must start with 'BEGIN' } else if (prefix.equals("INFO")) { Assert.notNull(t, "No 'BEGIN' was found."); t.setIsin(line.readString(1)); t.setCustomer(line.readString(2)); } else if (prefix.equals("AMNT")) { Assert.notNull(t, "No 'BEGIN' was found."); t.setQuantity(line.readInt(1)); t.setPrice(line.readBigDecimal(2)); } else if (prefix.equals("END")) { return t; // Record must end with 'END' } } Assert.isNull(t, "No 'END' was found."); return null; }
@Override public LineItem mapFieldSet(FieldSet fieldSet) { LineItem item = new LineItem(); item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN)); item.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN)); item.setDiscountPerc(fieldSet.readBigDecimal(DISCOUNT_PERC_COLUMN)); item.setDiscountAmount(fieldSet.readBigDecimal(DISCOUNT_AMOUNT_COLUMN)); item.setShippingPrice(fieldSet.readBigDecimal(SHIPPING_PRICE_COLUMN)); item.setHandlingPrice(fieldSet.readBigDecimal(HANDLING_PRICE_COLUMN)); item.setQuantity(fieldSet.readInt(QUANTITY_COLUMN)); item.setTotalPrice(fieldSet.readBigDecimal(TOTAL_PRICE_COLUMN)); return item; } }
public class ImportDataObjectFieldSetMapper implements FieldSetMapper<ImportDataObject> { @Override public ImportDataObject mapFieldSet(final FieldSet fieldSet) throws BindException { final ImportDataObject importDataObject = new ImportDataObject(); importDataObject.setKittenUrl(fieldSet.readString(0)); importDataObject.setKittenName(fieldSet.readString(1)); importDataObject.setNumOfReviews(fieldSet.readInt(2)); importDataObject.setRating(fieldSet.readInt(3)); importDataObject.setCategories(new ArrayList<String>()); for (int i = 4; i < fieldSet.getFieldCount(); i++) { importDataObject.getCategories().add(fieldSet.readString(i)); } return importDataObject; } }
public class UserMapper implements FieldSetMapper<User> { @Override public User mapFieldSet(FieldSet fieldSet) throws BindException { User user = new User(); String ped = fieldSet.readString("Position effective date"); user.setId(fieldSet.readInt("User ID")); user.setFn(fieldSet.readString("First Name")); user.loadRecord(fieldSet); // store fieldSet for regenerating line in future return user; } }