Skip to content

Commit f64d6e8

Browse files
committed
Use separate parameters for short_context length and exit_message length in JobRepositoryFactoryBean
Resolves #1617
1 parent 0a96669 commit f64d6e8

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
* jdbcTemplate for subclasses and handles table prefixes.
2929
*
3030
* @author Robert Kasanicky
31+
* @author Mahmoud Ben Hassine
3132
*/
3233
public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean {
3334

@@ -38,6 +39,8 @@ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean {
3839

3940
public static final int DEFAULT_EXIT_MESSAGE_LENGTH = 2500;
4041

42+
public static final int DEFAULT_SHORT_CONTEXT_LENGTH = 2500;
43+
4144
private String tablePrefix = DEFAULT_TABLE_PREFIX;
4245

4346
private int clobTypeToUse = Types.CLOB;

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i
9191

9292
private JobKeyGenerator jobKeyGenerator;
9393

94-
private int maxVarCharLength = AbstractJdbcBatchMetadataDao.DEFAULT_EXIT_MESSAGE_LENGTH;
94+
private int maxVarCharLengthForExitMessage = AbstractJdbcBatchMetadataDao.DEFAULT_EXIT_MESSAGE_LENGTH;
95+
96+
private int maxVarCharLengthForShortContext = AbstractJdbcBatchMetadataDao.DEFAULT_SHORT_CONTEXT_LENGTH;
9597

9698
private LobHandler lobHandler;
9799

@@ -138,14 +140,44 @@ public void setLobHandler(LobHandler lobHandler) {
138140
* Public setter for the length of long string columns in database. Do not set this if
139141
* you haven't modified the schema. Note this value will be used for the exit message
140142
* in both {@link JdbcJobExecutionDao} and {@link JdbcStepExecutionDao} and also the
141-
* short version of the execution context in {@link JdbcExecutionContextDao} . For
142-
* databases with multi-byte character sets this number can be smaller (by up to a
143-
* factor of 2 for 2-byte characters) than the declaration of the column length in the
144-
* DDL for the tables.
143+
* short version of the execution context in {@link JdbcExecutionContextDao} . If you
144+
* want to use separate values for exit message and short context, then use
145+
* {@link #setMaxVarCharLengthForExitMessage(int)} and
146+
* {@link #setMaxVarCharLengthForShortContext(int)}. For databases with multi-byte
147+
* character sets this number can be smaller (by up to a factor of 2 for 2-byte
148+
* characters) than the declaration of the column length in the DDL for the tables.
145149
* @param maxVarCharLength the exitMessageLength to set
146150
*/
147151
public void setMaxVarCharLength(int maxVarCharLength) {
148-
this.maxVarCharLength = maxVarCharLength;
152+
this.maxVarCharLengthForExitMessage = maxVarCharLength;
153+
this.maxVarCharLengthForShortContext = maxVarCharLength;
154+
}
155+
156+
/**
157+
* Public setter for the length of short context string column in database. Do not set
158+
* this if you haven't modified the schema. For databases with multi-byte character
159+
* sets this number can be smaller (by up to a factor of 2 for 2-byte characters) than
160+
* the declaration of the column length in the DDL for the tables. Defaults to
161+
* {@link AbstractJdbcBatchMetadataDao#DEFAULT_SHORT_CONTEXT_LENGTH}
162+
* @param maxVarCharLengthForShortContext the short context length to set
163+
* @since 5.1
164+
*/
165+
public void setMaxVarCharLengthForShortContext(int maxVarCharLengthForShortContext) {
166+
this.maxVarCharLengthForShortContext = maxVarCharLengthForShortContext;
167+
}
168+
169+
/**
170+
* Public setter for the length of the exit message in both
171+
* {@link JdbcJobExecutionDao} and {@link JdbcStepExecutionDao}. Do not set this if
172+
* you haven't modified the schema. For databases with multi-byte character sets this
173+
* number can be smaller (by up to a factor of 2 for 2-byte characters) than the
174+
* declaration of the column length in the DDL for the tables. Defaults to
175+
* {@link AbstractJdbcBatchMetadataDao#DEFAULT_EXIT_MESSAGE_LENGTH}.
176+
* @param maxVarCharLengthForExitMessage the exitMessageLength to set
177+
* @since 5.1
178+
*/
179+
public void setMaxVarCharLengthForExitMessage(int maxVarCharLengthForExitMessage) {
180+
this.maxVarCharLengthForExitMessage = maxVarCharLengthForExitMessage;
149181
}
150182

151183
/**
@@ -294,7 +326,7 @@ protected JobExecutionDao createJobExecutionDao() throws Exception {
294326
incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ"));
295327
dao.setTablePrefix(tablePrefix);
296328
dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType));
297-
dao.setExitMessageLength(maxVarCharLength);
329+
dao.setExitMessageLength(this.maxVarCharLengthForExitMessage);
298330
dao.setConversionService(this.conversionService);
299331
dao.afterPropertiesSet();
300332
return dao;
@@ -308,7 +340,7 @@ protected StepExecutionDao createStepExecutionDao() throws Exception {
308340
incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ"));
309341
dao.setTablePrefix(tablePrefix);
310342
dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType));
311-
dao.setExitMessageLength(maxVarCharLength);
343+
dao.setExitMessageLength(this.maxVarCharLengthForExitMessage);
312344
dao.afterPropertiesSet();
313345
return dao;
314346
}
@@ -327,8 +359,7 @@ protected ExecutionContextDao createExecutionContextDao() throws Exception {
327359
}
328360

329361
dao.afterPropertiesSet();
330-
// Assume the same length.
331-
dao.setShortContextLength(maxVarCharLength);
362+
dao.setShortContextLength(this.maxVarCharLengthForShortContext);
332363
return dao;
333364
}
334365

0 commit comments

Comments
 (0)