From 082c81765fcbc78351a26bee441e513afd91c0e6 Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Mon, 18 Mar 2013 19:54:08 -0400 Subject: [PATCH] BATCH-1968: Upgrade to hsqldb 2.2.9 --- archetypes/simple-cli/pom.xml | 4 +- spring-batch-core-tests/pom.xml | 2 +- spring-batch-core/pom.xml | 2 +- .../dao/JdbcExecutionContextDao.java | 67 ++++++++-------- .../repository/dao/JdbcStepExecutionDao.java | 77 ++++++++++--------- spring-batch-infrastructure-tests/pom.xml | 2 +- spring-batch-infrastructure/pom.xml | 2 +- .../StoredProcedureItemReaderCommonTests.java | 4 +- .../StoredprocedureItemReaderConfigTests.java | 2 +- spring-batch-parent/pom.xml | 12 +-- spring-batch-samples/pom.xml | 2 +- spring-batch-test/pom.xml | 2 +- 12 files changed, 91 insertions(+), 87 deletions(-) diff --git a/archetypes/simple-cli/pom.xml b/archetypes/simple-cli/pom.xml index c8fa65421..5d3cb6543 100644 --- a/archetypes/simple-cli/pom.xml +++ b/archetypes/simple-cli/pom.xml @@ -119,9 +119,9 @@ 1.4 - hsqldb + org.hsqldb hsqldb - 1.8.0.7 + 2.2.9 org.aspectj diff --git a/spring-batch-core-tests/pom.xml b/spring-batch-core-tests/pom.xml index 86988170f..37ab317aa 100644 --- a/spring-batch-core-tests/pom.xml +++ b/spring-batch-core-tests/pom.xml @@ -78,7 +78,7 @@ commons-dbcp - hsqldb + org.hsqldb hsqldb diff --git a/spring-batch-core/pom.xml b/spring-batch-core/pom.xml index 5593f2061..8d6716780 100644 --- a/spring-batch-core/pom.xml +++ b/spring-batch-core/pom.xml @@ -19,7 +19,7 @@ ${project.version} - hsqldb + org.hsqldb hsqldb 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 10a84984b..f69a2a21c 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 @@ -248,42 +248,41 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem * @param sql with parameters (shortContext, longContext, executionId) */ private void persistSerializedContexts(final Map serializedContexts, String sql) { + if (!serializedContexts.isEmpty()) { + final Iterator executionIdIterator = serializedContexts.keySet().iterator(); - final Iterator executionIdIterator = serializedContexts.keySet().iterator(); + getJdbcTemplate().batchUpdate(getQuery(sql), new BatchPreparedStatementSetter() { + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + Long executionId = executionIdIterator.next(); + String serializedContext = serializedContexts.get(executionId); + String shortContext; + String longContext; + 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 { + shortContext = serializedContext; + longContext = null; + } + ps.setString(1, shortContext); + if (longContext != null) { + lobHandler.getLobCreator().setClobAsString(ps, 2, longContext); + } else { + ps.setNull(2, getClobTypeToUse()); + } + ps.setLong(3, executionId); + } - getJdbcTemplate().batchUpdate(getQuery(sql), new BatchPreparedStatementSetter() { - @Override - public void setValues(PreparedStatement ps, int i) throws SQLException { - Long executionId = executionIdIterator.next(); - String serializedContext = serializedContexts.get(executionId); - String shortContext; - String longContext; - 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 { - shortContext = serializedContext; - longContext = null; - } - ps.setString(1, shortContext); - if (longContext != null) { - lobHandler.getLobCreator().setClobAsString(ps, 2, longContext); - } - else { - ps.setNull(2, getClobTypeToUse()); - } - ps.setLong(3, executionId); - } - - @Override - public int getBatchSize() { - return serializedContexts.size(); - } - }); - } + @Override + public int getBatchSize() { + return serializedContexts.size(); + } + }); + } + } @SuppressWarnings("unchecked") private String serializeContext(ExecutionContext ctx) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index da2125e38..84af2cd0b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -133,44 +133,49 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement @Override public void saveStepExecutions(final Collection stepExecutions) { Assert.notNull(stepExecutions, "Attempt to save a null collection of step executions"); - final Iterator iterator = stepExecutions.iterator(); - getJdbcTemplate().batchUpdate(getQuery(SAVE_STEP_EXECUTION), new BatchPreparedStatementSetter() { - @Override - public int getBatchSize() { - return stepExecutions.size(); - } + if (!stepExecutions.isEmpty()) { + final Iterator iterator = stepExecutions.iterator(); + getJdbcTemplate().batchUpdate(getQuery(SAVE_STEP_EXECUTION), new BatchPreparedStatementSetter() { - @Override - public void setValues(PreparedStatement ps, int i) throws SQLException { - StepExecution stepExecution = iterator.next(); - List parameters = buildStepExecutionParameters(stepExecution); - Object[] parameterValues = (Object[]) parameters.get(0); - Integer[] parameterTypes = (Integer[]) parameters.get(1); - for (int indx = 0; indx < parameterValues.length; indx++) { - switch (parameterTypes[indx]) { - case Types.INTEGER: - ps.setInt(indx + 1, (Integer) parameterValues[indx]); - break; - case Types.VARCHAR: - ps.setString(indx + 1, (String) parameterValues[indx]); - break; - case Types.TIMESTAMP: - if (parameterValues[indx] !=null) { - ps.setTimestamp(indx + 1, new Timestamp(((java.util.Date) parameterValues[indx]).getTime())); - } - break; - case Types.BIGINT: - ps.setLong(indx + 1, (Long) parameterValues[indx]); - break; - default: - throw new IllegalArgumentException( - "unsupported SQL parameter type for step execution field index " + i); - } - } - } - }); - } + @Override + public int getBatchSize() { + return stepExecutions.size(); + } + + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + StepExecution stepExecution = iterator.next(); + List parameters = buildStepExecutionParameters(stepExecution); + Object[] parameterValues = (Object[]) parameters.get(0); + Integer[] parameterTypes = (Integer[]) parameters.get(1); + for (int indx = 0; indx < parameterValues.length; indx++) { + switch (parameterTypes[indx]) { + case Types.INTEGER: + ps.setInt(indx + 1, (Integer) parameterValues[indx]); + break; + case Types.VARCHAR: + ps.setString(indx + 1, (String) parameterValues[indx]); + break; + case Types.TIMESTAMP: + if (parameterValues[indx] != null) { + ps.setTimestamp(indx + 1, new Timestamp(((java.util.Date) parameterValues[indx]).getTime())); + } else { + ps.setNull(indx + 1, Types.TIMESTAMP); + } + break; + case Types.BIGINT: + ps.setLong(indx + 1, (Long) parameterValues[indx]); + break; + default: + throw new IllegalArgumentException( + "unsupported SQL parameter type for step execution field index " + i); + } + } + } + }); + } + } private List buildStepExecutionParameters(StepExecution stepExecution) { Assert.isNull(stepExecution.getId(), diff --git a/spring-batch-infrastructure-tests/pom.xml b/spring-batch-infrastructure-tests/pom.xml index ec5c3c07d..d55d7b4a7 100644 --- a/spring-batch-infrastructure-tests/pom.xml +++ b/spring-batch-infrastructure-tests/pom.xml @@ -60,7 +60,7 @@ 2.2.0.BUILD-SNAPSHOT - hsqldb + org.hsqldb hsqldb diff --git a/spring-batch-infrastructure/pom.xml b/spring-batch-infrastructure/pom.xml index fad12c11f..607f21f05 100644 --- a/spring-batch-infrastructure/pom.xml +++ b/spring-batch-infrastructure/pom.xml @@ -86,7 +86,7 @@ true - hsqldb + org.hsqldb hsqldb test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java index 2fc9b45e6..0c1c226ad 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java @@ -3,7 +3,7 @@ package org.springframework.batch.item.database; import java.sql.PreparedStatement; import java.sql.SQLException; -import org.hsqldb.Types; +import org.hsqldb.types.Types; import org.junit.Test; import org.junit.runners.JUnit4; import org.junit.runner.RunWith; @@ -53,7 +53,7 @@ public class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemSt reader.setProcedureName("read_some_foos"); reader.setParameters( new SqlParameter[] { - new SqlParameter("from_id", Types.NUMERIC), + new SqlParameter("from_id", Types.NUMERIC), new SqlParameter("to_id", Types.NUMERIC) }); reader.setPreparedStatementSetter( diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java index 1a1cbb8de..210f35f55 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java @@ -12,7 +12,7 @@ import java.sql.SQLException; import javax.sql.DataSource; -import org.hsqldb.Types; +import org.hsqldb.types.Types; import org.junit.Test; import org.junit.runners.JUnit4; import org.junit.runner.RunWith; diff --git a/spring-batch-parent/pom.xml b/spring-batch-parent/pom.xml index d68929fe5..d3423a1a7 100644 --- a/spring-batch-parent/pom.xml +++ b/spring-batch-parent/pom.xml @@ -513,12 +513,12 @@ 1.2.14 true - - hsqldb - hsqldb - 1.8.0.7 - test - + + org.hsqldb + hsqldb + 2.2.9 + test + com.h2database h2 diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index 20f53e65e..6e86056dd 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -103,7 +103,7 @@ runtime - hsqldb + org.hsqldb hsqldb runtime diff --git a/spring-batch-test/pom.xml b/spring-batch-test/pom.xml index 0a4f06922..3b743b690 100755 --- a/spring-batch-test/pom.xml +++ b/spring-batch-test/pom.xml @@ -45,7 +45,7 @@ commons-dbcp - hsqldb + org.hsqldb hsqldb