Add method in ExecutionContext to expose the internal map as read-only
Resolves #4004
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
d9bf57e572
commit
06e6bdbc98
@@ -82,11 +82,7 @@ public class JobContext extends SynchronizedAttributeAccessor {
|
||||
* @return a map containing the items from the job {@link ExecutionContext}
|
||||
*/
|
||||
public Map<String, Object> getJobExecutionContext() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
for (Entry<String, Object> entry : jobExecution.getExecutionContext().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return Collections.unmodifiableMap(result);
|
||||
return jobExecution.getExecutionContext().toMap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -111,22 +111,14 @@ public class StepContext extends SynchronizedAttributeAccessor {
|
||||
* @return a map containing the items from the step {@link ExecutionContext}
|
||||
*/
|
||||
public Map<String, Object> getStepExecutionContext() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
for (Entry<String, Object> entry : stepExecution.getExecutionContext().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return Collections.unmodifiableMap(result);
|
||||
return stepExecution.getExecutionContext().toMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map containing the items from the job {@link ExecutionContext}
|
||||
*/
|
||||
public Map<String, Object> getJobExecutionContext() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
for (Entry<String, Object> entry : stepExecution.getJobExecution().getExecutionContext().entrySet()) {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return Collections.unmodifiableMap(result);
|
||||
return stepExecution.getJobExecution().getExecutionContext().toMap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.batch.item;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
@@ -69,9 +70,7 @@ public class ExecutionContext implements Serializable {
|
||||
if (executionContext == null) {
|
||||
return;
|
||||
}
|
||||
for (Entry<String, Object> entry : executionContext.entrySet()) {
|
||||
this.map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
this.map.putAll(executionContext.toMap());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,11 +292,20 @@ public class ExecutionContext implements Serializable {
|
||||
|
||||
/**
|
||||
* Returns the entry set containing the contents of this context.
|
||||
* @return A set representing the contents of the context
|
||||
* @return An unmodifiable set representing the contents of the context
|
||||
* @see java.util.Map#entrySet()
|
||||
*/
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
return this.map.entrySet();
|
||||
return Collections.unmodifiableSet(this.map.entrySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal map as read-only.
|
||||
* @return An unmodifiable map containing all contents.
|
||||
* @see java.util.Map
|
||||
*/
|
||||
public Map<String, Object> toMap() {
|
||||
return Collections.unmodifiableMap(this.map);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user