BATCH-316: Continued work on the Jdbc ItemReader documentation. Mostly additions to the DrivingQuery section.
This commit is contained in:
@@ -166,7 +166,7 @@ public class DrivingQueryItemReader implements ItemReader, InitializingBean,
|
||||
if(saveState){
|
||||
Assert.notNull(executionContext, "ExecutionContext must not be null");
|
||||
if(getCurrentKey() != null){
|
||||
keyGenerator.saveState(getCurrentKey(), executionContext);
|
||||
keyGenerator.updateContext(getCurrentKey(), executionContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +43,5 @@ public interface KeyCollector {
|
||||
* @throws IllegalArgumentException if key is null.
|
||||
* @throws IllegalArgumentException if key is an incompatible type.
|
||||
*/
|
||||
void saveState(Object key, ExecutionContext executionContext);
|
||||
void updateContext(Object key, ExecutionContext executionContext);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class IbatisKeyCollector extends ExecutionContextUserSupport implements K
|
||||
* (non-Javadoc)
|
||||
* @see KeyCollector#saveState(Object, ExecutionContext)
|
||||
*/
|
||||
public void saveState(Object key, ExecutionContext executionContext) {
|
||||
public void updateContext(Object key, ExecutionContext executionContext) {
|
||||
Assert.notNull(key, "Key must not be null");
|
||||
Assert.notNull(executionContext, "ExecutionContext must be null");
|
||||
executionContext.put(getKey(RESTART_KEY), key);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class MultipleColumnJdbcKeyCollector implements KeyCollector {
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsExecutionContext(java.lang.Object)
|
||||
*/
|
||||
public void saveState(Object key, ExecutionContext executionContext) {
|
||||
public void updateContext(Object key, ExecutionContext executionContext) {
|
||||
Assert.state(keyMapper != null, "Key mapper must not be null.");
|
||||
Assert.notNull(key, "The key must not be null");
|
||||
keyMapper.mapKeys(key, executionContext);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class SingleColumnJdbcKeyCollector extends ExecutionContextUserSupport im
|
||||
* @see KeyCollector#saveState(Object)
|
||||
* @throws IllegalArgumentException if key is null.
|
||||
*/
|
||||
public void saveState(Object key, ExecutionContext executionContext) {
|
||||
public void updateContext(Object key, ExecutionContext executionContext) {
|
||||
Assert.notNull(key, "The key must not be null.");
|
||||
Assert.notNull(executionContext, "The ExecutionContext must not be null");
|
||||
executionContext.put(RESTART_KEY, key);
|
||||
|
||||
@@ -163,7 +163,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
public void saveState(Object key, ExecutionContext executionContext) {
|
||||
public void updateContext(Object key, ExecutionContext executionContext) {
|
||||
}});
|
||||
|
||||
try{
|
||||
@@ -235,7 +235,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveState(Object key, ExecutionContext executionContext) {
|
||||
public void updateContext(Object key, ExecutionContext executionContext) {
|
||||
executionContext.put(RESTART_KEY, restartKeys);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
return null;
|
||||
}
|
||||
});
|
||||
keyStrategy.saveState(key, executionContext);
|
||||
keyStrategy.updateContext(key, executionContext);
|
||||
Properties props = executionContext.getProperties();
|
||||
|
||||
assertEquals(2, props.size());
|
||||
@@ -102,7 +102,7 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
public void testGetNullKeyAsStreamContext(){
|
||||
|
||||
try{
|
||||
keyStrategy.saveState(null, null);
|
||||
keyStrategy.updateContext(null, null);
|
||||
fail();
|
||||
}catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
|
||||
@@ -40,31 +40,39 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
Long id = (Long)keys.get(i);
|
||||
assertEquals(new Long(i + 1), id);
|
||||
}
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
System.out.println(keys.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testRestoreKeys(){
|
||||
|
||||
executionContext.putString("key", "3");
|
||||
keyStrategy.updateContext(new Long(3), executionContext);
|
||||
|
||||
List keys = keyStrategy.retrieveKeys(executionContext);
|
||||
|
||||
assertEquals(2, keys.size());
|
||||
assertEquals(new Long(4), keys.get(0));
|
||||
assertEquals(new Long(5), keys.get(1));
|
||||
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
System.out.println(keys.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetKeyAsStreamContext(){
|
||||
|
||||
keyStrategy.saveState(new Long(3), executionContext);
|
||||
keyStrategy.updateContext(new Long(3), executionContext);
|
||||
|
||||
assertEquals(1, executionContext.size());
|
||||
assertEquals("3", executionContext.getString("key"));
|
||||
assertEquals(new Long(3), executionContext.get("key"));
|
||||
}
|
||||
|
||||
public void testGetNullKeyAsStreamContext(){
|
||||
|
||||
try{
|
||||
keyStrategy.saveState(null, null);
|
||||
keyStrategy.updateContext(null, null);
|
||||
fail();
|
||||
}catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
@@ -74,7 +82,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
public void testRestoreKeysFromNull(){
|
||||
|
||||
try{
|
||||
keyStrategy.saveState(null, null);
|
||||
keyStrategy.updateContext(null, null);
|
||||
}catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user