I need to scoped 14 records. chunkSize is 10 page Size is 2. It is scoping only 10 records.
I checked with different ways. chunkSize = 5 pageSize = 10 Still scoped only 10 records not all 14.
it works fine only if chunksize =11 and pageSize =10 or chunkSize = 10 and pageSize = 20
build.gradle
partition:
defaultPartitionSize: 5
partitionScopeChunkSize: 10
jobs:
jpaPagingSize: 2
===================ReaderClass============================
public class PagingItemReader extends
JpaPagingItemReader<ScopeParams> {
public PagingItemReader (
EntityManager entityManager,
EntityManagerFactory entityManagerFactory,
@Value("${spring.jobs.jpaPagingSize}") int jpaPagingSize)
Map<String, Object> parameterValues = new HashMap<>();
this.setQueryProvider(
ScopeParamsQueryProvider.buildForContinuousMatchScoping(
entityManager,
IndustryCodes.valueFromCode(industryCd)));
this.setEntityManagerFactory(entityManagerFactory);
this.setPageSize(jpaPagingSize);
this.setSaveState(true);
this.setParameterValues(parameterValues);
}
}
==============WriterClass==========
public class JpaItemWriter<T> extends JpaItemWriter<T> {
private JpaRepository<T, ? extends Serializable> repository;
public JpaItemWriter(JpaRepository<T, ?> repository) {
this.repository = repository;
}
@Override
@Transactional
public void write(List<? extends T> items) {
persistEntities(items);
}
private void persistEntities(List<? extends T> list) {
list.stream()
.peek(item -> log.info("Writing={}", item))
.forEach(repository::save);
}
}
===================Step Configuration========
public Step WorkStep(StepBuilderFactory stepBuilderFactory,
PagingItemReader ItemReader,
ItemProcessor ItemProcessor,
JpaItemWriter<Scope> itemWriter) {
return stepBuilderFactory.get(WORK_MATCH)
.<Scope, ExecutionScope>chunk(10)
.reader(ItemReader)
.processor(ItemProcessor)
.writer(itemWriter)
.build();
}
Processor Code,
public class MatchItemProcessor implements ItemProcessor<Scope,ExecutionScope> {
public ExecutionScope process(Scope financialTransaction) throws Exception {
return batchExecutionScope;
}
}
private ExecutionScope prepareData(Scope transaction) { ExecutionScope executionScope = new ExecutionScope(); executionScope .setIndustryTypeCode(financialTransaction.getIndustryTypeCode()); return executionScope ; }
I am updating other object in processor with same fields on which reading happens. So i am reading "Scope" entity in reader class . In processor class creating execitionScope object and updating values based on scope and persisting execitionScope in DB.
Both entities are pointing to different tables. ScopeParam
hit fin_t
table and ExecutionScope
hit exec_scope table.
please provide me suggestion.