From 7a3dbdb69f09cba4c218a952c9c367c2bdfe35da Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Thu, 19 Sep 2024 12:01:43 +0200 Subject: [PATCH] #4588 Deprecate LobHandler --- .../annotation/BatchRegistrar.java | 10 --- .../annotation/EnableBatchProcessing.java | 6 -- .../support/DefaultBatchConfiguration.java | 16 ---- .../xml/JobRepositoryParser.java | 5 -- .../support/JobExplorerFactoryBean.java | 17 ---- .../dao/JdbcExecutionContextDao.java | 13 +-- .../support/JobRepositoryFactoryBean.java | 24 ----- .../configuration/xml/spring-batch-2.1.xsd | 15 +--- .../configuration/xml/spring-batch-2.2.xsd | 13 --- .../configuration/xml/spring-batch-3.0.xsd | 17 +--- .../core/configuration/xml/spring-batch.xsd | 17 +--- .../JobRepositoryFactoryBeanTests.java | 89 ++++++++++--------- ...aultTolerantStepFactoryBeanRetryTests.java | 2 +- .../RepeatOperationsStepFactoryBeanTests.java | 3 +- .../xml/JobRepositoryParserTests-context.xml | 5 +- .../main/resources/data-source-context.xml | 2 - .../misc/jmx/adhoc-job-launcher-context.xml | 6 +- .../resources/simple-job-launcher-context.xml | 2 +- 18 files changed, 64 insertions(+), 198 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java index 5a680aaa31..61c9016368 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/BatchRegistrar.java @@ -101,11 +101,6 @@ private void registerJobRepository(BeanDefinitionRegistry registry, EnableBatchP beanDefinitionBuilder.addPropertyReference("serializer", executionContextSerializerRef); } - String lobHandlerRef = batchAnnotation.lobHandlerRef(); - if (registry.containsBeanDefinition(lobHandlerRef)) { - beanDefinitionBuilder.addPropertyReference("lobHandler", lobHandlerRef); - } - String conversionServiceRef = batchAnnotation.conversionServiceRef(); if (registry.containsBeanDefinition(conversionServiceRef)) { beanDefinitionBuilder.addPropertyReference("conversionService", conversionServiceRef); @@ -168,11 +163,6 @@ private void registerJobExplorer(BeanDefinitionRegistry registry, EnableBatchPro beanDefinitionBuilder.addPropertyReference("serializer", executionContextSerializerRef); } - String lobHandlerRef = batchAnnotation.lobHandlerRef(); - if (registry.containsBeanDefinition(lobHandlerRef)) { - beanDefinitionBuilder.addPropertyReference("lobHandler", lobHandlerRef); - } - String conversionServiceRef = batchAnnotation.conversionServiceRef(); if (registry.containsBeanDefinition(conversionServiceRef)) { beanDefinitionBuilder.addPropertyReference("conversionService", conversionServiceRef); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java index c4fb3be8d7..ad241b8410 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java @@ -237,12 +237,6 @@ */ String jobKeyGeneratorRef() default "jobKeyGenerator"; - /** - * The large object handler to use in job repository and job explorer. - * @return the bean name of the lob handler to use. Defaults to {@literal lobHandler}. - */ - String lobHandlerRef() default "lobHandler"; - /** * The type of large objects. * @return the type of large objects. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java index 17cf0e391a..18e668b3ce 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java @@ -18,9 +18,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.sql.Types; - import javax.sql.DataSource; - import org.springframework.batch.core.DefaultJobKeyGenerator; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobKeyGenerator; @@ -65,8 +63,6 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.MetaDataAccessException; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; -import org.springframework.jdbc.support.lob.DefaultLobHandler; -import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Isolation; @@ -135,7 +131,6 @@ public JobRepository jobRepository() throws BatchConfigurationException { jobRepositoryFactoryBean.setSerializer(getExecutionContextSerializer()); jobRepositoryFactoryBean.setConversionService(getConversionService()); jobRepositoryFactoryBean.setJdbcOperations(getJdbcOperations()); - jobRepositoryFactoryBean.setLobHandler(getLobHandler()); jobRepositoryFactoryBean.setCharset(getCharset()); jobRepositoryFactoryBean.setMaxVarCharLength(getMaxVarCharLength()); jobRepositoryFactoryBean.setIsolationLevelForCreateEnum(getIsolationLevelForCreate()); @@ -189,7 +184,6 @@ public JobExplorer jobExplorer() throws BatchConfigurationException { jobExplorerFactoryBean.setJobKeyGenerator(getJobKeyGenerator()); jobExplorerFactoryBean.setCharset(getCharset()); jobExplorerFactoryBean.setTablePrefix(getTablePrefix()); - jobExplorerFactoryBean.setLobHandler(getLobHandler()); jobExplorerFactoryBean.setConversionService(getConversionService()); jobExplorerFactoryBean.setSerializer(getExecutionContextSerializer()); try { @@ -385,16 +379,6 @@ protected Charset getCharset() { return StandardCharsets.UTF_8; } - /** - * A special handler for large objects. The default is usually fine, except for some - * (usually older) versions of Oracle. - * @return the {@link LobHandler} to use - * - */ - protected LobHandler getLobHandler() { - return new DefaultLobHandler(); - } - /** * Return the {@link JdbcOperations}. If this property is not overridden, a new * {@link JdbcTemplate} will be created for the configured data source by default. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java index be88087562..117a3c3e61 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobRepositoryParser.java @@ -77,8 +77,6 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit String maxVarCharLength = element.getAttribute("max-varchar-length"); - String lobHandler = element.getAttribute("lob-handler"); - String serializer = element.getAttribute("serializer"); String conversionService = element.getAttribute("conversion-service"); @@ -97,9 +95,6 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit if (StringUtils.hasText(tablePrefix)) { builder.addPropertyValue("tablePrefix", tablePrefix); } - if (StringUtils.hasText(lobHandler)) { - builder.addPropertyReference("lobHandler", lobHandler); - } if (StringUtils.hasText(maxVarCharLength)) { builder.addPropertyValue("maxVarCharLength", maxVarCharLength); } 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 4d99c15fa8..cfb0fffabd 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,9 +18,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; - import javax.sql.DataSource; - import org.springframework.batch.core.DefaultJobKeyGenerator; import org.springframework.batch.core.JobKeyGenerator; import org.springframework.batch.core.converter.DateToStringConverter; @@ -42,7 +40,6 @@ 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.item.ExecutionContext; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.support.ConfigurableConversionService; @@ -51,7 +48,6 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; -import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.lang.NonNull; import org.springframework.util.Assert; @@ -81,8 +77,6 @@ protected long getNextKey() { private JobKeyGenerator jobKeyGenerator; - private LobHandler lobHandler; - private ExecutionContextSerializer serializer; private Charset charset = StandardCharsets.UTF_8; @@ -138,16 +132,6 @@ public void setJobKeyGenerator(JobKeyGenerator jobKeyGenerator) { this.jobKeyGenerator = jobKeyGenerator; } - /** - * The lob handler to use when saving {@link ExecutionContext} instances. Defaults to - * {@code null}, which works for most databases. - * @param lobHandler Large object handler for saving an - * {@link org.springframework.batch.item.ExecutionContext}. - */ - public void setLobHandler(LobHandler lobHandler) { - this.lobHandler = lobHandler; - } - /** * Sets the {@link Charset} to use when deserializing the execution context. Defaults * to "UTF-8". Must not be {@code null}. @@ -208,7 +192,6 @@ public void afterPropertiesSet() throws Exception { protected ExecutionContextDao createExecutionContextDao() throws Exception { JdbcExecutionContextDao dao = new JdbcExecutionContextDao(); dao.setJdbcTemplate(jdbcOperations); - dao.setLobHandler(lobHandler); dao.setTablePrefix(tablePrefix); dao.setSerializer(serializer); dao.setCharset(charset); 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 e59c459390..b2c05824be 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 @@ -33,6 +33,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import javax.sql.rowset.serial.SerialClob; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.ExecutionContextSerializer; @@ -40,8 +41,6 @@ import org.springframework.core.serializer.Serializer; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.support.lob.DefaultLobHandler; -import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.lang.NonNull; import org.springframework.util.Assert; @@ -110,8 +109,6 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem private int shortContextLength = DEFAULT_MAX_VARCHAR_LENGTH; - private LobHandler lobHandler = new DefaultLobHandler(); - private ExecutionContextSerializer serializer = new DefaultExecutionContextSerializer(); private final Lock lock = new ReentrantLock(); @@ -268,10 +265,6 @@ public void deleteExecutionContext(StepExecution stepExecution) { getJdbcTemplate().update(getQuery(DELETE_STEP_EXECUTION_CONTEXT), stepExecution.getId()); } - public void setLobHandler(LobHandler lobHandler) { - this.lobHandler = lobHandler; - } - @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); @@ -301,7 +294,7 @@ private void persistSerializedContext(final Long executionId, String serializedC getJdbcTemplate().update(getQuery(sql), ps -> { ps.setString(1, shortContext); if (longContext != null) { - lobHandler.getLobCreator().setClobAsString(ps, 2, longContext); + ps.setClob(2, new SerialClob(longContext.toCharArray())); } else { ps.setNull(2, getClobTypeToUse()); @@ -337,7 +330,7 @@ public void setValues(PreparedStatement ps, int i) throws SQLException { } ps.setString(1, shortContext); if (longContext != null) { - lobHandler.getLobCreator().setClobAsString(ps, 2, longContext); + ps.setClob(2, new SerialClob(longContext.toCharArray())); } else { ps.setNull(2, getClobTypeToUse()); 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 2d72203d6f..546e69f134 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 @@ -56,8 +56,6 @@ import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.support.lob.DefaultLobHandler; -import org.springframework.jdbc.support.lob.LobHandler; import org.springframework.lang.NonNull; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -95,8 +93,6 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i private int maxVarCharLengthForShortContext = AbstractJdbcBatchMetadataDao.DEFAULT_SHORT_CONTEXT_LENGTH; - private LobHandler lobHandler; - private ExecutionContextSerializer serializer; private Integer clobType; @@ -124,18 +120,6 @@ public void setSerializer(ExecutionContextSerializer serializer) { this.serializer = serializer; } - /** - * A special handler for large objects. The default is usually fine, except for some - * (usually older) versions of Oracle. The default is determined from the data base - * type. - * @param lobHandler the {@link LobHandler} to set - * - * @see LobHandler - */ - public void setLobHandler(LobHandler lobHandler) { - this.lobHandler = lobHandler; - } - /** * Public setter for the length of long string columns in database. Do not set this if * you haven't modified the schema. Note this value will be used for the exit message @@ -275,10 +259,6 @@ public void afterPropertiesSet() throws Exception { } } - if (lobHandler == null && databaseType.equalsIgnoreCase(DatabaseType.ORACLE.toString())) { - lobHandler = new DefaultLobHandler(); - } - if (serializer == null) { serializer = new DefaultExecutionContextSerializer(); } @@ -354,10 +334,6 @@ protected ExecutionContextDao createExecutionContextDao() throws Exception { dao.setSerializer(serializer); dao.setCharset(charset); - if (lobHandler != null) { - dao.setLobHandler(lobHandler); - } - dao.afterPropertiesSet(); dao.setShortContextLength(this.maxVarCharLengthForShortContext); return dao; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd index 559c74a748..e254199fb1 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd @@ -235,19 +235,6 @@ ref" is not required, and only needs to be specified explicitly ]]> - - - - - - - - - - @@ -1288,4 +1275,4 @@ ref" is not required, and only needs to be specified explicitly - \ No newline at end of file + diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.2.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.2.xsd index df341d1b29..9d5655c342 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.2.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.2.xsd @@ -249,19 +249,6 @@ ref" is not required, and only needs to be specified explicitly - - - - - - - - - - diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-3.0.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-3.0.xsd index 3857e27962..9f0cc73cbb 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-3.0.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-3.0.xsd @@ -184,7 +184,7 @@ @@ -198,7 +198,7 @@ @@ -264,19 +264,6 @@ - - - - - - - - - - diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch.xsd index 9879886658..6b971ec844 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch.xsd @@ -185,7 +185,7 @@ @@ -199,7 +199,7 @@ @@ -265,19 +265,6 @@ - - - - - - - - - - - - + - \ No newline at end of file + diff --git a/spring-batch-samples/src/main/resources/data-source-context.xml b/spring-batch-samples/src/main/resources/data-source-context.xml index 39c1506bda..2f0c1fe7a4 100644 --- a/spring-batch-samples/src/main/resources/data-source-context.xml +++ b/spring-batch-samples/src/main/resources/data-source-context.xml @@ -24,6 +24,4 @@ - - diff --git a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml index efbc83b8d5..b485064b32 100644 --- a/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/org/springframework/batch/samples/misc/jmx/adhoc-job-launcher-context.xml @@ -17,7 +17,7 @@ + p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"/> - + @@ -71,4 +71,4 @@ - \ No newline at end of file + diff --git a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml index 7e66008208..92758f0a07 100644 --- a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml @@ -17,7 +17,7 @@ + p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"/>