使用 Jberet 时,我可以在 ItemProcessor 中获取 beanIOItemReader 记录号吗?
Can I get the beanIOItemReader record number in an ItemProcessor when using Jberet?
我正在使用块读取文件并将内容插入数据库,table 中的其中一列需要输入文件中的记录号。有没有办法在传递给 ItemProcessor 的对象中获取它或从 ItemProcessor 中获取它?
JBeret BeanIOItemReader
将所有操作委托给底层 org.beanio.BeanReader
。因此,如果您需要来自输入的信息,那么您需要配置 BeanIO 映射文件以将其包含在 BeanReader
.
使用的 DTO 中
如果您需要访问累积统计数据,您可以查看 javax.batch.runtime.context.StepContext#getMetrics
,在那里您可以访问各种统计数据:
READ_COUNT
WRITE_COUNT
COMMIT_COUNT
ROLLBACK_COUNT
READ_SKIP_COUNT
PROCESS_SKIP_COUNT
FILTER_COUNT
WRITE_SKIP_COUNT
BeanReader.getRecordCount()
javadoc 将其描述为:
/**
* Returns the number of records read from the underlying input stream for the
* most recent bean object read from this reader. This typically returns 1
* unless a bean object was mapped to a record group which may span
* multiple records.
* @return the record count
* @since 2.0
*/
public int getRecordCount();
如果它通常 returns 1,那么我看不出它有什么用。
如果您想知道 reader 已读取的记录数,即第 5 条或第 6 条记录,那么您可以使用如上所述的批处理指标 READ_COUNT
。
我最终使用 ItemReadListener 在 afterRead 方法中获取 StepContext 指标,并使用当前读取计数更新我的对象读取。
我正在使用块读取文件并将内容插入数据库,table 中的其中一列需要输入文件中的记录号。有没有办法在传递给 ItemProcessor 的对象中获取它或从 ItemProcessor 中获取它?
JBeret BeanIOItemReader
将所有操作委托给底层 org.beanio.BeanReader
。因此,如果您需要来自输入的信息,那么您需要配置 BeanIO 映射文件以将其包含在 BeanReader
.
如果您需要访问累积统计数据,您可以查看 javax.batch.runtime.context.StepContext#getMetrics
,在那里您可以访问各种统计数据:
READ_COUNT
WRITE_COUNT
COMMIT_COUNT
ROLLBACK_COUNT
READ_SKIP_COUNT
PROCESS_SKIP_COUNT
FILTER_COUNT
WRITE_SKIP_COUNT
BeanReader.getRecordCount()
javadoc 将其描述为:
/**
* Returns the number of records read from the underlying input stream for the
* most recent bean object read from this reader. This typically returns 1
* unless a bean object was mapped to a record group which may span
* multiple records.
* @return the record count
* @since 2.0
*/
public int getRecordCount();
如果它通常 returns 1,那么我看不出它有什么用。
如果您想知道 reader 已读取的记录数,即第 5 条或第 6 条记录,那么您可以使用如上所述的批处理指标 READ_COUNT
。
我最终使用 ItemReadListener 在 afterRead 方法中获取 StepContext 指标,并使用当前读取计数更新我的对象读取。