org.springframework.batch.item.ExecutionContext.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.springframework.batch.item.ExecutionContext.<init>()方法的一些代码示例,展示了ExecutionContext.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExecutionContext.<init>()方法的具体详情如下:
包路径:org.springframework.batch.item.ExecutionContext
类名称:ExecutionContext
方法名:<init>

ExecutionContext.<init>介绍

[英]Default constructor. Initializes a new execution context with an empty internal map.
[中]默认构造函数。使用空的内部映射初始化新的执行上下文。

代码示例

代码示例来源:origin: spring-projects/spring-batch

/**
 * @param jobRepository a {@link org.springframework.batch.core.repository.JobRepository}
 */
public SimpleStepHandler(JobRepository jobRepository) {
  this(jobRepository, new ExecutionContext());
}

代码示例来源:origin: spring-projects/spring-batch

@Override
public Map<String, ExecutionContext> partition(int gridSize) {
  Map<String, ExecutionContext> map = new HashMap<>(gridSize);
  for (int i = 0; i < gridSize; i++) {
    map.put(PARTITION_KEY + i, new ExecutionContext());
  }
  return map;
}

代码示例来源:origin: spring-projects/spring-batch

@Override
public void writeCredit(CustomerCredit customerCredit) throws Exception {
  if (!opened) {
    open(new ExecutionContext());
  }
  String line = "" + customerCredit.getName() + separator
      + customerCredit.getCredit();
  itemWriter.write(Collections.singletonList(line));
}

代码示例来源:origin: spring-projects/spring-batch

@Before
public void setUp() throws Exception {
  File directory = new File("build/data");
  directory.mkdirs();
  resource = new FileSystemResource(File.createTempFile("StaxEventWriterOutputSourceTests", ".xml", directory));
  writer = createItemWriter();
  executionContext = new ExecutionContext();
  jaxbMarshaller = new Jaxb2Marshaller();
  jaxbMarshaller.setClassesToBeBound(JAXBItem.class);
}

代码示例来源:origin: spring-projects/spring-batch

@Override
  public RepeatStatus doInIteration(RepeatContext context) throws Exception {
    assertNotSame(threadName, Thread.currentThread().getName());
    threadNames.add(Thread.currentThread().getName());
    Thread.sleep(100);
    TradeItemReader provider = new TradeItemReader(resource);
    provider.open(new ExecutionContext());
    while (provider.read() != null)
      ;
    return super.doInIteration(context);
  }
};

代码示例来源:origin: spring-projects/spring-batch

@Override
  protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception {
    MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested;
    multiReader.close();
    multiReader.setResources(new Resource[] { new ByteArrayResource("".getBytes()) });
    multiReader.open(new ExecutionContext());
  }
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testSimpleStepExecutionProviderJobRepositoryStepPartitioner() throws Exception {
  final Map<String, ExecutionContext> map = Collections.singletonMap("foo", new ExecutionContext());
  SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, true, step.getName(),
      new Partitioner() {
    @Override
    public Map<String, ExecutionContext> partition(int gridSize) {
      return map;
    }
  });
  assertEquals(1, splitter.split(stepExecution, 2).size());
}

代码示例来源:origin: spring-projects/spring-batch

@Override
protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception {
  MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested;
  multiReader.close();
  multiReader.setResources(new Resource[] { new ByteArrayResource("<foos />"
      .getBytes()) });
  multiReader.open(new ExecutionContext());
}

代码示例来源:origin: spring-projects/spring-batch

@Transactional
@Test
public void testStoreInteger() {
  ExecutionContext ec = new ExecutionContext();
  ec.put("intValue", new Integer(343232));
  stepExecution.setExecutionContext(ec);
  contextDao.saveExecutionContext(stepExecution);
  ExecutionContext restoredEc = contextDao.getExecutionContext(stepExecution);
  assertEquals(ec, restoredEc);
}

代码示例来源:origin: spring-projects/spring-batch

@Transactional
@Test
public void testSaveAndFindEmptyStepContext() {
  ExecutionContext ctx = new ExecutionContext();
  stepExecution.setExecutionContext(ctx);
  contextDao.saveExecutionContext(stepExecution);
  ExecutionContext retrieved = contextDao.getExecutionContext(stepExecution);
  assertEquals(ctx, retrieved);
}

代码示例来源:origin: spring-projects/spring-batch

@Before
public void onSetUp()throws Exception{
  itemReader = createItemReader();
  getAsInitializingBean(itemReader).afterPropertiesSet();
  executionContext = new ExecutionContext();
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testJob() throws Exception {
  stream.open(new ExecutionContext());
  assertEquals("foo", reader.read());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testUpdateWithMax() throws Exception {
  ExecutionContext context = new ExecutionContext();
  context.putInt("foo.read.count.max", 1);
  reader.open(context);
  reader.update(context);
  assertEquals(2, context.size());
}

代码示例来源:origin: spring-projects/spring-batch

private void start(String foo) {
  StepSynchronizationManager.close();
  stepExecution = new StepExecution("foo", new JobExecution(11L), 123L);
  ExecutionContext executionContext = new ExecutionContext();
  executionContext.put("foo", foo);
  executionContext.put("type", TestCollaborator.class.getName());
  stepExecution.setExecutionContext(executionContext);
  StepSynchronizationManager.register(stepExecution);
  beanCount = beanFactory.getBeanDefinitionCount();
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testInvalidResourceFormat() {
  this.expectedException.expect(ItemStreamException.class);
  this.expectedException.expectMessage("Failed to initialize the reader");
  this.expectedException.expectCause(instanceOf(IllegalStateException.class));
  JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>()
      .jsonObjectReader(getJsonObjectReader())
      .resource(new ByteArrayResource("{}, {}".getBytes()))
      .name("tradeJsonItemReader")
      .build();
  itemReader.open(new ExecutionContext());
}

代码示例来源:origin: spring-projects/spring-batch

private JpaPagingItemReader<Foo> getItemReader() throws Exception {
  String jpqlQuery = "select f from Foo f";
  JpaPagingItemReader<Foo> reader = new JpaPagingItemReader<>();
  reader.setQueryString(jpqlQuery);
  reader.setEntityManagerFactory(entityManagerFactory);
  reader.setPageSize(PAGE_SIZE);
  reader.afterPropertiesSet();
  reader.setSaveState(false);
  reader.open(new ExecutionContext());
  return reader;
}

代码示例来源:origin: spring-projects/spring-batch

@Transactional @Test
public void testRead() throws Exception{
  itemReader.open(new ExecutionContext());
  Foo foo = itemReader.read();
  assertEquals(2, foo.getId());
  foo = itemReader.read();
  assertEquals(3, foo.getId());
  assertNull(itemReader.read());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testSaveStateDisabled() throws Exception {
  this.ldifReader = new LdifReaderBuilder().saveState(false).resource(context.getResource("classpath:/test.ldif"))
      .build();
  ExecutionContext executionContext = new ExecutionContext();
  firstRead(executionContext);
  this.ldifReader.update(executionContext);
  assertEquals("ExecutionContext should have been empty", 0, executionContext.size());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testSaveStateDisabled() throws Exception {
  this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>()
      .saveState(false)
      .recordMapper(new TestMapper())
      .resource(context.getResource("classpath:/test.ldif"))
      .build();
  ExecutionContext executionContext = new ExecutionContext();
  firstRead(executionContext);
  this.mappingLdifReader.update(executionContext);
  assertEquals("ExecutionContext should have been empty", 0, executionContext.size());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testExecutionContext() throws Exception {
  StepExecution stepExecution = new StepExecution("foo", new JobExecution(11L), 1L);
  ExecutionContext executionContext = new ExecutionContext();
  executionContext.put("name", "spam");
  stepExecution.setExecutionContext(executionContext);
  proxied.execute(stepExecution);
  assertTrue(TestStep.getContext().attributeNames().length > 0);
  String collaborator = (String) TestStep.getContext().getAttribute("collaborator");
  assertNotNull(collaborator);
  assertEquals("bar", collaborator);
}

相关文章