• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ItemReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.batch.item.ItemReader的典型用法代码示例。如果您正苦于以下问题:Java ItemReader类的具体用法?Java ItemReader怎么用?Java ItemReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ItemReader类属于org.springframework.batch.item包,在下文中一共展示了ItemReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: hdfsFileReader

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
@StepScope
ItemReader<Map<String, Object>> hdfsFileReader(HdfsResourceLoader resourceLoader, LineMapper<Map<String, Object>> lineMapper) throws IOException {
	MultiResourceItemReader<Map<String, Object>> multiReader = new MultiResourceItemReader<>();
	Resource[] resources = resourceLoader.getResources("/demo/influencers/*");
	multiReader.setResources(resources);	
	FlatFileItemReader<Map<String, Object>> itemReader = new FlatFileItemReader<>();
	itemReader.setLineMapper(lineMapper);
	multiReader.setDelegate(itemReader);
	return multiReader;
}
 
开发者ID:trisberg,项目名称:springone-2015,代码行数:12,代码来源:BatchHive2Configuration.java


示例2: importTicketStep

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Step importTicketStep(final StepBuilderFactory stepBuilderFactory,
                             @Qualifier("jpaTransactionManagerForBatch")
                             final PlatformTransactionManager jpaTransactionManager,
                             final @Value("${ticket.chunk.size}") int chunkSize,
                             final ItemReader<Ticket> ticketReader,
                             final ItemWriter<Ticket> ticketWriter,
                             final ItemProcessor<Ticket, Ticket> importTicketProcessor) {
    return stepBuilderFactory.get("importTicketStep")
            .<Ticket, Ticket>chunk(chunkSize)
            .reader(ticketReader)
            .processor(importTicketProcessor)
            .writer(ticketWriter)
            .transactionManager(jpaTransactionManager)
            .build();
}
 
开发者ID:create1st,项目名称:spring-batch,代码行数:17,代码来源:BatchConfiguration.java


示例3: testRead

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
/**
 * Test method for {@link org.emonocot.harvest.common.CompositeItemReader#read()}.
 */
@Test
public void testRead() throws Exception {
	ItemReader<Object> mock1 = delegates.get(0);
	ItemReader<Object> mock2 = delegates.get(1);
	EasyMock.expect(mock1.read()).andReturn("from 1st delegate");
	EasyMock.expect(mock1.read()).andReturn("from 1st delegate");
	EasyMock.expect(mock1.read()).andReturn(null);
	EasyMock.expect(mock2.read()).andReturn("from 2nd delegate");
	EasyMock.expect(mock2.read()).andReturn(null);
	EasyMock.replay(mock1,mock2);
	CompositeItemReader<Object> composite = new CompositeItemReader<>();
	composite.setDelegates(delegates);

	for (int i = 1; i <= 2; i++) {
		assertEquals("Read " + (i) + " should have returned an object", "from 1st delegate", composite.read());
	}
	assertEquals("Read 3 should have returned an object", "from 2nd delegate", composite.read());
	assertNull("There should be no more items to read", composite.read());
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:23,代码来源:CompositeItemReaderTest.java


示例4: createInventoryEntryStep

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Step createInventoryEntryStep(final BlockingSphereClient sphereClient,
                                     final ItemReader<ProductProjection> inventoryEntryReader,
                                     final ItemProcessor<ProductProjection, List<InventoryEntryDraft>> inventoryEntryProcessor,
                                     final ItemWriter<List<InventoryEntryDraft>> inventoryEntryWriter) {
    final StepBuilder stepBuilder = stepBuilderFactory.get("createInventoryEntryStep");
    return stepBuilder
            .<ProductProjection, List<InventoryEntryDraft>>chunk(1)
            .reader(inventoryEntryReader)
            .processor(inventoryEntryProcessor)
            .writer(inventoryEntryWriter)
            .faultTolerant()
            .skip(ErrorResponseException.class)
            .skipLimit(1)
            .build();
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-data,代码行数:17,代码来源:InventoryEntryCreationJobConfiguration.java


示例5: userAnonymizedIdReader

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
private ItemReader<UUID> userAnonymizedIdReader()
{
	try
	{
		JdbcPagingItemReader<UUID> reader = new JdbcPagingItemReader<>();
		final SqlPagingQueryProviderFactoryBean sqlPagingQueryProviderFactoryBean = new SqlPagingQueryProviderFactoryBean();
		sqlPagingQueryProviderFactoryBean.setDataSource(dataSource);
		sqlPagingQueryProviderFactoryBean.setSelectClause("select id");
		sqlPagingQueryProviderFactoryBean.setFromClause("from users_anonymized");
		sqlPagingQueryProviderFactoryBean.setSortKey("id");
		reader.setQueryProvider(sqlPagingQueryProviderFactoryBean.getObject());
		reader.setDataSource(dataSource);
		reader.setPageSize(USERS_CHUNK_SIZE);
		reader.setRowMapper(singleUUIDColumnRowMapper());
		reader.afterPropertiesSet();
		reader.setSaveState(true);
		logger.info("Reading users anonymized in chunks of {}", USERS_CHUNK_SIZE);
		return reader;
	}
	catch (Exception e)
	{
		throw YonaException.unexpected(e);
	}
}
 
开发者ID:yonadev,项目名称:yona-server,代码行数:25,代码来源:SendSystemMessageBatchJob.java


示例6: itemReader

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
@StepScope
public ItemReader<String> itemReader() {
	final List<String> items = IntStream.range(0, 1000).mapToObj(String::valueOf).collect(toList());

	return new ListItemReader<String>(items);
}
 
开发者ID:phjardas,项目名称:spring-batch-tools,代码行数:8,代码来源:TestJobConfig.java


示例7: readCsvFileIntoTableStep

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean(name = readCsvFileIntoTableStep)
public Step readCsvFileIntoTableStep(
        StepBuilderFactory stepBuilderFactory,
        PlatformTransactionManager platformTransactionManager,
        @Qualifier(readCsvFileIntoTableStepReader) ItemReader<Customer> ir,
        @Qualifier(readCsvFileIntoTableStepProcessor) ItemProcessor<Customer, Customer> itemProcessor,
        @Qualifier(readCsvFileIntoTableStepWriter) ItemWriter<Customer> iw) {

    StepBuilder builder = stepBuilderFactory.get(readCsvFileIntoTableStep);

    return builder.<Customer, Customer>chunk(3)
            .reader(ir)
            .processor(itemProcessor)
            .writer(iw)
            .transactionManager(platformTransactionManager)
            .build();
}
 
开发者ID:joshlong,项目名称:javaconfig-ftw,代码行数:18,代码来源:BatchConfiguration.java


示例8: importProductsJob

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Job importProductsJob(Tasklet decompressTasklet, ItemReader<Product> reader) {

    Step decompress = stepBuilders.get("decompress")
                                  .tasklet(decompressTasklet)
                                  .repository(jobRepository)
                                  .transactionManager(transactionManager)
                                  .build();

    Step readWriteProducts = stepBuilders.get("readWriteProducts")
                                         .<Product, Product>chunk(3)
                                         .reader(reader)
                                         .writer(writer())
                                         .faultTolerant()
                                         .skipLimit(5)
                                         .skip(FlatFileParseException.class)
                                         .build();

    return jobBuilders.get("importProductsJob")
                      .repository(jobRepository)
                      .listener(loggerListener)
                      .start(decompress)
                      .next(readWriteProducts)
                      .build();
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:26,代码来源:ImportProductJobConfiguration.java


示例9: productItemReader

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public ItemReader<Product> productItemReader() throws Exception {
    JpaPagingItemReader<Product> reader = new JpaPagingItemReader<Product>();
    reader.setEntityManagerFactory(emf);
    reader.setQueryString("select p from Product p");
    reader.setPageSize(5);
    reader.afterPropertiesSet();

    return reader;
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:11,代码来源:JobStructureJpaConfig.java


示例10: productItemReader

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public ItemReader<Product> productItemReader() throws Exception {
	FlatFileItemReader<Product> reader = new FlatFileItemReader<Product>();
	reader.setResource(new ClassPathResource("/kr/spring/batch/chapter05/test/input/multi-products-delimited.txt"));
	reader.setLinesToSkip(1);
	reader.setLineMapper(productLineMapper());

	return reader;
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:10,代码来源:JobStructureDelimitedMultiFlatFileConfig.java


示例11: step2

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean("step2")
public Step step2(StepBuilderFactory stepBuilderFactory, ItemReader<Employee> reader,
                   ItemProcessor<Employee, Permanent> processor) {
      return stepBuilderFactory.get("step2")
              .<Employee, Permanent>chunk(2)
              .reader(reader)
              .processor(processor)
              .writer(xmlWriter())
              .build();
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:11,代码来源:BatchConfig.java


示例12: jobFactory

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Supplier<Job> jobFactory(JmsTemplate jmsTemplate, Artifact jreArtifact,
		GraphDatabaseService graphDatabaseService) throws SettingsBuildingException {
	return () -> {
		ItemReader<Page<Artifact, Artifact>> reader = new Reader(jmsTemplate, new ActiveMQQueue(this.output));
		ItemProcessor<Page<Artifact, Artifact>, Result> processor = new Processor(new AnalysisRunner(this.timeout),
				jreArtifact, new File(this.lastModifiedCache), this.groupIdFilter);
		ItemWriter<Result> writer = new Writer(graphDatabaseService);
		Step step = this.stepBuilderFactory.get("analysis").<Page<Artifact, Artifact>, Result>chunk(1)
				.faultTolerant().skipPolicy(new LoggingAlwaysSkipItemSkipPolicy()).noRollback(Throwable.class)
				.reader(reader).processor(processor).writer(writer).build();
		return this.jobBuilderFactory.get("analysis").start(step).build();
	};
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:15,代码来源:Configuration.java


示例13: toWorkerPool

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
public WorkerPool toWorkerPool(JmsTemplate jmsTemplate,
		Supplier<ch.unibe.scg.kowalski.worker.match.Processor> processorFactoryMatch,
		Supplier<ch.unibe.scg.kowalski.worker.dependent.Processor> processorFactoryDependent,
		Supplier<ch.unibe.scg.kowalski.worker.dependency.Processor> processorFactoryDependency) {
	ItemReader<?> reader = this.toReader(jmsTemplate);
	ItemProcessor<?, ?> processor = this.toProcessor(processorFactoryMatch, processorFactoryDependent,
			processorFactoryDependency);
	ItemWriter<?> writer = this.toWriter(jmsTemplate);
	return new WorkerPool(this.size, reader, processor, writer);
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:11,代码来源:WorkerPoolParser.java


示例14: toReader

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
private ItemReader<?> toReader(JmsTemplate jmsTemplate) {
	if (this.readLimit.isPresent()) {
		return new LimitedReader<>(jmsTemplate, this.input, this.readLimit.get());
	} else {
		return new Reader<>(jmsTemplate, this.input);
	}
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:8,代码来源:WorkerPoolParser.java


示例15: innofactorImportStep

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean(name = STEP_NAME)
public Step innofactorImportStep(@Qualifier(STEP_NAME) ItemReader<InnofactorImportFileLine> reader,
                                 @Qualifier(STEP_NAME) ItemWriter<MetsastajaRekisteriPerson> writer) {
    CompositeItemProcessor<InnofactorImportFileLine, MetsastajaRekisteriPerson>
            processorChain = new CompositeItemProcessor<>();

    processorChain.setDelegates(Arrays.asList(
            new InnofactorImportFormatter(),
            new MetsastajaRekisteriItemValidator()
    ));

    return stepBuilder.get(JOB_NAME)
            .<InnofactorImportFileLine, MetsastajaRekisteriPerson>chunk(BatchConfig.BATCH_SIZE)
            .reader(reader)
            .processor(processorChain)
            .writer(writer)
            .faultTolerant()
            .skipLimit(200)
            .skip(PersistenceException.class)
            .skip(org.hibernate.exception.ConstraintViolationException.class)
            .skip(DataIntegrityViolationException.class)
            .skip(InvalidHunterDateFieldException.class)
            .skip(InvalidHunterNumberException.class)
            .skip(InvalidSsnException.class)
            .skip(InvalidPersonName.class)
            .skip(InvalidRhyException.class)
            .listener(new LoggingBatchListener())
            .build();
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:30,代码来源:InnofactorImportConfig.java


示例16: step1

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Step step1(ItemReader<Result> restMovieReader,
                    ItemProcessor<Result, Movie> moviesItemProcessor,
                    RepositoryItemWriter<Movie> movieRepositoryItemWriter) throws Exception {
    return stepBuilderFactory.get("step1")
            .<Result, Movie>chunk(10)
            .reader(restMovieReader)
            .processor(moviesItemProcessor)
            .writer(movieRepositoryItemWriter)
            .build();
}
 
开发者ID:RawSanj,项目名称:SpringRestBatch,代码行数:12,代码来源:JobConfiguration.java


示例17: step1

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader<MooreNcaaStat> reader,
				  ItemWriter<MooreNcaaStat> writer) {
	return stepBuilderFactory.get("step1")
			.<MooreNcaaStat, MooreNcaaStat>chunk(10)
			.reader(reader)
			.writer(writer)
			.build();
}
 
开发者ID:mminella,项目名称:TaskMadness,代码行数:10,代码来源:MooreStatConfiguration.java


示例18: step1

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Step step1(StepBuilderFactory stepBuilderFactory,
				  ItemReader<NcaaStats> reader,
				  ItemWriter<NcaaStats> writer,
				  ItemProcessor<NcaaStats,NcaaStats> processor) {
	return stepBuilderFactory.get("step1")
			.<NcaaStats, NcaaStats>chunk(10)
			.reader(reader)
			.processor(processor)
			.writer(writer)
			.build();
}
 
开发者ID:mminella,项目名称:TaskMadness,代码行数:13,代码来源:NcaaStatConfiguration.java


示例19: reader

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public ItemReader<Account> reader() {
	String sqlFile = "META-INF/hello/AccountDao/findAll.sql";
	String sql = sqlFinder.get(sqlFile);

	Mapper<Account> rowMapper = new Mapper<>(Account.class, config);

	DomaConsorItemReader<Account> itemReader = new DomaConsorItemReader<>(sql, rowMapper);
	itemReader.setSelectOption(SelectOptions.get().limit(3).offset(0));
	return itemReader;
}
 
开发者ID:lospatitos,项目名称:springboot-batch-doma,代码行数:12,代码来源:BatchConfiguration.java


示例20: job2

import org.springframework.batch.item.ItemReader; //导入依赖的package包/类
@Bean
public Job job2() throws Exception {

    AtomicInteger source = new AtomicInteger(1);
    Logger logger = LoggerFactory.getLogger(ChunkedBatch.class);

    ItemReader<Integer> reader = () -> {
        int value = source.getAndIncrement();
        if (value > 100) {
            //nullを返したらデータの読み取り終了とみなされる
            return null;
        }
        return value;
    };

    ItemProcessor<Integer, String> processor = item -> {
        //nullを返したらItemWriterには渡さない
        if (item % 2 == 0 && item > 10) {
            return null;
        }
        return String.format("*%d*", item);
    };

    ItemWriter<String> writer = items -> logger.info("{}", items);

    Step step = steps.get("step2")
            //10個ずつItemWriterに渡される
            .<Integer, String> chunk(10).reader(reader)
            .processor(processor).writer(writer).build();

    return jobs.get("job2").start(step).build();
}
 
开发者ID:backpaper0,项目名称:spring-boot-sandbox,代码行数:33,代码来源:ChunkedBatch.java



注:本文中的org.springframework.batch.item.ItemReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PostPersist类代码示例发布时间:2022-05-21
下一篇:
Java SelectExpressionItem类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap