BATCH 186: modified the iBatis input source to now use the KeyGenerator, and moved into io.driving. io.orm package was romoved.

This commit is contained in:
lucasward
2007-11-01 12:19:19 +00:00
parent c4dc54ba6b
commit bd6ebc3f6f
7 changed files with 42 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -43,7 +43,7 @@
</property>
</bean>
<bean id="hibernateInputSource" class="org.springframework.batch.io.orm.hibernate.HibernateInputSource"
<bean id="hibernateInputSource" class="org.springframework.batch.io.cursor.HibernateInputSource"
scope="step" >
<aop:scoped-proxy />
<property name="queryString" value="from CustomerCredit" />

View File

@@ -45,7 +45,7 @@
</property>
</bean>
<bean id="ibatisInputSource" class="org.springframework.batch.io.orm.ibatis.IbatisInputSource"
<bean id="ibatisInputSource" class="org.springframework.batch.io.driving.IbatisInputSource"
scope="step" >
<aop:scoped-proxy />
<property name="drivingQueryId" value="getAllCustomerCreditIds" />