diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java index aac208e4a..b755651fb 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import org.springframework.util.StringUtils; * jdbcTemplate for subclasses and handles table prefixes. * * @author Robert Kasanicky + * @author Mahmoud Ben Hassine */ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { @@ -38,6 +39,8 @@ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { public static final int DEFAULT_EXIT_MESSAGE_LENGTH = 2500; + public static final int DEFAULT_SHORT_CONTEXT_LENGTH = 2500; + private String tablePrefix = DEFAULT_TABLE_PREFIX; private int clobTypeToUse = Types.CLOB; 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 01a203250..2d72203d6 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 @@ -91,7 +91,9 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i private JobKeyGenerator jobKeyGenerator; - private int maxVarCharLength = AbstractJdbcBatchMetadataDao.DEFAULT_EXIT_MESSAGE_LENGTH; + private int maxVarCharLengthForExitMessage = AbstractJdbcBatchMetadataDao.DEFAULT_EXIT_MESSAGE_LENGTH; + + private int maxVarCharLengthForShortContext = AbstractJdbcBatchMetadataDao.DEFAULT_SHORT_CONTEXT_LENGTH; private LobHandler lobHandler; @@ -138,14 +140,44 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i * 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 * in both {@link JdbcJobExecutionDao} and {@link JdbcStepExecutionDao} and also the - * short version of the execution context in {@link JdbcExecutionContextDao} . For - * databases with multi-byte character sets this number can be smaller (by up to a - * factor of 2 for 2-byte characters) than the declaration of the column length in the - * DDL for the tables. + * short version of the execution context in {@link JdbcExecutionContextDao} . If you + * want to use separate values for exit message and short context, then use + * {@link #setMaxVarCharLengthForExitMessage(int)} and + * {@link #setMaxVarCharLengthForShortContext(int)}. For databases with multi-byte + * character sets this number can be smaller (by up to a factor of 2 for 2-byte + * characters) than the declaration of the column length in the DDL for the tables. * @param maxVarCharLength the exitMessageLength to set */ public void setMaxVarCharLength(int maxVarCharLength) { - this.maxVarCharLength = maxVarCharLength; + this.maxVarCharLengthForExitMessage = maxVarCharLength; + this.maxVarCharLengthForShortContext = maxVarCharLength; + } + + /** + * Public setter for the length of short context string column in database. Do not set + * this if you haven't modified the schema. For databases with multi-byte character + * sets this number can be smaller (by up to a factor of 2 for 2-byte characters) than + * the declaration of the column length in the DDL for the tables. Defaults to + * {@link AbstractJdbcBatchMetadataDao#DEFAULT_SHORT_CONTEXT_LENGTH} + * @param maxVarCharLengthForShortContext the short context length to set + * @since 5.1 + */ + public void setMaxVarCharLengthForShortContext(int maxVarCharLengthForShortContext) { + this.maxVarCharLengthForShortContext = maxVarCharLengthForShortContext; + } + + /** + * Public setter for the length of the exit message in both + * {@link JdbcJobExecutionDao} and {@link JdbcStepExecutionDao}. Do not set this if + * you haven't modified the schema. For databases with multi-byte character sets this + * number can be smaller (by up to a factor of 2 for 2-byte characters) than the + * declaration of the column length in the DDL for the tables. Defaults to + * {@link AbstractJdbcBatchMetadataDao#DEFAULT_EXIT_MESSAGE_LENGTH}. + * @param maxVarCharLengthForExitMessage the exitMessageLength to set + * @since 5.1 + */ + public void setMaxVarCharLengthForExitMessage(int maxVarCharLengthForExitMessage) { + this.maxVarCharLengthForExitMessage = maxVarCharLengthForExitMessage; } /** @@ -294,7 +326,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")); dao.setTablePrefix(tablePrefix); dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType)); - dao.setExitMessageLength(maxVarCharLength); + dao.setExitMessageLength(this.maxVarCharLengthForExitMessage); dao.setConversionService(this.conversionService); dao.afterPropertiesSet(); return dao; @@ -308,7 +340,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")); dao.setTablePrefix(tablePrefix); dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType)); - dao.setExitMessageLength(maxVarCharLength); + dao.setExitMessageLength(this.maxVarCharLengthForExitMessage); dao.afterPropertiesSet(); return dao; } @@ -327,8 +359,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i } dao.afterPropertiesSet(); - // Assume the same length. - dao.setShortContextLength(maxVarCharLength); + dao.setShortContextLength(this.maxVarCharLengthForShortContext); return dao; }