RESOLVED - issue BATCH-1415: Execution context cannot be saved on Oracle (UTF8) when context length is between 2000 and 2500 characters

http://jira.springframework.org/browse/BATCH-1415
This commit is contained in:
dsyer
2009-09-28 13:18:20 +00:00
parent 244e18a019
commit e349e4a643

View File

@@ -16,19 +16,19 @@
package org.springframework.batch.core.repository.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.util.Map.Entry;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.util.Assert;
@@ -63,12 +63,28 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
private static final String UPDATE_STEP_EXECUTION_CONTEXT = "UPDATE %PREFIX%STEP_EXECUTION_CONTEXT "
+ "SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? " + "WHERE STEP_EXECUTION_ID = ?";
private static final int MAX_VARCHAR_LENGTH = 2500;
private static final int DEFAULT_MAX_VARCHAR_LENGTH = 2500;
private int shortContextLength = DEFAULT_MAX_VARCHAR_LENGTH;
private LobHandler lobHandler = new DefaultLobHandler();
private ExecutionContextStringSerializer serializer;
/**
* The maximum size that an execution context can have and still be stored
* completely in short form in the column <code>SHORT_CONTEXT</code>.
* Anything longer than this will overflow into large-object storage, and
* the first part only will be retained in the short form for readability.
* Default value is 2500. Clients using multi-bytes charsets on the database
* server may need to reduce this value to as little as half the value of
* the column size.
* @param shortContextLength
*/
public void setShortContextLength(int shortContextLength) {
this.shortContextLength = shortContextLength;
}
public ExecutionContext getExecutionContext(JobExecution jobExecution) {
Long executionId = jobExecution.getId();
Assert.notNull(executionId, "ExecutionId must not be null.");
@@ -163,8 +179,10 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem
final String shortContext;
final String longContext;
if (serializedContext.length() > MAX_VARCHAR_LENGTH) {
shortContext = serializedContext.substring(0, MAX_VARCHAR_LENGTH - 4) + " ...";
if (serializedContext.length() > shortContextLength) {
// Overestimate length of ellipsis to be on the safe side with
// 2-byte chars
shortContext = serializedContext.substring(0, shortContextLength - 8) + " ...";
longContext = serializedContext;
}
else {