From dafb8360444abe38bdc2b05628b2021234ebfcdb Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Tue, 9 Oct 2012 13:01:46 -0500 Subject: [PATCH] BATCH-1684: Updated to include injection via the JobExplorerFactoryBean as well --- .../support/JobExplorerFactoryBean.java | 31 ++++++++++++++++--- .../dao/JdbcExecutionContextDao.java | 1 + .../support/JobRepositoryFactoryBean.java | 6 +--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java index a62b96aea..c14e305de 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/JobExplorerFactoryBean.java @@ -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); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java index 90e555fa0..85856462d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java @@ -239,6 +239,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem @SuppressWarnings("unchecked") private class ExecutionContextRowMapper implements ParameterizedRowMapper { + public ExecutionContext mapRow(ResultSet rs, int i) throws SQLException { ExecutionContext executionContext = new ExecutionContext(); String serializedContext = rs.getString("SERIALIZED_CONTEXT"); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java index 4b4ad92e2..1407429b2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java @@ -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);