Merge pull request #58 from mminella/master

BATCH-1684: Updated to include injection via the JobExplorerFactoryBean as well
This commit is contained in:
Michael Minella
2012-10-09 11:06:42 -07:00
3 changed files with 29 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.explore.support;
import javax.sql.DataSource;
import org.springframework.batch.core.repository.ExecutionContextSerializer;
import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
import org.springframework.batch.core.repository.dao.ExecutionContextDao;
import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao;
@@ -27,6 +28,7 @@ import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao;
import org.springframework.batch.core.repository.dao.JobExecutionDao;
import org.springframework.batch.core.repository.dao.JobInstanceDao;
import org.springframework.batch.core.repository.dao.StepExecutionDao;
import org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
@@ -41,7 +43,7 @@ import org.springframework.util.Assert;
* A {@link FactoryBean} that automates the creation of a
* {@link SimpleJobExplorer} using JDBC DAO implementations. Requires the user
* to describe what kind of database they are using.
*
*
* @author Dave Syer
* @since 2.0
*/
@@ -63,9 +65,22 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
private LobHandler lobHandler;
private ExecutionContextSerializer serializer;
/**
* A custom implementation of the {@link ExecutionContextSerializer}.
* The default, if not injected, is the {@link XStreamExecutionContextStringSerializer}.
*
* @param serializer
* @see ExecutionContextSerializer
*/
public void setSerializer(ExecutionContextSerializer serializer) {
this.serializer = serializer;
}
/**
* Public setter for the {@link DataSource}.
*
*
* @param dataSource
* a {@link DataSource}
*/
@@ -75,7 +90,7 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
/**
* Sets the table prefix for all the batch meta-data tables.
*
*
* @param tablePrefix
*/
public void setTablePrefix(String tablePrefix) {
@@ -85,7 +100,7 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
/**
* The lob handler to use when saving {@link ExecutionContext} instances.
* Defaults to null which works for most databases.
*
*
* @param lobHandler
*/
public void setLobHandler(LobHandler lobHandler) {
@@ -98,6 +113,12 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
jdbcTemplate = new JdbcTemplate(dataSource);
if(serializer == null) {
XStreamExecutionContextStringSerializer defaultSerializer = new XStreamExecutionContextStringSerializer();
defaultSerializer.afterPropertiesSet();
serializer = defaultSerializer;
}
}
private Object getTarget() throws Exception {
@@ -112,6 +133,7 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
dao.setJdbcTemplate(jdbcTemplate);
dao.setLobHandler(lobHandler);
dao.setTablePrefix(tablePrefix);
dao.setSerializer(serializer);
dao.afterPropertiesSet();
return dao;
}
@@ -136,6 +158,7 @@ public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
return dao;
}
@Override
protected StepExecutionDao createStepExecutionDao() throws Exception {
JdbcStepExecutionDao dao = new JdbcStepExecutionDao();
dao.setJdbcTemplate(jdbcTemplate);

View File

@@ -239,6 +239,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
@SuppressWarnings("unchecked")
private class ExecutionContextRowMapper implements ParameterizedRowMapper<ExecutionContext> {
public ExecutionContext mapRow(ResultSet rs, int i) throws SQLException {
ExecutionContext executionContext = new ExecutionContext();
String serializedContext = rs.getString("SERIALIZED_CONTEXT");

View File

@@ -179,7 +179,6 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i
+ StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes()));
super.afterPropertiesSet();
}
@Override
@@ -224,15 +223,12 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i
dao.setJdbcTemplate(jdbcTemplate);
dao.setTablePrefix(tablePrefix);
dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType));
dao.setSerializer(serializer);
if (lobHandler != null) {
dao.setLobHandler(lobHandler);
}
if(serializer != null) {
dao.setSerializer(serializer);
}
dao.afterPropertiesSet();
// Assume the same length.
dao.setShortContextLength(maxVarCharLength);