1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package examples.springbatch.bulkinsert;
17
18 import examples.springbatch.common.PersonRecord;
19 import org.jspecify.annotations.Nullable;
20 import org.springframework.batch.infrastructure.item.ItemReader;
21
22 public class TestRecordGenerator implements ItemReader<PersonRecord> {
23
24 private int index = 0;
25
26 private static final PersonRecord[] testRecords = {
27 new PersonRecord(null, "Fred", "Flintstone"),
28 new PersonRecord(null, "Wilma", "Flintstone"),
29 new PersonRecord(null, "Pebbles", "Flintstone"),
30 new PersonRecord(null, "Barney", "Rubble"),
31 new PersonRecord(null, "Betty", "Rubble"),
32 new PersonRecord(null, "Bamm Bamm", "Rubble")
33 };
34
35 @Override
36 public @Nullable PersonRecord read() {
37 if (index < testRecords.length) {
38 return (testRecords[index++]);
39 } else {
40 return null;
41 }
42 }
43
44 public static int recordCount() {
45 return testRecords.length;
46 }
47 }