org.springframework.batch.core.configuration.annotation.StepScope Java Examples
The following examples show how to use
org.springframework.batch.core.configuration.annotation.StepScope.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BatchJobConfiguration.java From patient-batch-loader with GNU General Public License v3.0 | 7 votes |
@Bean @StepScope public Function<PatientRecord, PatientEntity> processor() { return (patientRecord) -> { return new PatientEntity( patientRecord.getSourceId(), patientRecord.getFirstName(), patientRecord.getMiddleInitial(), patientRecord.getLastName(), patientRecord.getEmailAddress(), patientRecord.getPhoneNumber(), patientRecord.getStreet(), patientRecord.getCity(), patientRecord.getState(), patientRecord.getZip(), LocalDate.parse(patientRecord.getBirthDate(), DateTimeFormatter.ofPattern("M/dd/yyyy")), patientRecord.getSsn()); }; }
Example #2
Source File: BatchConfiguration.java From building-microservices with Apache License 2.0 | 6 votes |
@Bean @StepScope FlatFileItemReader<Person> flatFileItemReader(@Value("#{jobParameters[file]}") File file) { FlatFileItemReader<Person> r = new FlatFileItemReader<>(); r.setResource(new FileSystemResource(file)); r.setLineMapper(new DefaultLineMapper<Person>() { { this.setLineTokenizer(new DelimitedLineTokenizer(",") { { this.setNames(new String[]{"first", "last", "email"}); } }); this.setFieldSetMapper(new BeanWrapperFieldSetMapper<Person>() { { this.setTargetType(Person.class); } }); } }); return r; }
Example #3
Source File: EmployeeJobConfigMaster.java From batchers with Apache License 2.0 | 6 votes |
@Bean @StepScope public PartitionHandler taxCalculationPartitionHandler() { MessageChannelPartitionHandler messageChannelPartitionHandler = new MessageChannelPartitionHandler(); messageChannelPartitionHandler.setGridSize(clusterConfig.getClusterSize() - MASTER_WITHOUT_TAX_CALCULATION_STEP); messageChannelPartitionHandler.setReplyChannel(replyChannel()); messageChannelPartitionHandler.setStepName(EmployeeJobConfigSlave.TAX_CALCULATION_STEP); MessagingTemplate messagingGateway = new MessagingTemplate(); messagingGateway.setReceiveTimeout(RECEIVE_TIMEOUT); messagingGateway.setDefaultChannel(outboundRequests()); messageChannelPartitionHandler.setMessagingOperations(messagingGateway); return messageChannelPartitionHandler; }
Example #4
Source File: JobConfiguration.java From CogStack-Pipeline with Apache License 2.0 | 5 votes |
@Bean @StepScope @Qualifier("mapJdbcItemWriter") @Profile("jdbc_out_map") public ItemWriter<Document> mapJdbcItemWriter( @Qualifier("targetDataSource") DataSource jdbcDocumentTarget) { JdbcBatchItemWriter<Document> writer = new JdbcBatchItemWriter<>(); writer.setItemSqlParameterSourceProvider(new MapItemSqlParameterSourceProvider<Document>()); writer.setSql(env.getRequiredProperty("target.Sql")); writer.setDataSource(jdbcDocumentTarget); return writer; }
Example #5
Source File: BatchConfiguration.java From spring-graalvm-native with Apache License 2.0 | 5 votes |
@Bean @StepScope public ResourceAwareItemWriterItemStream<CustomerCredit> itemWriter(@Value("#{jobParameters[outputFile]}") Resource resource) { return new FlatFileItemWriterBuilder<CustomerCredit>() .name("itemWriter") .resource(resource) .delimited() .names("credit", "name") .build(); }
Example #6
Source File: BatchConfiguration.java From messaging with Apache License 2.0 | 5 votes |
@Bean @StepScope FlatFileItemReader<Contact> fileReader( @Value("file://#{jobParameters['file']}") Resource pathToFile) throws Exception { return new FlatFileItemReaderBuilder<Contact>().name("file-reader") .resource(pathToFile).targetType(Contact.class).delimited() .names("fullName,email".split(",")).build(); }
Example #7
Source File: JdbcHdfsConfiguration.java From spring-cloud-task-app-starters with Apache License 2.0 | 5 votes |
@Bean @StepScope public NamedColumnJdbcItemReader namedColumnJdbcItemReader( @Value("#{stepExecutionContext['partClause']}") String partClause) throws Exception { NamedColumnJdbcItemReaderFactory namedColumnJdbcItemReaderFactory = new NamedColumnJdbcItemReaderFactory(); namedColumnJdbcItemReaderFactory.setDataSource(this.jdbcHdfsDataSource); namedColumnJdbcItemReaderFactory.setPartitionClause(partClause); namedColumnJdbcItemReaderFactory.setTableName(this.props.getTableName()); namedColumnJdbcItemReaderFactory.setColumnNames(this.props.getColumnNames()); namedColumnJdbcItemReaderFactory.setSql(this.props.getSql()); namedColumnJdbcItemReaderFactory.setFetchSize(this.props.getCommitInterval()); namedColumnJdbcItemReaderFactory.setDelimiter(this.props.getDelimiter()); namedColumnJdbcItemReaderFactory.afterPropertiesSet(); return namedColumnJdbcItemReaderFactory.getObject(); }
Example #8
Source File: JobConfiguration.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Bean @StepScope public Tasklet workerTasklet( final @Value("#{stepExecutionContext['partitionNumber']}") Integer partitionNumber) { return new Tasklet() { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { System.out.println("This tasklet ran partition: " + partitionNumber); return RepeatStatus.FINISHED; } }; }
Example #9
Source File: ItemReaderWriterConfig.java From batchers with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "") @StepScope public JpaPagingItemReader<Employee> taxCalculatorItemReader(@Value("#{stepExecution}") StepExecution stepExecution) { JpaPagingItemReader<Employee> employeeItemReader = new JpaPagingItemReader<>(); employeeItemReader.setEntityManagerFactory(persistenceConfig.entityManagerFactory()); employeeItemReader.setQueryString(TaxCalculation.GET_UNPROCESSED_EMPLOYEES_BY_YEAR_AND_MONTH_QUERY); Map<String, Object> parameters = new HashMap<>(); parameters.put("year", stepExecution.getJobParameters().getLong("year").intValue()); parameters.put("month", stepExecution.getJobParameters().getLong("month").intValue()); parameters.put("jobExecutionId", stepExecution.getJobExecutionId()); employeeItemReader.setParameterValues(parameters); employeeItemReader.setSaveState(false); return employeeItemReader; }
Example #10
Source File: ItemReaderWriterConfig.java From batchers with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "") @StepScope public JpaPagingItemReader<Employee> taxCalculatorItemReaderSlave(@Value("#{stepExecution}") StepExecution stepExecution) { JpaPagingItemReader<Employee> employeeItemReader = new JpaPagingItemReader<>(); employeeItemReader.setEntityManagerFactory(persistenceConfig.entityManagerFactory()); employeeItemReader.setQueryString(TaxCalculation.GET_UNPROCESSED_EMPLOYEES_BY_YEAR_AND_MONTH_QUERY_SLAVE); Map<String, Object> parameters = new HashMap<>(); parameters.put("year", stepExecution.getJobParameters().getLong("year").intValue()); parameters.put("month", stepExecution.getJobParameters().getLong("month").intValue()); parameters.put("jobExecutionId", stepExecution.getJobExecutionId()); parameters.put("minId", stepExecution.getExecutionContext().getLong("minValue")); parameters.put("maxId", stepExecution.getExecutionContext().getLong("maxValue")); employeeItemReader.setParameterValues(parameters); return employeeItemReader; }
Example #11
Source File: ItemReaderWriterConfig.java From batchers with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "") @StepScope public JpaPagingItemReader<TaxCalculation> wsCallItemReader(@Value("#{jobParameters[year]}") Long year, @Value("#{jobParameters[month]}") Long month, @Value("#{stepExecution}") StepExecution stepExecution) { JpaPagingItemReader<TaxCalculation> employeeItemReader = new JpaPagingItemReader<>(); employeeItemReader.setEntityManagerFactory(persistenceConfig.entityManagerFactory()); employeeItemReader.setQueryString(TaxCalculation.FIND_BY_YEAR_AND_MONTH_QUERY); Map<String, Object> queryParams = new HashMap<>(); queryParams.put("year", year.intValue()); queryParams.put("month", month.intValue()); queryParams.put("jobExecutionId", stepExecution.getJobExecutionId()); employeeItemReader.setParameterValues(queryParams); employeeItemReader.setSaveState(false); return employeeItemReader; }
Example #12
Source File: ItemReaderWriterConfig.java From batchers with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "") @StepScope public JpaPagingItemReader<Employee> taxCalculatorItemReader(@Value("#{stepExecution}") StepExecution stepExecution) { JpaPagingItemReader<Employee> employeeItemReader = new JpaPagingItemReader<>(); employeeItemReader.setEntityManagerFactory(persistenceConfig.entityManagerFactory()); employeeItemReader.setQueryString(TaxCalculation.GET_UNPROCESSED_EMPLOYEES_BY_YEAR_AND_MONTH_QUERY_SLAVE); Map<String, Object> parameters = new HashMap<>(); parameters.put("year", stepExecution.getJobParameters().getLong("year").intValue()); parameters.put("month", stepExecution.getJobParameters().getLong("month").intValue()); parameters.put("jobExecutionId", stepExecution.getJobExecutionId()); parameters.put("minId", stepExecution.getExecutionContext().getLong("minValue")); parameters.put("maxId", stepExecution.getExecutionContext().getLong("maxValue")); employeeItemReader.setParameterValues(parameters); return employeeItemReader; }
Example #13
Source File: ItemReaderWriterConfig.java From batchers with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "") @StepScope public JpaPagingItemReader<TaxCalculation> wsCallItemReader(@Value("#{jobParameters[year]}") Long year, @Value("#{jobParameters[month]}") Long month, @Value("#{stepExecution}") StepExecution stepExecution) { JpaPagingItemReader<TaxCalculation> employeeItemReader = new JpaPagingItemReader<>(); employeeItemReader.setEntityManagerFactory(persistenceConfig.entityManagerFactory()); employeeItemReader.setQueryString(TaxCalculation.FIND_BY_YEAR_AND_MONTH_QUERY); Map<String, Object> queryParams = new HashMap<>(); queryParams.put("year", year.intValue()); queryParams.put("month", month.intValue()); queryParams.put("jobExecutionId", stepExecution.getJobExecutionId()); employeeItemReader.setParameterValues(queryParams); employeeItemReader.setSaveState(false); return employeeItemReader; }
Example #14
Source File: FlatFileToDbNoSkipJobConfiguration.java From spring-boot-starter-batch-web with Apache License 2.0 | 5 votes |
@Bean @StepScope public FlatFileItemReader<Item> flatFileItemReader(@Value("#{jobParameters[pathToFile]}") String pathToFile) { FlatFileItemReader<Item> itemReader = new FlatFileItemReader<Item>(); itemReader.setLineMapper(lineMapper()); itemReader.setResource(new FileSystemResource("src/test/resources/" + pathToFile)); return itemReader; }
Example #15
Source File: FlatFileToDbSkipReaderTransactionalJobConfiguration.java From spring-boot-starter-batch-web with Apache License 2.0 | 5 votes |
@Bean @StepScope public FlatFileItemReader<Item> flatFileItemReader(@Value("#{jobParameters[pathToFile]}") String pathToFile) { FlatFileItemReader<Item> itemReader = new FlatFileItemReader<Item>(); itemReader.setLineMapper(lineMapper()); itemReader.setResource(new FileSystemResource("src/test/resources/" + pathToFile)); return itemReader; }
Example #16
Source File: FlatFileToDbSkipProcessorNonTransactionalJobConfiguration.java From spring-boot-starter-batch-web with Apache License 2.0 | 5 votes |
@Bean @StepScope public FlatFileItemReader<Item> flatFileItemReader(@Value("#{jobParameters[pathToFile]}") String pathToFile) { FlatFileItemReader<Item> itemReader = new FlatFileItemReader<Item>(); itemReader.setLineMapper(lineMapper()); itemReader.setResource(new FileSystemResource("src/test/resources/" + pathToFile)); return itemReader; }
Example #17
Source File: FlatFileToDbSkipJobConfiguration.java From spring-boot-starter-batch-web with Apache License 2.0 | 5 votes |
@Bean @StepScope public FlatFileItemReader<Item> flatFileItemReader(@Value("#{jobParameters[pathToFile]}") String pathToFile) { FlatFileItemReader<Item> itemReader = new FlatFileItemReader<Item>(); itemReader.setLineMapper(lineMapper()); itemReader.setResource(new FileSystemResource("src/test/resources/" + pathToFile)); return itemReader; }
Example #18
Source File: SpringbatchPartitionConfig.java From tutorials with MIT License | 5 votes |
@Bean @StepScope public FlatFileItemReader<Transaction> itemReader(@Value("#{stepExecutionContext[fileName]}") String filename) throws UnexpectedInputException, ParseException { FlatFileItemReader<Transaction> reader = new FlatFileItemReader<>(); DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); String[] tokens = {"username", "userid", "transactiondate", "amount"}; tokenizer.setNames(tokens); reader.setResource(new ClassPathResource("input/partitioner/" + filename)); DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<>(); lineMapper.setLineTokenizer(tokenizer); lineMapper.setFieldSetMapper(new RecordFieldSetMapper()); reader.setLinesToSkip(1); reader.setLineMapper(lineMapper); return reader; }
Example #19
Source File: SpringBatchConfiguration.java From tutorials with MIT License | 5 votes |
@Bean @StepScope public FlatFileItemReader<BookRecord> csvItemReader(@Value("#{jobParameters['file.input']}") String input) { FlatFileItemReaderBuilder<BookRecord> builder = new FlatFileItemReaderBuilder<>(); FieldSetMapper<BookRecord> bookRecordFieldSetMapper = new BookRecordFieldSetMapper(); LOGGER.info("Configuring reader to input {}", input); // @formatter:off return builder .name("bookRecordItemReader") .resource(new FileSystemResource(input)) .delimited() .names(TOKENS) .fieldSetMapper(bookRecordFieldSetMapper) .build(); // @formatter:on }
Example #20
Source File: SpringBatchConfiguration.java From tutorials with MIT License | 5 votes |
@Bean @StepScope public JsonFileItemWriter<Book> jsonItemWriter(@Value("#{jobParameters['file.output']}") String output) throws IOException { JsonFileItemWriterBuilder<Book> builder = new JsonFileItemWriterBuilder<>(); JacksonJsonObjectMarshaller<Book> marshaller = new JacksonJsonObjectMarshaller<>(); LOGGER.info("Configuring writer to output {}", output); // @formatter:off return builder .name("bookItemWriter") .jsonObjectMarshaller(marshaller) .resource(new FileSystemResource(output)) .build(); // @formatter:on }
Example #21
Source File: JobConfiguration.java From CogStack-Pipeline with Apache License 2.0 | 5 votes |
@Bean @StepScope @Qualifier("documentItemReader") @Profile("jdbc_in") public ItemReader<Document> documentItemReader( @Value("#{stepExecutionContext[minValue]}") String minValue, @Value("#{stepExecutionContext[maxValue]}") String maxValue, @Value("#{stepExecutionContext[min_time_stamp]}") String minTimeStamp, @Value("#{stepExecutionContext[max_time_stamp]}") String maxTimeStamp, @Qualifier("documentRowMapper")RowMapper<Document> documentRowmapper, @Qualifier("sourceDataSource") DataSource jdbcDocumentSource) throws Exception { JdbcPagingItemReader<Document> reader = new JdbcPagingItemReader<>(); reader.setDataSource(jdbcDocumentSource); // read and set obligatory properties SqlPagingQueryProviderFactoryBean qp = new SqlPagingQueryProviderFactoryBean(); qp.setSelectClause(env.getRequiredProperty("source.selectClause")); qp.setFromClause(env.getRequiredProperty("source.fromClause")); qp.setSortKey(env.getRequiredProperty("source.sortKey")); qp.setWhereClause(stepPartitioner.getPartitioningLogic(minValue,maxValue, minTimeStamp,maxTimeStamp)); qp.setDataSource(jdbcDocumentSource); // set optional properties if (env.containsProperty("source.pageSize")) { reader.setPageSize(Integer.parseInt(env.getProperty("source.pageSize"))); } else { // it's a good idea to batch size and page size (commit interval) set to the same value LOG.info("property: 'source.pageSize' not specified -> setting DB reader page size to batch step chunk size: {}", chunkSize); reader.setPageSize(chunkSize); } reader.setQueryProvider(qp.getObject()); reader.setRowMapper(documentRowmapper); return reader; }
Example #22
Source File: PersonJobConfig.java From spring-batch-rest with Apache License 2.0 | 5 votes |
@Bean @StepScope ItemProcessor personNameCaseChange(@Value("#{jobParameters['upperCase']}") Boolean upperCaseParam) { boolean upperCase = upperCaseParam == null ? false : upperCaseParam; log.info("personNameCaseChange(upperCase={})", upperCase); return new FunctionItemProcessor<Person, Person>(p -> new Person( upperCase ? p.firstName.toUpperCase() : p.firstName.toLowerCase(), upperCase ? p.lastName.toUpperCase() : p.lastName.toLowerCase())); }
Example #23
Source File: PersonJobConfig.java From spring-batch-rest with Apache License 2.0 | 5 votes |
@Bean @StepScope ItemProcessor personProcessor( @Qualifier("personNameCaseChange") ItemProcessor personNameCaseChange, @Value("#{jobParameters['" + LAST_NAME_PREFIX + "']}") String lastNamePrefix) { CompositeItemProcessor p = new CompositeItemProcessor(); p.setDelegates(newArrayList( personNameFilter(Optional.ofNullable(lastNamePrefix).orElseGet(() -> environment.getProperty(LAST_NAME_PREFIX))), personNameCaseChange)); return p; }
Example #24
Source File: PersonJobConfig.java From spring-batch-rest with Apache License 2.0 | 5 votes |
@Bean @StepScope ItemProcessor personNameCaseChange(@Value("#{jobParameters['upperCase']}") Boolean upperCaseParam) { boolean upperCase = upperCaseParam == null ? false : upperCaseParam; log.info("personNameCaseChange(upperCase={})", upperCase); return new FunctionItemProcessor<Person, Person>(p -> new Person( upperCase ? p.firstName.toUpperCase() : p.firstName.toLowerCase(), upperCase ? p.lastName.toUpperCase() : p.lastName.toLowerCase())); }
Example #25
Source File: PersonJobConfig.java From spring-batch-rest with Apache License 2.0 | 5 votes |
@Bean @StepScope ItemProcessor personProcessor( @Qualifier("personNameCaseChange") ItemProcessor personNameCaseChange, @Value("#{jobParameters['" + LAST_NAME_PREFIX + "']}") String lastNamePrefix) { CompositeItemProcessor p = new CompositeItemProcessor(); p.setDelegates(newArrayList( personNameFilter(Optional.ofNullable(lastNamePrefix).orElseGet(() -> environment.getProperty(LAST_NAME_PREFIX))), personNameCaseChange)); return p; }
Example #26
Source File: BatchConfiguration.java From spring-graalvm-native with Apache License 2.0 | 5 votes |
@Bean @StepScope public ItemStreamReader<CustomerCredit> itemReader() { return new FlatFileItemReaderBuilder<CustomerCredit>() .name("itemReader") .resource(new ClassPathResource("/customer.csv")) .delimited() .names("name", "credit") .targetType(CustomerCredit.class) .build(); }
Example #27
Source File: BatchJobConfiguration.java From patient-batch-loader with GNU General Public License v3.0 | 5 votes |
@Bean @StepScope public FlatFileItemReader<PatientRecord> reader( @Value("#{jobParameters['" + Constants.JOB_PARAM_FILE_NAME + "']}")String fileName) { return new FlatFileItemReaderBuilder<PatientRecord>() .name(Constants.ITEM_READER_NAME) .resource( new PathResource( Paths.get(applicationProperties.getBatch().getInputPath() + File.separator + fileName))) .linesToSkip(1) .lineMapper(lineMapper()) .build(); }
Example #28
Source File: JobConfiguration.java From CogStack-Pipeline with Apache License 2.0 | 5 votes |
@Bean @StepScope @Qualifier("simpleJdbcItemWriter") @Profile("jdbc_out") public ItemWriter<Document> simpleJdbcItemWriter( @Qualifier("targetDataSource") DataSource jdbcDocumentTarget) { JdbcBatchItemWriter<Document> writer = new JdbcBatchItemWriter<>(); writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>()); writer.setSql(env.getRequiredProperty("target.Sql")); writer.setDataSource(jdbcDocumentTarget); return writer; }
Example #29
Source File: JobConfiguration.java From CogStack-Pipeline with Apache License 2.0 | 5 votes |
@StepScope @Bean public LoggerHelper loggerHelper(){ LoggerHelper lh = new LoggerHelper(); lh.setContextID(env.getProperty("job.jobName")); return lh; }
Example #30
Source File: JobConfig.java From spring4-sandbox with Apache License 2.0 | 4 votes |
@Bean @StepScope public ConferenceItemWriter itemWriter() { return new ConferenceItemWriter(dataSource); }