List of usage examples for org.springframework.batch.core.step.tasklet TaskletStep setTransactionManager
public void setTransactionManager(PlatformTransactionManager transactionManager)
From source file:org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean.java
@SuppressWarnings("serial") private void configureTaskletStep(TaskletStep ts) { configureAbstractStep(ts);// w w w . j a v a 2 s .c o m if (listeners != null) { List<ChunkListener> newListeners = new ArrayList<ChunkListener>(); for (StepListener listener : listeners) { if (listener instanceof ChunkListener) { newListeners.add((ChunkListener) listener); } } ts.setChunkListeners(newListeners.toArray(new ChunkListener[0])); } if (tasklet != null) { ts.setTasklet(tasklet); } if (taskExecutor != null) { TaskExecutorRepeatTemplate repeatTemplate = new TaskExecutorRepeatTemplate(); repeatTemplate.setTaskExecutor(taskExecutor); if (throttleLimit != null) { repeatTemplate.setThrottleLimit(throttleLimit); } ts.setStepOperations(repeatTemplate); } if (transactionManager != null) { ts.setTransactionManager(transactionManager); } if (transactionTimeout != null || propagation != null || isolation != null || noRollbackExceptionClasses != null) { DefaultTransactionAttribute attribute = new DefaultTransactionAttribute(); if (propagation != null) { attribute.setPropagationBehavior(propagation.value()); } if (isolation != null) { attribute.setIsolationLevel(isolation.value()); } if (transactionTimeout != null) { attribute.setTimeout(transactionTimeout); } Collection<Class<? extends Throwable>> exceptions = noRollbackExceptionClasses == null ? new HashSet<Class<? extends Throwable>>() : noRollbackExceptionClasses; final BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(exceptions, false); ts.setTransactionAttribute(new DefaultTransactionAttribute(attribute) { @Override public boolean rollbackOn(Throwable ex) { return classifier.classify(ex); } }); } }
From source file:org.springframework.batch.core.step.item.SimpleStepFactoryBean.java
/** * @param step//ww w. j a va 2 s . co m * */ protected void applyConfiguration(TaskletStep step) { Assert.state(getItemReader() != null, "ItemReader must be provided"); Assert.state(getItemWriter() != null || getItemProcessor() != null, "ItemWriter or ItemProcessor must be provided"); Assert.state(transactionManager != null, "TransactionManager must be provided"); step.setTransactionManager(transactionManager); step.setTransactionAttribute(getTransactionAttribute()); step.setJobRepository(jobRepository); step.setStartLimit(startLimit); step.setAllowStartIfComplete(allowStartIfComplete); registerStreams(step, streams); if (chunkOperations == null) { RepeatTemplate repeatTemplate = new RepeatTemplate(); repeatTemplate.setCompletionPolicy(getChunkCompletionPolicy()); chunkOperations = repeatTemplate; } if (stepOperations == null) { stepOperations = new RepeatTemplate(); if (taskExecutor != null) { TaskExecutorRepeatTemplate repeatTemplate = new TaskExecutorRepeatTemplate(); repeatTemplate.setTaskExecutor(taskExecutor); repeatTemplate.setThrottleLimit(throttleLimit); stepOperations = repeatTemplate; } ((RepeatTemplate) stepOperations).setExceptionHandler(exceptionHandler); } step.setStepOperations(stepOperations); SimpleChunkProvider<T> chunkProvider = configureChunkProvider(); SimpleChunkProcessor<T, S> chunkProcessor = configureChunkProcessor(); registerItemListeners(chunkProvider, chunkProcessor); registerStepListeners(step, chunkOperations); registerStreams(step, itemReader, itemProcessor, itemWriter); ChunkOrientedTasklet<T> tasklet = new ChunkOrientedTasklet<T>(chunkProvider, chunkProcessor); tasklet.setBuffering(!isReaderTransactionalQueue()); step.setTasklet(tasklet); }
From source file:org.springframework.data.hadoop.admin.util.HadoopWorkflowUtils.java
/** * create and register Spring Batch job//from www.j a va 2 s.com * * @param context root application context * @param artifacts workflow artifacts which include workflow descriptor and class loader information. * @throws Exception */ public static void createAndRegisterSpringBatchJob(ApplicationContext context, final WorkflowArtifacts artifacts) throws SpringHadoopAdminWorkflowException { if (context == null) { logger.warn("root applicaton context is null"); throw new SpringHadoopAdminWorkflowException("root applicaton context is null"); } String workflowDescriptor = getWorkflowDescriptor(artifacts); logger.info("create spring batch job:" + workflowDescriptor + ", classloader:" + artifacts.getWorkflowClassLoader()); final FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(); ctx.setClassLoader(artifacts.getWorkflowClassLoader()); ctx.setConfigLocation(HadoopWorkflowUtils.fileURLPrefix + workflowDescriptor); try { SimpleJob job = new SimpleJob(generateSpringBatchJobName(artifacts)); TaskletStep step = new TaskletStep(springHadoopTaskName); SimpleSpringHadoopTasklet tasklet = new SimpleSpringHadoopTasklet(); tasklet.setContext(ctx); step.setTasklet(tasklet); JobRepository jobRepository = context.getBean(JobRepository.class); DataSourceTransactionManager transactionManager = context.getBean("transactionManager", DataSourceTransactionManager.class); step.setTransactionManager(transactionManager); step.setJobRepository(jobRepository); step.afterPropertiesSet(); job.addStep(step); JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class); job.setJobRepository(jobRepository); job.afterPropertiesSet(); JobFactory jobFactory = new ReferenceJobFactory(job); jobRegistry.register(jobFactory); } catch (Exception e) { logger.warn("create and register Spring Batch Job failed"); throw new SpringHadoopAdminWorkflowException("create and register Spring Batch Job failed", e); } }