我需要限定 14 条记录。chunkSize 是 10 页大小是 2。它的作用域只有 10 条记录。
我用不同的方式检查过。chunkSize = 5 pageSize = 10 范围仍然只有 10 条记录,而不是全部 14 条。
只有当 chunksize =11 和 pageSize =10 或 chunkSize = 10 和 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();
}
处理器代码,
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 ; }
我正在使用发生读取的相同字段更新处理器中的其他对象。所以我正在阅读器类中阅读“范围”实体。在处理器类中创建 execitionScope 对象并根据范围更新值并在 DB 中持久化 execitionScope。
两个实体都指向不同的表。ScopeParam
点击fin_t
表并ExecutionScope
点击exec_scope表。
请给我建议。