本文整理汇总了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();
}
示例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);
}
}
};
}
示例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;
}
示例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();
}
示例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));
};
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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();
};
}
示例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);
}
示例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();
}
示例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();
}