From 78768959b0bfa33f29db70fa754d33aa35116fc6 Mon Sep 17 00:00:00 2001 From: dsyer Date: Tue, 22 Sep 2009 11:33:21 +0000 Subject: [PATCH] BATCH-1407: make samples work with MySQL. --- spring-batch-samples/.classpath | 4 +- ...org.springframework.ide.eclipse.core.prefs | 34 +++--- spring-batch-samples/.springBeans | 28 +---- .../trade/internal/JdbcCustomerDao.java | 11 +- .../datasource/DataSourceInitializer.java | 103 +++++++----------- .../src/main/resources/batch-hsql.properties | 19 ++-- .../src/main/resources/batch-mysql.properties | 24 ++-- .../main/resources/business-schema-derby.sql | 3 + .../main/resources/business-schema-hsqldb.sql | 3 + .../main/resources/business-schema-mysql.sql | 2 +- .../resources/business-schema-sqlserver.sql | 3 + .../main/resources/business-schema-sybase.sql | 3 + .../resources/data-source-context-init.xml | 17 --- .../main/resources/data-source-context.xml | 22 +++- .../main/resources/jobs/customerFilterJob.xml | 11 +- .../main/resources/staging-test-context.xml | 14 +-- spring-batch-samples/src/main/sql/db2.vpp | 2 +- spring-batch-samples/src/main/sql/derby.vpp | 3 +- spring-batch-samples/src/main/sql/hsqldb.vpp | 3 +- .../src/main/sql/init.sql.vpp | 6 +- spring-batch-samples/src/main/sql/mysql.vpp | 4 +- .../src/main/sql/oracle10g.vpp | 2 +- .../src/main/sql/postgresql.vpp | 2 +- .../src/main/sql/sqlserver.vpp | 3 +- spring-batch-samples/src/main/sql/sybase.vpp | 3 +- .../CustomerFilterJobFunctionalTests.java | 2 +- .../sample/common/StagingItemWriterTests.java | 2 +- 27 files changed, 148 insertions(+), 185 deletions(-) delete mode 100644 spring-batch-samples/src/main/resources/data-source-context-init.xml diff --git a/spring-batch-samples/.classpath b/spring-batch-samples/.classpath index 96489ff1c..2daddec39 100644 --- a/spring-batch-samples/.classpath +++ b/spring-batch-samples/.classpath @@ -1,9 +1,9 @@ - + - + diff --git a/spring-batch-samples/.settings/org.springframework.ide.eclipse.core.prefs b/spring-batch-samples/.settings/org.springframework.ide.eclipse.core.prefs index 461d0a98e..e3588417e 100644 --- a/spring-batch-samples/.settings/org.springframework.ide.eclipse.core.prefs +++ b/spring-batch-samples/.settings/org.springframework.ide.eclipse.core.prefs @@ -1,14 +1,14 @@ -#Wed May 27 18:05:53 BST 2009 +#Tue Sep 22 12:31:29 BST 2009 eclipse.preferences.version=1 org.springframework.ide.eclipse.core.builders.enable.aopreferencemodelbuilder=true -org.springframework.ide.eclipse.core.builders.enable.beanmetadatabuilder=false -org.springframework.ide.eclipse.core.builders.enable.osgibundleupdater=true +org.springframework.ide.eclipse.core.builders.enable.beanmetadatabuilder=true +org.springframework.ide.eclipse.core.builders.enable.osgibundleupdater=false org.springframework.ide.eclipse.core.enable.project.preferences=false org.springframework.ide.eclipse.core.validator.enable.com.springsource.platform.ide.manifest.core.manifestvalidator=true org.springframework.ide.eclipse.core.validator.enable.com.springsource.server.ide.manifest.core.manifestvalidator=true org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.ap.quickfix.manifestvalidator=true -org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.server.quickfix.manifestvalidator=true +org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.server.quickfix.manifestvalidator=false org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.beans.core.beansvalidator=true org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.core.springvalidator=false org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.webflow.core.validator=true @@ -40,18 +40,18 @@ org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts. org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.ap.quickfix.importLibraryVersionRule-com.springsource.sts.ap.quickfix.manifestvalidator=true org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.ap.quickfix.importPackageVersionRule-com.springsource.sts.ap.quickfix.manifestvalidator=true org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.ap.quickfix.requireBundleVersionRule-com.springsource.sts.ap.quickfix.manifestvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.AvoidDriverManagerDataSource-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ImportElementsAtTopRulee-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ParentBeanSpecifiesAbstractClassRule-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.RefElementRule-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.TooManyBeansInFileRule-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UnnecessaryValueElementRule-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UseBeanInheritance-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.legacyxmlusage.jndiobjectfactory-com.springsource.sts.bestpractices.beansvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importLibraryVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importPackageVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=true -org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.requireBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=true +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.AvoidDriverManagerDataSource-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ImportElementsAtTopRulee-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ParentBeanSpecifiesAbstractClassRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.RefElementRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.TooManyBeansInFileRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UnnecessaryValueElementRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UseBeanInheritance-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.legacyxmlusage.jndiobjectfactory-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importLibraryVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importPackageVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.requireBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanAlias-org.springframework.ide.eclipse.beans.core.beansvalidator=true org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanClass-org.springframework.ide.eclipse.beans.core.beansvalidator=true org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanConstructorArgument-org.springframework.ide.eclipse.beans.core.beansvalidator=true diff --git a/spring-batch-samples/.springBeans b/spring-batch-samples/.springBeans index 59737c92d..47aea6566 100644 --- a/spring-batch-samples/.springBeans +++ b/spring-batch-samples/.springBeans @@ -1,7 +1,7 @@ 1 - + @@ -15,7 +15,6 @@ src/main/resources/jobs/beanWrapperMapperSampleJob.xml src/main/resources/jobs/adhocLoopJob.xml src/main/resources/jobs/infiniteLoopJob.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/footballJob.xml src/main/resources/jobs/delegatingJob.xml src/main/resources/jobs/parallelJob.xml @@ -71,6 +70,11 @@ src/main/resources/jobs/multilineOrderValidator.xml src/main/resources/jobs/restartFileSampleJob.xml src/main/resources/jobs/taskletJob.xml + src/main/resources/org/springframework/batch/sample/football-job-context.xml + src/main/resources/jobs/groovyJob.xml + src/main/resources/jobs/iosample/jdbcPaging.xml + src/test/resources/org/springframework/batch/sample/GroovyJobFunctionalTests-context.xml + src/test/resources/org/springframework/batch/sample/TaskletJobFunctionalTests-context.xml @@ -88,7 +92,6 @@ src/main/resources/jobs/beanWrapperMapperSampleJob.xml src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -122,7 +125,6 @@ src/main/resources/jobs/infiniteLoopJob.xml src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -133,7 +135,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/multilineJob.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -156,7 +157,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/restartSample.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -169,7 +169,6 @@ src/main/resources/jobs/retrySample.xml src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -180,7 +179,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/tradeJob.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -192,7 +190,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -214,7 +211,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml src/main/resources/jobs/compositeItemWriterSampleJob.xml @@ -227,7 +223,6 @@ src/main/resources/jobs/adhocLoopJob.xml src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -281,7 +276,6 @@ src/main/resources/jobs/customerFilterJob.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -303,7 +297,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -316,7 +309,6 @@ src/main/resources/data-source-context.xml src/main/resources/jobs/skipSampleJob.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/skipSample-job-launcher-context.xml @@ -326,7 +318,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/ioSampleJob.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml src/main/resources/simple-job-launcher-context.xml @@ -340,7 +331,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/iosample/jdbcCursor.xml src/main/resources/jobs/ioSampleJob.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -353,7 +343,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/iosample/multiLine.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml src/main/resources/simple-job-launcher-context.xml @@ -365,7 +354,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/iosample/multiRecordType.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml src/main/resources/simple-job-launcher-context.xml @@ -377,7 +365,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/iosample/jpa.xml src/main/resources/jobs/ioSampleJob.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -399,7 +386,6 @@ src/main/resources/data-source-context.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/iosample/ibatis.xml @@ -419,7 +405,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/multilineOrderJob.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml @@ -434,7 +419,6 @@ false src/main/resources/data-source-context.xml - src/main/resources/data-source-context-init.xml src/main/resources/jobs/restartFileSampleJob.xml src/main/resources/simple-job-launcher-context.xml src/main/resources/org/springframework/batch/sample/config/common-context.xml diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java index c7b5f24e2..76d522f67 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcCustomerDao.java @@ -25,6 +25,7 @@ import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.sample.domain.trade.CustomerDao; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.support.JdbcDaoSupport; +import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; /** * @author Lucas Ward @@ -33,9 +34,15 @@ import org.springframework.jdbc.core.support.JdbcDaoSupport; public class JdbcCustomerDao extends JdbcDaoSupport implements CustomerDao{ private static final String GET_CUSTOMER_BY_NAME = "SELECT ID, NAME, CREDIT from CUSTOMER where NAME = ?"; - private static final String INSERT_CUSTOMER = "INSERT into CUSTOMER(NAME, CREDIT) values(?,?)"; + private static final String INSERT_CUSTOMER = "INSERT into CUSTOMER(ID, NAME, CREDIT) values(?,?,?)"; private static final String UPDATE_CUSTOMER = "UPDATE CUSTOMER set CREDIT = ? where NAME = ?"; + private DataFieldMaxValueIncrementer incrementer; + + public void setIncrementer(DataFieldMaxValueIncrementer incrementer) { + this.incrementer = incrementer; + } + public CustomerCredit getCustomerByName(String name) { @SuppressWarnings("unchecked") @@ -64,7 +71,7 @@ public class JdbcCustomerDao extends JdbcDaoSupport implements CustomerDao{ public void insertCustomer(String name, BigDecimal credit) { - getJdbcTemplate().update(INSERT_CUSTOMER, new Object[]{name, credit}); + getJdbcTemplate().update(INSERT_CUSTOMER, new Object[]{incrementer.nextIntValue(), name, credit}); } public void updateCustomer(String name, BigDecimal credit) { diff --git a/spring-batch-samples/src/main/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-samples/src/main/java/test/jdbc/datasource/DataSourceInitializer.java index 95dbfba9f..c58538cfe 100644 --- a/spring-batch-samples/src/main/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-samples/src/main/java/test/jdbc/datasource/DataSourceInitializer.java @@ -18,6 +18,7 @@ package test.jdbc.datasource; import java.io.IOException; import java.util.List; +import java.util.Arrays; import javax.sql.DataSource; @@ -27,85 +28,67 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.Resource; -import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; -/** - * Wrapper for a {@link DataSource} that can run scripts on start up and shut - * down. Us as a bean definition

- * - * Run this class to initialize a database in a running server process. - * Make sure the server is running first by launching the "hsql-server" from the - * hsql.server project. Then you can right click in Eclipse and - * Run As -> Java Application. Do the same any time you want to wipe the - * database and start again. - * - * @author Dave Syer - * - */ public class DataSourceInitializer implements InitializingBean, DisposableBean { - private static final Log logger = LogFactory.getLog(DataSourceInitializer.class); - private Resource[] initScripts; - private Resource[] destroyScripts; + private Resource destroyScript; private DataSource dataSource; - private boolean ignoreFailedDrop = true; + private boolean initialize = false; + + private Log logger = LogFactory.getLog(getClass()); private static boolean initialized = false; - /** - * Main method as convenient entry point. - * - * @param args - */ - public static void main(String... args) { - new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(DataSourceInitializer.class, - DataSourceInitializer.class.getSimpleName() + "-context.xml")); + public void setInitialize(boolean initialize) { + this.initialize = initialize; } - public void destroy() { - if (destroyScripts==null) return; - for (int i = 0; i < destroyScripts.length; i++) { - Resource destroyScript = initScripts[i]; - try { + public void destroy() throws Exception { + if (!initialized) { + return; + } + try { + if (destroyScript!=null) { doExecuteScript(destroyScript); - } - catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.warn("Could not execute destroy script [" + destroyScript + "]", e); - } - else { - logger.warn("Could not execute destroy script [" + destroyScript + "]"); - } + initialized = false; + } + } + catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.warn("Could not execute destroy script [" + destroyScript + "]", e); + } + else { + logger.warn("Could not execute destroy script [" + destroyScript + "]"); } } - initialized = false; } public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource); - initialize(); - } - - private void initialize() { - if (!initialized) { - destroy(); + logger.info("Initializing with scripts: "+Arrays.asList(initScripts)); + if (!initialized && initialize) { + try { + doExecuteScript(destroyScript); + } + catch (Exception e) { + logger.debug("Could not execute destroy script [" + destroyScript + "]", e); + } if (initScripts != null) { for (int i = 0; i < initScripts.length; i++) { Resource initScript = initScripts[i]; + logger.info("Executing init script: "+initScript); doExecuteScript(initScript); } } @@ -133,17 +116,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { for (int i = 0; i < scripts.length; i++) { String script = scripts[i].trim(); if (StringUtils.hasText(script)) { - try { - jdbcTemplate.execute(script); - } - catch (DataAccessException e) { - if (ignoreFailedDrop && script.toLowerCase().startsWith("drop")) { - logger.debug("DROP script failed (ignoring): " + script); - } - else { - throw e; - } - } + jdbcTemplate.execute(scripts[i]); } } return null; @@ -163,20 +136,20 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { return buffer.toString(); } + public Class getObjectType() { + return DataSource.class; + } + public void setInitScripts(Resource[] initScripts) { this.initScripts = initScripts; } - public void setDestroyScripts(Resource[] destroyScripts) { - this.destroyScripts = destroyScripts; + public void setDestroyScript(Resource destroyScript) { + this.destroyScript = destroyScript; } public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } - public void setIgnoreFailedDrop(boolean ignoreFailedDrop) { - this.ignoreFailedDrop = ignoreFailedDrop; - } - } diff --git a/spring-batch-samples/src/main/resources/batch-hsql.properties b/spring-batch-samples/src/main/resources/batch-hsql.properties index d68b8457e..5ff3505ae 100644 --- a/spring-batch-samples/src/main/resources/batch-hsql.properties +++ b/spring-batch-samples/src/main/resources/batch-hsql.properties @@ -7,16 +7,11 @@ batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true # batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples batch.jdbc.user=sa batch.jdbc.password= -batch.schema= -batch.jndi.name= -batch.naming.factory.initial= -batch.naming.provider.url= -batch.schema.script=schema-hsqldb.sql -batch.drop.script=schema-drop-hsqldb.sql -batch.business.schema.script=business-schema-hsqldb.sql +batch.jdbc.testWhileIdle=false +batch.jdbc.validationQuery= +batch.schema.script=classpath:/schema-hsqldb.sql +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.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler - -# Bean Properties for override -# when not using sequences: -incrementerParent.columnName=ID +batch.database.incrementer.parent=columnIncrementerParent +batch.grid.size=2 diff --git a/spring-batch-samples/src/main/resources/batch-mysql.properties b/spring-batch-samples/src/main/resources/batch-mysql.properties index f481d74a7..be6ba495a 100644 --- a/spring-batch-samples/src/main/resources/batch-mysql.properties +++ b/spring-batch-samples/src/main/resources/batch-mysql.properties @@ -2,18 +2,14 @@ # for MySQL: batch.jdbc.driver=com.mysql.jdbc.Driver batch.jdbc.url=jdbc:mysql://localhost/test -batch.jdbc.user=root -batch.jdbc.password=root -batch.schema= -batch.jndi.name= -batch.naming.factory.initial= -batch.naming.provider.url= -batch.schema.script=schema-mysql.sql -batch.drop.script=schema-drop-mysql.sql -batch.business.schema.script=business-schema-mysql.sql +batch.jdbc.user=test +batch.jdbc.password=test +batch.jdbc.testWhileIdle=true +batch.jdbc.validationQuery=SELECT 1 +batch.drop.script=classpath:schema-drop-mysql.sql +batch.schema.script=classpath:schema-mysql.sql +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.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler - -# Bean Properties for override -# when not using sequences: -incrementerParent.columnName=ID +batch.database.incrementer.parent=columnIncrementerParent +batch.grid.size=50 diff --git a/spring-batch-samples/src/main/resources/business-schema-derby.sql b/spring-batch-samples/src/main/resources/business-schema-derby.sql index 133b6c3f4..61f36fdb5 100644 --- a/spring-batch-samples/src/main/resources/business-schema-derby.sql +++ b/spring-batch-samples/src/main/resources/business-schema-derby.sql @@ -13,8 +13,11 @@ DROP TABLE ERROR_LOG ; -- Autogenerated: do not edit this file CREATE TABLE CUSTOMER_SEQ (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); +INSERT INTO CUSTOMER_SEQ (ID) values (4); CREATE TABLE BATCH_STAGING_SEQ (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); +INSERT INTO BATCH_STAGING_SEQ (ID) values (0); CREATE TABLE TRADE_SEQ (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); +INSERT INTO TRADE_SEQ (ID) values (0); CREATE TABLE BATCH_STAGING ( ID BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, diff --git a/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql b/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql index d6a21cab5..39845bbfa 100644 --- a/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql +++ b/spring-batch-samples/src/main/resources/business-schema-hsqldb.sql @@ -15,12 +15,15 @@ DROP TABLE ERROR_LOG IF EXISTS; CREATE TABLE CUSTOMER_SEQ ( ID BIGINT IDENTITY ); +INSERT INTO CUSTOMER_SEQ (ID) values (4); CREATE TABLE BATCH_STAGING_SEQ ( ID BIGINT IDENTITY ); +INSERT INTO BATCH_STAGING_SEQ (ID) values (0); CREATE TABLE TRADE_SEQ ( ID BIGINT IDENTITY ); +INSERT INTO TRADE_SEQ (ID) values (0); CREATE TABLE BATCH_STAGING ( ID BIGINT IDENTITY NOT NULL PRIMARY KEY , diff --git a/spring-batch-samples/src/main/resources/business-schema-mysql.sql b/spring-batch-samples/src/main/resources/business-schema-mysql.sql index cb3c76c3e..86164e3e9 100644 --- a/spring-batch-samples/src/main/resources/business-schema-mysql.sql +++ b/spring-batch-samples/src/main/resources/business-schema-mysql.sql @@ -13,7 +13,7 @@ DROP TABLE IF EXISTS ERROR_LOG ; -- Autogenerated: do not edit this file CREATE TABLE CUSTOMER_SEQ (ID BIGINT NOT NULL) type=MYISAM; -INSERT INTO CUSTOMER_SEQ values(0); +INSERT INTO CUSTOMER_SEQ values(4); CREATE TABLE BATCH_STAGING_SEQ (ID BIGINT NOT NULL) type=MYISAM; INSERT INTO BATCH_STAGING_SEQ values(0); CREATE TABLE TRADE_SEQ (ID BIGINT NOT NULL) type=MYISAM; diff --git a/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql b/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql index 4d910d6c1..6b90c2ff6 100644 --- a/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql +++ b/spring-batch-samples/src/main/resources/business-schema-sqlserver.sql @@ -13,8 +13,11 @@ DROP TABLE ERROR_LOG ; -- Autogenerated: do not edit this file CREATE TABLE CUSTOMER_SEQ (ID BIGINT IDENTITY); +INSERT INTO CUSTOMER_SEQ (ID) values (4); CREATE TABLE BATCH_STAGING_SEQ (ID BIGINT IDENTITY); +INSERT INTO BATCH_STAGING_SEQ (ID) values (0); CREATE TABLE TRADE_SEQ (ID BIGINT IDENTITY); +INSERT INTO TRADE_SEQ (ID) values (0); CREATE TABLE BATCH_STAGING ( ID BIGINT NOT NULL PRIMARY KEY , diff --git a/spring-batch-samples/src/main/resources/business-schema-sybase.sql b/spring-batch-samples/src/main/resources/business-schema-sybase.sql index 3e1d62f20..7400cca1d 100644 --- a/spring-batch-samples/src/main/resources/business-schema-sybase.sql +++ b/spring-batch-samples/src/main/resources/business-schema-sybase.sql @@ -13,8 +13,11 @@ DROP TABLE ERROR_LOG ; -- Autogenerated: do not edit this file CREATE TABLE CUSTOMER_SEQ (ID BIGINT IDENTITY); +INSERT INTO CUSTOMER_SEQ (ID) values (4); CREATE TABLE BATCH_STAGING_SEQ (ID BIGINT IDENTITY); +INSERT INTO BATCH_STAGING_SEQ (ID) values (0); CREATE TABLE TRADE_SEQ (ID BIGINT IDENTITY); +INSERT INTO TRADE_SEQ (ID) values (0); CREATE TABLE BATCH_STAGING ( ID BIGINT NOT NULL PRIMARY KEY , diff --git a/spring-batch-samples/src/main/resources/data-source-context-init.xml b/spring-batch-samples/src/main/resources/data-source-context-init.xml deleted file mode 100644 index f38b88e12..000000000 --- a/spring-batch-samples/src/main/resources/data-source-context-init.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - ${batch.drop.script} - ${batch.schema.script} - ${batch.business.schema.script} - - - - - \ No newline at end of file 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 6b1cb4690..0604682f4 100644 --- a/spring-batch-samples/src/main/resources/data-source-context.xml +++ b/spring-batch-samples/src/main/resources/data-source-context.xml @@ -5,7 +5,17 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"> - + + + + + + ${batch.drop.script} + ${batch.schema.script} + ${batch.business.schema.script} + + + @@ -45,11 +55,13 @@ - - - + - + + + + + diff --git a/spring-batch-samples/src/main/resources/jobs/customerFilterJob.xml b/spring-batch-samples/src/main/resources/jobs/customerFilterJob.xml index 9721aac63..ed3af525e 100644 --- a/spring-batch-samples/src/main/resources/jobs/customerFilterJob.xml +++ b/spring-batch-samples/src/main/resources/jobs/customerFilterJob.xml @@ -24,7 +24,7 @@ - + @@ -66,10 +66,11 @@ - - - - + + + + + diff --git a/spring-batch-samples/src/main/resources/staging-test-context.xml b/spring-batch-samples/src/main/resources/staging-test-context.xml index 374d4bbe1..a1019a772 100644 --- a/spring-batch-samples/src/main/resources/staging-test-context.xml +++ b/spring-batch-samples/src/main/resources/staging-test-context.xml @@ -1,25 +1,21 @@ - - + - - + + - + diff --git a/spring-batch-samples/src/main/sql/db2.vpp b/spring-batch-samples/src/main/sql/db2.vpp index 56bd1c6e3..4e1c4bdbb 100644 --- a/spring-batch-samples/src/main/sql/db2.vpp +++ b/spring-batch-samples/src/main/sql/db2.vpp @@ -1,2 +1,2 @@ -#macro (sequence $name)CREATE SEQUENCE ${name}; +#macro (sequence $name $value)CREATE SEQUENCE ${name}; #end diff --git a/spring-batch-samples/src/main/sql/derby.vpp b/spring-batch-samples/src/main/sql/derby.vpp index 95d9c397a..c5c1bd4f9 100644 --- a/spring-batch-samples/src/main/sql/derby.vpp +++ b/spring-batch-samples/src/main/sql/derby.vpp @@ -1,2 +1,3 @@ -#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); +#macro (sequence $name $value)CREATE TABLE ${name} (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); +INSERT INTO ${name} (ID) values (${value}); #end diff --git a/spring-batch-samples/src/main/sql/hsqldb.vpp b/spring-batch-samples/src/main/sql/hsqldb.vpp index 9fbc68564..d70c15a1e 100644 --- a/spring-batch-samples/src/main/sql/hsqldb.vpp +++ b/spring-batch-samples/src/main/sql/hsqldb.vpp @@ -1,4 +1,5 @@ -#macro (sequence $name)CREATE TABLE ${name} ( +#macro (sequence $name $value)CREATE TABLE ${name} ( ID BIGINT IDENTITY ); +INSERT INTO ${name} (ID) values (${value}); #end diff --git a/spring-batch-samples/src/main/sql/init.sql.vpp b/spring-batch-samples/src/main/sql/init.sql.vpp index a818d73eb..af4836a84 100644 --- a/spring-batch-samples/src/main/sql/init.sql.vpp +++ b/spring-batch-samples/src/main/sql/init.sql.vpp @@ -1,8 +1,8 @@ -- Autogenerated: do not edit this file -#sequence( "CUSTOMER_SEQ" ) -#sequence( "BATCH_STAGING_SEQ" ) -#sequence( "TRADE_SEQ" ) +#sequence( "CUSTOMER_SEQ" 4 ) +#sequence( "BATCH_STAGING_SEQ" 0 ) +#sequence( "TRADE_SEQ" 0 ) CREATE TABLE BATCH_STAGING ( ID ${BIGINT} $!{IDENTITY} NOT NULL PRIMARY KEY $!{GENERATED}, diff --git a/spring-batch-samples/src/main/sql/mysql.vpp b/spring-batch-samples/src/main/sql/mysql.vpp index 1812fa977..9897be54e 100644 --- a/spring-batch-samples/src/main/sql/mysql.vpp +++ b/spring-batch-samples/src/main/sql/mysql.vpp @@ -1,3 +1,3 @@ -#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT NOT NULL) type=MYISAM; -INSERT INTO ${name} values(0); +#macro (sequence $name $value)CREATE TABLE ${name} (ID BIGINT NOT NULL) type=MYISAM; +INSERT INTO ${name} values(${value}); #end diff --git a/spring-batch-samples/src/main/sql/oracle10g.vpp b/spring-batch-samples/src/main/sql/oracle10g.vpp index 56bd1c6e3..4e1c4bdbb 100644 --- a/spring-batch-samples/src/main/sql/oracle10g.vpp +++ b/spring-batch-samples/src/main/sql/oracle10g.vpp @@ -1,2 +1,2 @@ -#macro (sequence $name)CREATE SEQUENCE ${name}; +#macro (sequence $name $value)CREATE SEQUENCE ${name}; #end diff --git a/spring-batch-samples/src/main/sql/postgresql.vpp b/spring-batch-samples/src/main/sql/postgresql.vpp index 56bd1c6e3..4e1c4bdbb 100644 --- a/spring-batch-samples/src/main/sql/postgresql.vpp +++ b/spring-batch-samples/src/main/sql/postgresql.vpp @@ -1,2 +1,2 @@ -#macro (sequence $name)CREATE SEQUENCE ${name}; +#macro (sequence $name $value)CREATE SEQUENCE ${name}; #end diff --git a/spring-batch-samples/src/main/sql/sqlserver.vpp b/spring-batch-samples/src/main/sql/sqlserver.vpp index 1c798e451..12e5ad571 100644 --- a/spring-batch-samples/src/main/sql/sqlserver.vpp +++ b/spring-batch-samples/src/main/sql/sqlserver.vpp @@ -1,3 +1,4 @@ -#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT IDENTITY); +#macro (sequence $name $value)CREATE TABLE ${name} (ID BIGINT IDENTITY); +INSERT INTO ${name} (ID) values (${value}); #end #macro (notnull $name $type)ALTER COLUMN ${name} ${type} NOT NULL#end diff --git a/spring-batch-samples/src/main/sql/sybase.vpp b/spring-batch-samples/src/main/sql/sybase.vpp index 1c798e451..12e5ad571 100644 --- a/spring-batch-samples/src/main/sql/sybase.vpp +++ b/spring-batch-samples/src/main/sql/sybase.vpp @@ -1,3 +1,4 @@ -#macro (sequence $name)CREATE TABLE ${name} (ID BIGINT IDENTITY); +#macro (sequence $name $value)CREATE TABLE ${name} (ID BIGINT IDENTITY); +INSERT INTO ${name} (ID) values (${value}); #end #macro (notnull $name $type)ALTER COLUMN ${name} ${type} NOT NULL#end diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java index 0954403c0..9038b7d60 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/CustomerFilterJobFunctionalTests.java @@ -40,7 +40,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration() +@ContextConfiguration public class CustomerFilterJobFunctionalTests extends AbstractJobTests { private static final String GET_CUSTOMERS = "select NAME, CREDIT from CUSTOMER order by NAME"; diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java index f8d1f3185..c93369826 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/common/StagingItemWriterTests.java @@ -35,7 +35,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration() +@ContextConfiguration public class StagingItemWriterTests { private SimpleJdbcTemplate simpleJdbcTemplate;