From f38c05567a392a925319336eed3cda87a501b065 Mon Sep 17 00:00:00 2001 From: dsyer Date: Mon, 5 Apr 2010 16:22:08 +0000 Subject: [PATCH] BATCH-1546: enable integration tests with Oracle --- .../batch/core/schema-oracle10g.sql | 6 ++--- spring-batch-core/src/main/sql/oracle10g.vpp | 2 +- spring-batch-infrastructure-tests/pom.xml | 23 ++++++++++++++++++ .../JdbcPagingItemReaderAsyncTests.java | 13 +++++----- .../JdbcPagingRestartIntegrationTests.java | 15 ++++++------ .../src/test/resources/batch-hsql.properties | 2 +- .../test/resources/batch-oracle.properties | 14 +++++++++++ ...dbcPagingItemReaderCommonTests-context.xml | 2 +- .../item/database/init-foo-schema-oracle.sql | 24 +++++++++++++++++++ .../resources/adhoc-job-launcher-context.xml | 5 ++++ .../src/main/resources/batch-hsql.properties | 1 + .../src/main/resources/batch-mysql.properties | 1 + .../main/resources/batch-oracle.properties | 11 +++++---- .../resources/business-schema-oracle10g.sql | 4 ++-- .../main/resources/data-source-context.xml | 2 +- .../resources/simple-job-launcher-context.xml | 2 +- .../CustomerFilterJobFunctionalTests.java | 6 ++--- 17 files changed, 102 insertions(+), 31 deletions(-) create mode 100644 spring-batch-infrastructure-tests/src/test/resources/batch-oracle.properties create mode 100644 spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/init-foo-schema-oracle.sql diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle10g.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle10g.sql index 1f5c94545..a50f89f28 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle10g.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle10g.sql @@ -74,6 +74,6 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ) ; -CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ START WITH 0 MAXVALUE 9223372036854775807 NOCYCLE; -CREATE SEQUENCE BATCH_JOB_EXECUTION_SEQ START WITH 0 MAXVALUE 9223372036854775807 NOCYCLE; -CREATE SEQUENCE BATCH_JOB_SEQ START WITH 0 MAXVALUE 9223372036854775807 NOCYCLE; +CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 NOCYCLE; +CREATE SEQUENCE BATCH_JOB_EXECUTION_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 NOCYCLE; +CREATE SEQUENCE BATCH_JOB_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 NOCYCLE; diff --git a/spring-batch-core/src/main/sql/oracle10g.vpp b/spring-batch-core/src/main/sql/oracle10g.vpp index facb61f19..610c1f821 100644 --- a/spring-batch-core/src/main/sql/oracle10g.vpp +++ b/spring-batch-core/src/main/sql/oracle10g.vpp @@ -1,3 +1,3 @@ -#macro (sequence $name $value)CREATE SEQUENCE ${name} START WITH ${value} MAXVALUE 9223372036854775807 NOCYCLE; +#macro (sequence $name $value)CREATE SEQUENCE ${name} START WITH ${value} MINVALUE 0 MAXVALUE 9223372036854775807 NOCYCLE; #end #macro (notnull $name $type)MODIFY ${name} NOT NULL#end diff --git a/spring-batch-infrastructure-tests/pom.xml b/spring-batch-infrastructure-tests/pom.xml index a600f8e1b..7feafd91e 100644 --- a/spring-batch-infrastructure-tests/pom.xml +++ b/spring-batch-infrastructure-tests/pom.xml @@ -11,6 +11,10 @@ 2.1.1.CI-SNAPSHOT ../spring-batch-parent + + + hsql + tiger @@ -65,6 +69,12 @@ maven-surefire-plugin false + + + ENVIRONMENT + ${environment} + + @@ -219,6 +229,19 @@ org.springframework spring-aop + + mysql + mysql-connector-java + 5.1.6 + runtime + + + com.oracle.jdbc + com.springsource.oracle.jdbc + 10.2.0.2 + true + runtime + diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java index 6cd7e12cf..1da5da798 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java @@ -24,7 +24,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; +import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; @@ -137,11 +137,12 @@ public class JdbcPagingItemReaderAsyncTests { JdbcPagingItemReader reader = new JdbcPagingItemReader(); reader.setDataSource(dataSource); - HsqlPagingQueryProvider queryProvider = new HsqlPagingQueryProvider(); - queryProvider.setSelectClause("select ID, NAME, VALUE"); - queryProvider.setFromClause("from T_FOOS"); - queryProvider.setSortKey("ID"); - reader.setQueryProvider(queryProvider); + SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean(); + factory.setDataSource(dataSource); + factory.setSelectClause("select ID, NAME, VALUE"); + factory.setFromClause("from T_FOOS"); + factory.setSortKey("ID"); + reader.setQueryProvider((PagingQueryProvider) factory.getObject()); reader.setRowMapper(new ParameterizedRowMapper() { public Foo mapRow(ResultSet rs, int i) throws SQLException { Foo foo = new Foo(); diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java index 9f547b3be..9ebc966a9 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java @@ -36,7 +36,7 @@ import org.junit.runner.RunWith; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; +import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; @@ -122,7 +122,7 @@ public class JdbcPagingRestartIntegrationTests { List> ids = jdbcTemplate .queryForList("SELECT ID,NAME FROM T_FOOS ORDER BY ID ASC"); logger.debug("Ids: "+ids); - int startAfterValue = ((Long) ids.get(count - 1).get("ID")).intValue(); + int startAfterValue = (new Long(ids.get(count - 1).get("ID").toString())).intValue(); logger.debug("Start after: " + startAfterValue); executionContext.putInt("JdbcPagingItemReader.start.after", startAfterValue); ((ItemStream) reader).open(executionContext); @@ -143,11 +143,12 @@ public class JdbcPagingRestartIntegrationTests { JdbcPagingItemReader reader = new JdbcPagingItemReader(); reader.setDataSource(dataSource); - HsqlPagingQueryProvider queryProvider = new HsqlPagingQueryProvider(); - queryProvider.setSelectClause("select ID, NAME, VALUE"); - queryProvider.setFromClause("from T_FOOS"); - queryProvider.setSortKey("ID"); - reader.setQueryProvider(queryProvider); + SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean(); + factory.setDataSource(dataSource); + factory.setSelectClause("select ID, NAME, VALUE"); + factory.setFromClause("from T_FOOS"); + factory.setSortKey("ID"); + reader.setQueryProvider((PagingQueryProvider) factory.getObject()); reader.setRowMapper(new ParameterizedRowMapper() { public Foo mapRow(ResultSet rs, int i) throws SQLException { Foo foo = new Foo(); diff --git a/spring-batch-infrastructure-tests/src/test/resources/batch-hsql.properties b/spring-batch-infrastructure-tests/src/test/resources/batch-hsql.properties index 105b10f94..d179b0d85 100644 --- a/spring-batch-infrastructure-tests/src/test/resources/batch-hsql.properties +++ b/spring-batch-infrastructure-tests/src/test/resources/batch-hsql.properties @@ -9,7 +9,7 @@ batch.jdbc.user=sa batch.jdbc.password= batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.schema.script=classpath:/org/springframework/batch/core/schema-hsqldb.sql +batch.schema.script=classpath:org/springframework/batch/item/database/init-foo-schema-hsqldb.sql batch.business.schema.script=classpath:/org/springframework/batch/jms/init.sql batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer diff --git a/spring-batch-infrastructure-tests/src/test/resources/batch-oracle.properties b/spring-batch-infrastructure-tests/src/test/resources/batch-oracle.properties new file mode 100644 index 000000000..74c3d8b78 --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/batch-oracle.properties @@ -0,0 +1,14 @@ +# Placeholders batch.* +# for Oracle: +batch.jdbc.driver=oracle.jdbc.OracleDriver +batch.jdbc.url=jdbc:oracle:thin:@oracle:1521:xe +batch.jdbc.user=spring +batch.jdbc.password=spring +batch.jdbc.testWhileIdle=false +batch.jdbc.validationQuery= +batch.schema.script=classpath:org/springframework/batch/item/database/init-foo-schema-oracle.sql +batch.business.schema.script=classpath:/org/springframework/batch/jms/init.sql +batch.data.source.init=true +batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer +batch.database.incrementer.parent=sequenceIncrementerParent +batch.verify.cursor.position=true diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests-context.xml b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests-context.xml index 8ec4b50cd..2fe85e54a 100644 --- a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests-context.xml +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests-context.xml @@ -12,7 +12,7 @@ - classpath:org/springframework/batch/item/database/init-foo-schema-hsqldb.sql + ${batch.schema.script} diff --git a/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/init-foo-schema-oracle.sql b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/init-foo-schema-oracle.sql new file mode 100644 index 000000000..ba236164a --- /dev/null +++ b/spring-batch-infrastructure-tests/src/test/resources/org/springframework/batch/item/database/init-foo-schema-oracle.sql @@ -0,0 +1,24 @@ +DROP TABLE T_FOOS; +DROP TABLE T_WRITE_FOOS; + +CREATE TABLE T_FOOS ( + ID NUMBER(19) NOT NULL, + NAME VARCHAR(45), + VALUE NUMBER(19) +); + +ALTER TABLE T_FOOS ADD PRIMARY KEY (ID); + +INSERT INTO t_foos (id, name, value) VALUES (1, 'bar1', 1); +INSERT INTO t_foos (id, name, value) VALUES (2, 'bar2', 2); +INSERT INTO t_foos (id, name, value) VALUES (3, 'bar3', 3); +INSERT INTO t_foos (id, name, value) VALUES (4, 'bar4', 4); +INSERT INTO t_foos (id, name, value) VALUES (5, 'bar5', 5); + +CREATE TABLE T_WRITE_FOOS ( + ID NUMBER(19) NOT NULL, + NAME VARCHAR(45), + VALUE NUMBER(19) +); + +ALTER TABLE T_WRITE_FOOS ADD PRIMARY KEY (ID); diff --git a/spring-batch-samples/src/main/resources/adhoc-job-launcher-context.xml b/spring-batch-samples/src/main/resources/adhoc-job-launcher-context.xml index 53cff59e3..dd9f1df40 100644 --- a/spring-batch-samples/src/main/resources/adhoc-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/adhoc-job-launcher-context.xml @@ -5,7 +5,9 @@ http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> + + @@ -49,8 +51,11 @@ + + + \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/batch-hsql.properties b/spring-batch-samples/src/main/resources/batch-hsql.properties index 188d9edb4..523673a86 100644 --- a/spring-batch-samples/src/main/resources/batch-hsql.properties +++ b/spring-batch-samples/src/main/resources/batch-hsql.properties @@ -15,5 +15,6 @@ batch.business.schema.script=classpath:/business-schema-hsqldb.sql batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer batch.database.incrementer.parent=columnIncrementerParent +batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.grid.size=2 batch.verify.cursor.position=true diff --git a/spring-batch-samples/src/main/resources/batch-mysql.properties b/spring-batch-samples/src/main/resources/batch-mysql.properties index 4fe7a243e..3e6eef0b5 100644 --- a/spring-batch-samples/src/main/resources/batch-mysql.properties +++ b/spring-batch-samples/src/main/resources/batch-mysql.properties @@ -12,5 +12,6 @@ batch.business.schema.script=classpath:business-schema-mysql.sql batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer batch.database.incrementer.parent=columnIncrementerParent +batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.grid.size=50 batch.verify.cursor.position=true diff --git a/spring-batch-samples/src/main/resources/batch-oracle.properties b/spring-batch-samples/src/main/resources/batch-oracle.properties index 6adf754ad..facd8a650 100644 --- a/spring-batch-samples/src/main/resources/batch-oracle.properties +++ b/spring-batch-samples/src/main/resources/batch-oracle.properties @@ -1,16 +1,17 @@ # Placeholders batch.* -# for MS SQLServer: +# for Oracle: batch.jdbc.driver=oracle.jdbc.OracleDriver -batch.jdbc.url=jdbc:oracle:thin:@//dbhost:1521/xe +batch.jdbc.url=jdbc:oracle:thin:@oracle:1521:xe batch.jdbc.user=spring batch.jdbc.password=spring batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.schema.script=/org/springframework/batch/core/schema-oracle10g.sql +batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-oracle10g.sql +batch.schema.script=classpath:/org/springframework/batch/core/schema-oracle10g.sql batch.business.schema.script=business-schema-oracle10g.sql batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer batch.database.incrementer.parent=sequenceIncrementerParent -batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler +batch.lob.handler.class=org.springframework.jdbc.support.lob.OracleLobHandler batch.grid.size=2 - +batch.verify.cursor.position=true diff --git a/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql b/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql index 47f66092a..5e15fcbdb 100644 --- a/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql +++ b/spring-batch-samples/src/main/resources/business-schema-oracle10g.sql @@ -13,8 +13,8 @@ DROP TABLE ERROR_LOG ; -- Autogenerated: do not edit this file CREATE SEQUENCE CUSTOMER_SEQ START WITH 5; -CREATE SEQUENCE BATCH_STAGING_SEQ START WITH 0; -CREATE SEQUENCE TRADE_SEQ START WITH 0; +CREATE SEQUENCE BATCH_STAGING_SEQ START WITH 0 MINVALUE 0; +CREATE SEQUENCE TRADE_SEQ START WITH 0 MINVALUE 0; CREATE TABLE BATCH_STAGING ( ID NUMBER(38) NOT NULL PRIMARY KEY , 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 f92799db8..8dde8d3c8 100644 --- a/spring-batch-samples/src/main/resources/data-source-context.xml +++ b/spring-batch-samples/src/main/resources/data-source-context.xml @@ -68,6 +68,6 @@ - + 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 3dd3e9785..d6ebd6445 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 @@ -20,7 +20,7 @@ + p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" p:lobHandler-ref="lobHandler"/> step1Execution = this.getStepExecution(jobExecution, "uploadCustomer"); - assertEquals(new Long(4), step1Execution.get("READ_COUNT")); - assertEquals(new Long(1), step1Execution.get("FILTER_COUNT")); - assertEquals(new Long(3), step1Execution.get("WRITE_COUNT")); + assertEquals("4", step1Execution.get("READ_COUNT").toString()); + assertEquals("1", step1Execution.get("FILTER_COUNT").toString()); + assertEquals("3", step1Execution.get("WRITE_COUNT").toString()); }