當前位置: 首頁>>代碼示例>>Java>>正文


Java ItemWriter類代碼示例

本文整理匯總了Java中org.springframework.batch.item.ItemWriter的典型用法代碼示例。如果您正苦於以下問題:Java ItemWriter類的具體用法?Java ItemWriter怎麽用?Java ItemWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ItemWriter類屬於org.springframework.batch.item包,在下文中一共展示了ItemWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: importTicketStep

import org.springframework.batch.item.ItemWriter; //導入依賴的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

示例2: itemWriter

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean
public ItemWriter<Bracket> itemWriter(BracketRepository bracketRepository) {
	return new ItemWriter<Bracket>() {
		private int brackets = 0;

		@Override
		public void write(List<? extends Bracket> items) throws Exception {
			brackets += items.size();

			System.out.println("written " + brackets + " brackets");

			for (Bracket item : items) {
				bracketRepository.save(item);
			}
		}
	};
}
 
開發者ID:mminella,項目名稱:TaskMadness,代碼行數:18,代碼來源:JobConfiguration.java

示例3: ticketWriter

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean
public ItemWriter<Ticket> ticketWriter(final TicketRepository repository,
                                       final JmsTemplate jmsTemplate) {
    final CompositeItemWriter<Ticket> writer = new CompositeItemWriter<>();
    final RepositoryItemWriter<Ticket> repositoryItemWriter = new RepositoryItemWriter<>();
    repositoryItemWriter.setRepository(repository);
    repositoryItemWriter.setMethodName("saveAndFlush");
    final JmsItemWriter<Ticket> jmsItemWriter = new JmsItemWriter();
    jmsItemWriter.setJmsTemplate(jmsTemplate);
    final List<ItemWriter<? super Ticket>> delegates = Stream.of(
            repositoryItemWriter,
            jmsItemWriter)
            .collect(Collectors.toList());
    writer.setDelegates(delegates);
    return writer;
}
 
開發者ID:create1st,項目名稱:spring-batch,代碼行數:17,代碼來源:BatchConfiguration.java

示例4: createInventoryEntryStep

import org.springframework.batch.item.ItemWriter; //導入依賴的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: deleteProductsStep

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean
protected Step deleteProductsStep(final BlockingSphereClient sphereClient,
                                  final ItemWriter<Versioned<Product>> productDeleteWriter) {
    return stepBuilderFactory.get("deleteProductsStep")
            .<Product, Product>chunk(50)
            .reader(ItemReaderFactory.sortedByIdQueryReader(sphereClient, ProductQuery.of()))
            .writer(productDeleteWriter)
            .build();
}
 
開發者ID:commercetools,項目名稱:commercetools-sunrise-data,代碼行數:10,代碼來源:ProductDeleteJobConfiguration.java

示例6: productUnpublishWriter

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean
public ItemWriter<Versioned<Product>> productUnpublishWriter(final BlockingSphereClient sphereClient) {
    return items -> {
        final List<CompletionStage<Product>> completionStages = items.stream()
                .peek(element -> System.err.println("attempting to delete product " + element.getId()))
                .map(item -> sphereClient.execute(ProductUpdateCommand.of(item, Unpublish.of())))
                .collect(toList());
        completionStages.forEach(stage -> SphereClientUtils.blockingWait(stage, 60, TimeUnit.SECONDS));
    };
}
 
開發者ID:commercetools,項目名稱:commercetools-sunrise-data,代碼行數:11,代碼來源:ProductDeleteJobConfiguration.java

示例7: chunkStep

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean
public Step chunkStep() {
	final int chunkSize = 100;

	final ItemProcessor<String, String> processor = (item) -> {
		Thread.sleep(100);
		return item;
	};

	final ItemWriter<String> writer = (items) -> {
		Thread.sleep(1000);
	};

	return steps.get("Chunk Step") //
			.<String, String> chunk(chunkSize) //
			.reader(itemReader()) //
			.processor(processor) //
			.writer(writer) //
			.build();
}
 
開發者ID:phjardas,項目名稱:spring-batch-tools,代碼行數:21,代碼來源:TestJobConfig.java

示例8: readCsvFileIntoTableStep

import org.springframework.batch.item.ItemWriter; //導入依賴的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

示例9: readWriteStep

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean
public Step readWriteStep(ItemWriter<Product> writer) {
	return stepBuilders.get("readWrite")
	                   .<Product, Product>chunk(2)
	                   .reader(reader())
	                   .processor(processor())
	                   .writer(writer)
	                   .build();
}
 
開發者ID:debop,項目名稱:spring-batch-experiments,代碼行數:10,代碼來源:ItemProcessorConfiguration.java

示例10: productItemWriter

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean
public ItemWriter<Product> productItemWriter() {
	JdbcBatchItemWriter<Product> itemWriter = new JdbcBatchItemWriter<Product>();
	itemWriter.setDataSource(dataSource);
	itemWriter.setSql("insert into product (id, name, description, price) values(?,?,?,?)");
	itemWriter.setItemPreparedStatementSetter(new ProductPrepareStatementSetter());
	itemWriter.afterPropertiesSet();

	return itemWriter;
}
 
開發者ID:debop,項目名稱:spring-batch-experiments,代碼行數:11,代碼來源:JobStructureConfiguration.java

示例11: xmlWriter

import org.springframework.batch.item.ItemWriter; //導入依賴的package包/類
@Bean("writer2")
public ItemWriter<Permanent> xmlWriter() {
       StaxEventItemWriter<Permanent> xmlFileWriter = new StaxEventItemWriter<>();

       String exportFilePath = "./src/main/resources/emps.xml";
       xmlFileWriter.setResource(new FileSystemResource(exportFilePath));
       xmlFileWriter.setRootTagName("employees");

       Jaxb2Marshaller empMarshaller = new Jaxb2Marshaller();
       empMarshaller.setClassesToBeBound(Permanent.class);
       xmlFileWriter.setMarshaller(empMarshaller);
       System.out.println("marshalling");;
       return xmlFileWriter;
   }
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:15,代碼來源:BatchConfig.java

示例12: jobFactory

import org.springframework.batch.item.ItemWriter; //導入依賴的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.ItemWriter; //導入依賴的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: innofactorImportStep

import org.springframework.batch.item.ItemWriter; //導入依賴的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

示例15: step1

import org.springframework.batch.item.ItemWriter; //導入依賴的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


注:本文中的org.springframework.batch.item.ItemWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。