本文整理了Java中org.springframework.batch.item.ExecutionContext.containsKey()
方法的一些代码示例,展示了ExecutionContext.containsKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExecutionContext.containsKey()
方法的具体详情如下:
包路径:org.springframework.batch.item.ExecutionContext
类名称:ExecutionContext
方法名:containsKey
[英]Indicates whether or not a key is represented in this context.
[中]指示是否在此上下文中表示键。
代码示例来源:origin: spring-projects/spring-batch
@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;
}
}
代码示例来源:origin: spring-projects/spring-batch
/**
* 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);
}
代码示例来源:origin: spring-projects/spring-batch
/**
* 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);
}
代码示例来源:origin: spring-projects/spring-batch
/**
* 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);
}
代码示例来源:origin: spring-projects/spring-batch
/**
* 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);
}
代码示例来源:origin: spring-projects/spring-batch
@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");
}
}
代码示例来源:origin: spring-projects/spring-batch
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
if(executionContext.containsKey(CURRENT_INDEX)){
currentIndex = executionContext.getInt(CURRENT_INDEX);
}
else{
currentIndex = 0;
}
}
代码示例来源:origin: spring-projects/spring-batch
@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;
}
代码示例来源:origin: spring-projects/spring-batch
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");
}
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testSetKeyName() {
partitioner.setKeyName("foo");
Map<String, ExecutionContext> partition = partitioner.partition(0);
assertTrue(partition.get("partition0").containsKey("foo"));
}
代码示例来源:origin: spring-projects/spring-batch
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
);
}
代码示例来源:origin: spring-projects/spring-batch
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);
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testContains() {
context.putString("1", "testString");
assertTrue(context.containsKey("1"));
assertTrue(context.containsValue("testString"));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* 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"));
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testSetKeys() {
listener.setKeys(new String[]{});
listener.beforeStep(stepExecution);
assertFalse(stepExecution.getExecutionContext().containsKey("foo"));
}
代码示例来源:origin: spring-projects/spring-batch
/**
* 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"));
}
代码示例来源:origin: spring-projects/spring-batch
@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"));
代码示例来源:origin: spring-projects/spring-batch
@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"));
代码示例来源:origin: spring-projects/spring-batch
/**
* 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);
}
}
代码示例来源:origin: spring-projects/spring-batch
@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"));
}
内容来源于网络,如有侵权,请联系作者删除!