BATCH-316: Continued work on the Jdbc ItemReader documentation. Mostly additions to the DrivingQuery section.

This commit is contained in:
lucasward
2008-03-10 21:31:16 +00:00
parent f032e68efb
commit 96343035ef
8 changed files with 22 additions and 14 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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
}