diff --git a/infrastructure/src/main/java/org/springframework/batch/io/orm/hibernate/HibernateInputSource.java b/infrastructure/src/main/java/org/springframework/batch/io/cursor/HibernateInputSource.java similarity index 95% rename from infrastructure/src/main/java/org/springframework/batch/io/orm/hibernate/HibernateInputSource.java rename to infrastructure/src/main/java/org/springframework/batch/io/cursor/HibernateInputSource.java index 879cd6cca..a31ee9bec 100644 --- a/infrastructure/src/main/java/org/springframework/batch/io/orm/hibernate/HibernateInputSource.java +++ b/infrastructure/src/main/java/org/springframework/batch/io/cursor/HibernateInputSource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.io.orm.hibernate; +package org.springframework.batch.io.cursor; import java.util.Properties; diff --git a/infrastructure/src/main/java/org/springframework/batch/io/orm/ibatis/IbatisInputSource.java b/infrastructure/src/main/java/org/springframework/batch/io/driving/IbatisInputSource.java similarity index 61% rename from infrastructure/src/main/java/org/springframework/batch/io/orm/ibatis/IbatisInputSource.java rename to infrastructure/src/main/java/org/springframework/batch/io/driving/IbatisInputSource.java index 2a372ca9b..d6e4c120f 100644 --- a/infrastructure/src/main/java/org/springframework/batch/io/orm/ibatis/IbatisInputSource.java +++ b/infrastructure/src/main/java/org/springframework/batch/io/driving/IbatisInputSource.java @@ -13,19 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.io.orm.ibatis; +package org.springframework.batch.io.driving; + +import org.springframework.batch.io.driving.support.IbatisKeyGenerator; +import org.springframework.orm.ibatis.SqlMapClientTemplate; /** - * Extension of {@link IbatisDrivingQueryInputSource} that maps keys to + * Extension of {@link DrivingQueryInputSource} that maps keys to * objects. An iBatis query id must be set to map and return each 'detail record'. * * @author Lucas Ward - * @see IbatisDrivingQueryInputSource + * @see IbatisKeyGenerator */ -public class IbatisInputSource extends IbatisDrivingQueryInputSource { +public class IbatisInputSource extends DrivingQueryInputSource { private String detailsQueryId; + private SqlMapClientTemplate sqlMapClientTemplate; /** * Overriden read that uses the returned key as arguments to the details query. @@ -33,7 +37,7 @@ public class IbatisInputSource extends IbatisDrivingQueryInputSource { * @see org.springframework.batch.io.driving.DrivingQueryInputSource#read() */ public Object read() { - return getSqlMapClientTemplate().queryForObject(detailsQueryId, super.read()); + return sqlMapClientTemplate.queryForObject(detailsQueryId, super.read()); } /** @@ -44,4 +48,14 @@ public class IbatisInputSource extends IbatisDrivingQueryInputSource { public void setDetailsQueryId(String detailsQueryId) { this.detailsQueryId = detailsQueryId; } + + /** + * Set the {@link SqlMapClientTemplate} to use for this input source. + * + * @param sqlMapClientTemplate + */ + public void setSqlMapClientTemplate( + SqlMapClientTemplate sqlMapClientTemplate) { + this.sqlMapClientTemplate = sqlMapClientTemplate; + } } diff --git a/infrastructure/src/main/java/org/springframework/batch/io/orm/ibatis/IbatisDrivingQueryInputSource.java b/infrastructure/src/main/java/org/springframework/batch/io/driving/support/IbatisKeyGenerator.java similarity index 83% rename from infrastructure/src/main/java/org/springframework/batch/io/orm/ibatis/IbatisDrivingQueryInputSource.java rename to infrastructure/src/main/java/org/springframework/batch/io/driving/support/IbatisKeyGenerator.java index 15c04d1f4..ba10a24d8 100644 --- a/infrastructure/src/main/java/org/springframework/batch/io/orm/ibatis/IbatisDrivingQueryInputSource.java +++ b/infrastructure/src/main/java/org/springframework/batch/io/driving/support/IbatisKeyGenerator.java @@ -1,11 +1,11 @@ -package org.springframework.batch.io.orm.ibatis; +package org.springframework.batch.io.driving.support; import java.util.List; import java.util.Properties; import org.springframework.batch.io.InputSource; import org.springframework.batch.io.driving.DrivingQueryInputSource; -import org.springframework.batch.io.driving.support.SingleColumnJdbcKeyGenerator; +import org.springframework.batch.io.driving.KeyGenerator; import org.springframework.batch.restart.GenericRestartData; import org.springframework.batch.restart.RestartData; import org.springframework.orm.ibatis.SqlMapClientTemplate; @@ -14,16 +14,15 @@ import org.springframework.util.Assert; import com.ibatis.sqlmap.client.SqlMapClient; /** - * Driving query {@link InputSource} based on iBATIS ORM framework. It is functionally similar to + * {@link KeyGenerator} based on iBATIS ORM framework. It is functionally similar to * {@link SingleColumnJdbcKeyGenerator} but does not make assumptions about the primary key * structure. * - * * @author Robert Kasanicky * @author Lucas Ward * @see DrivingQueryInputSource */ -public class IbatisDrivingQueryInputSource extends DrivingQueryInputSource { +public class IbatisKeyGenerator implements KeyGenerator { public static final String RESTART_KEY = "IbatisDrivingQueryInputSource.keyIndex"; @@ -38,7 +37,7 @@ public class IbatisDrivingQueryInputSource extends DrivingQueryInputSource { * * @see org.springframework.batch.io.support.AbstractDrivingQueryInputSource#retrieveKeys() */ - protected List retrieveKeys() { + public List retrieveKeys() { return sqlMapClientTemplate.queryForList(drivingQuery); } @@ -46,9 +45,9 @@ public class IbatisDrivingQueryInputSource extends DrivingQueryInputSource { * * @see org.springframework.batch.restart.Restartable#getRestartData() */ - public RestartData getRestartData() { + public RestartData getKeyAsRestartData(Object key) { Properties props = new Properties(); - props.setProperty(RESTART_KEY, getCurrentKey().toString()); + props.setProperty(RESTART_KEY, key.toString()); return new GenericRestartData(props); } diff --git a/infrastructure/src/test/java/org/springframework/batch/io/orm/hibernate/HibernateInputSourceIntegrationTests.java b/infrastructure/src/test/java/org/springframework/batch/io/cursor/HibernateInputSourceIntegrationTests.java similarity index 88% rename from infrastructure/src/test/java/org/springframework/batch/io/orm/hibernate/HibernateInputSourceIntegrationTests.java rename to infrastructure/src/test/java/org/springframework/batch/io/cursor/HibernateInputSourceIntegrationTests.java index 16c4e5a2c..83331c505 100644 --- a/infrastructure/src/test/java/org/springframework/batch/io/orm/hibernate/HibernateInputSourceIntegrationTests.java +++ b/infrastructure/src/test/java/org/springframework/batch/io/cursor/HibernateInputSourceIntegrationTests.java @@ -1,8 +1,8 @@ -package org.springframework.batch.io.orm.hibernate; +package org.springframework.batch.io.cursor; import org.hibernate.SessionFactory; import org.springframework.batch.io.InputSource; -import org.springframework.batch.io.orm.hibernate.HibernateInputSource; +import org.springframework.batch.io.cursor.HibernateInputSource; import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; diff --git a/infrastructure/src/test/java/org/springframework/batch/io/orm/ibatis/IbatisInputSourceIntegrationTests.java b/infrastructure/src/test/java/org/springframework/batch/io/driving/IbatisInputSourceIntegrationTests.java similarity index 59% rename from infrastructure/src/test/java/org/springframework/batch/io/orm/ibatis/IbatisInputSourceIntegrationTests.java rename to infrastructure/src/test/java/org/springframework/batch/io/driving/IbatisInputSourceIntegrationTests.java index c72041804..8efec8e3e 100644 --- a/infrastructure/src/test/java/org/springframework/batch/io/orm/ibatis/IbatisInputSourceIntegrationTests.java +++ b/infrastructure/src/test/java/org/springframework/batch/io/driving/IbatisInputSourceIntegrationTests.java @@ -1,10 +1,12 @@ -package org.springframework.batch.io.orm.ibatis; +package org.springframework.batch.io.driving; import org.springframework.batch.io.InputSource; -import org.springframework.batch.io.orm.ibatis.IbatisDrivingQueryInputSource; +import org.springframework.batch.io.driving.IbatisInputSource; +import org.springframework.batch.io.driving.support.IbatisKeyGenerator; import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests; import org.springframework.core.io.ClassPathResource; import org.springframework.orm.ibatis.SqlMapClientFactoryBean; +import org.springframework.orm.ibatis.SqlMapClientTemplate; import com.ibatis.sqlmap.client.SqlMapClient; @@ -22,12 +24,16 @@ public class IbatisInputSourceIntegrationTests extends AbstractDataSourceInputSo factory.setDataSource(super.getJdbcTemplate().getDataSource()); factory.afterPropertiesSet(); SqlMapClient sqlMapClient = (SqlMapClient) factory.getObject(); + SqlMapClientTemplate sqlMapClientTemplate = new SqlMapClientTemplate(sqlMapClient); IbatisInputSource inputSource = new IbatisInputSource(); - inputSource.setDrivingQueryId("getAllFooIds"); + IbatisKeyGenerator keyGenerator = new IbatisKeyGenerator(); + keyGenerator.setDrivingQueryId("getAllFooIds"); inputSource.setDetailsQueryId("getFooById"); - inputSource.setRestartQueryId("getAllFooIdsRestart"); - inputSource.setSqlMapClient(sqlMapClient); + keyGenerator.setRestartQueryId("getAllFooIdsRestart"); + keyGenerator.setSqlMapClient(sqlMapClient); + inputSource.setSqlMapClientTemplate(sqlMapClientTemplate); + inputSource.setKeyGenerator(keyGenerator); return inputSource; } diff --git a/samples/src/main/resources/jobs/hibernateJob.xml b/samples/src/main/resources/jobs/hibernateJob.xml index 7633d3e3b..5ad0b3a5e 100644 --- a/samples/src/main/resources/jobs/hibernateJob.xml +++ b/samples/src/main/resources/jobs/hibernateJob.xml @@ -43,7 +43,7 @@ - diff --git a/samples/src/main/resources/jobs/ibatisJob.xml b/samples/src/main/resources/jobs/ibatisJob.xml index 712aa8905..4c3a88239 100644 --- a/samples/src/main/resources/jobs/ibatisJob.xml +++ b/samples/src/main/resources/jobs/ibatisJob.xml @@ -45,7 +45,7 @@ -