@Override public void open(ExecutionContext executionContext) { if (executionContext.containsKey(TOTAL_AMOUNT_KEY)) { this.totalPrice = (BigDecimal) executionContext.get(TOTAL_AMOUNT_KEY); } else { // // Fresh run. Disregard old state. // this.totalPrice = BigDecimal.ZERO; } }
/** * Typesafe Getter for the Integer represented by the provided key with * default value to return if key is not represented. * * @param key The key to get a value for * @param defaultInt Default to return if key is not represented * @return The <code>int</code> value if key is represented, specified * default otherwise */ public int getInt(String key, int defaultInt) { if (!containsKey(key)) { return defaultInt; } return getInt(key); }
/** * Typesafe Getter for the Double represented by the provided key with * default value to return if key is not represented. * * @param key The key to get a value for * @param defaultDouble Default to return if key is not represented * @return The <code>double</code> value if key is represented, specified * default otherwise */ public double getDouble(String key, double defaultDouble) { if (!containsKey(key)) { return defaultDouble; } return getDouble(key); }
/** * Typesafe Getter for the String represented by the provided key with * default value to return if key is not represented. * * @param key The key to get a value for * @param defaultString Default to return if key is not represented * @return The <code>String</code> value if key is represented, specified * default otherwise */ public String getString(String key, String defaultString) { if (!containsKey(key)) { return defaultString; } return getString(key); }
/** * Typesafe Getter for the Long represented by the provided key with default * value to return if key is not represented. * * @param key The key to get a value for * @param defaultLong Default to return if key is not represented * @return The <code>long</code> value if key is represented, specified * default otherwise */ public long getLong(String key, long defaultLong) { if (!containsKey(key)) { return defaultLong; } return getLong(key); }
@BeforeStep public void createOutputNameFromInput(StepExecution stepExecution) { ExecutionContext executionContext = stepExecution.getExecutionContext(); String inputName = stepExecution.getStepName().replace(":", "-"); if (executionContext.containsKey(inputKeyName)) { inputName = executionContext.getString(inputKeyName); } if (!executionContext.containsKey(outputKeyName)) { executionContext.putString(outputKeyName, path + FilenameUtils.getBaseName(inputName) + ".csv"); } }
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { if(executionContext.containsKey(CURRENT_INDEX)){ currentIndex = executionContext.getInt(CURRENT_INDEX); } else{ currentIndex = 0; } }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { this.jdbcTemplate.update("insert into TESTS(ID, NAME) values (?, 'SampleTasklet" + id + "')", id); if (jobExecution != null) { ExecutionContext jobContext = jobExecution.getExecutionContext(); if (jobContext.containsKey("key1")) { jobContextEntryFound = true; } } return RepeatStatus.FINISHED; }
public void open(ExecutionContext executionContext) throws ItemStreamException { if (executionContext.containsKey(EXPECTED)) { localState.open(executionContext.getInt(EXPECTED), executionContext.getInt(ACTUAL)); if (!waitForResults()) { throw new ItemStreamException("Timed out waiting for back log on open"); } } }
@Test public void testSetKeyName() { partitioner.setKeyName("foo"); Map<String, ExecutionContext> partition = partitioner.partition(0); assertTrue(partition.get("partition0").containsKey("foo")); }
public void update(ExecutionContext executionContext) { if (!executionContext.containsKey(UPDATE_COUNT_KEY)) { executionContext.putInt(UPDATE_COUNT_KEY, 0); } executionContext.putInt(UPDATE_COUNT_KEY , executionContext.getInt(UPDATE_COUNT_KEY) + 1 ); }
public void update(ExecutionContext executionContext) { if (!executionContext.containsKey(UPDATE_COUNT_KEY)) { executionContext.putInt(UPDATE_COUNT_KEY, 0); } executionContext.putInt(UPDATE_COUNT_KEY, executionContext.getInt(UPDATE_COUNT_KEY) + 1); }
@Test public void testContains() { context.putString("1", "testString"); assertTrue(context.containsKey("1")); assertTrue(context.containsValue("testString")); }
/** * Putting null value is equivalent to removing the entry for the given key. */ @Test public void testPutNull() { context.put("1", null); assertNull(context.get("1")); assertFalse(context.containsKey("1")); }
@Test public void testSetKeys() { listener.setKeys(new String[]{}); listener.beforeStep(stepExecution); assertFalse(stepExecution.getExecutionContext().containsKey("foo")); }
/** * Test setting writer name. */ @Test public void testSetName() throws Exception { writer.setName("test"); writer.open(executionContext); writer.write(items); writer.update(executionContext); writer.close(); assertTrue("execution context keys should be prefixed with writer name", executionContext.containsKey("test.position")); }
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException { if (!stepExecution.getJobExecution().getExecutionContext().containsKey("STOPPED")) { stepExecution.getJobExecution().getExecutionContext().put("STOPPED", true); stepExecution.setStatus(BatchStatus.STOPPED); jobRepository.update(stepExecution); } else { fail("The Job should have stopped by now"); } } }), "end0"));
@Override public void execute(StepExecution stepExecution) throws JobInterruptedException { if (!stepExecution.getJobExecution().getExecutionContext().containsKey("STOPPED")) { stepExecution.getJobExecution().getExecutionContext().put("STOPPED", true); stepExecution.setStatus(BatchStatus.STOPPED); jobRepository.update(stepExecution); } else { fail("The Job should have stopped by now"); } } }), "end0"));
/** * Count of 'records written so far' is returned as statistics. */ @Test public void testStreamContext() throws Exception { writer.open(executionContext); final int NUMBER_OF_RECORDS = 10; assertFalse(executionContext.containsKey(ClassUtils.getShortName(StaxEventItemWriter.class) + ".record.count")); for (int i = 1; i <= NUMBER_OF_RECORDS; i++) { writer.write(items); writer.update(executionContext); long writeStatistics = executionContext.getLong(ClassUtils.getShortName(StaxEventItemWriter.class) + ".record.count"); assertEquals(i, writeStatistics); } }
@Test public void testDirectlyInjectedItemStream() throws Exception { step.setStreams(new ItemStream[] { new ItemStreamSupport() { @Override public void update(ExecutionContext executionContext) { super.update(executionContext); executionContext.putString("foo", "bar"); } } }); JobExecution jobExecution = new JobExecution(jobInstance, jobParameters); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); assertEquals(false, stepExecution.getExecutionContext().containsKey("foo")); step.execute(stepExecution); assertEquals("bar", stepExecution.getExecutionContext().getString("foo")); }