diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java index 8678052145..57f990bc21 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerIntegrationTests.java @@ -20,10 +20,8 @@ import javax.sql.DataSource; -import org.apache.commons.dbcp2.BasicDataSource; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import test.jdbc.datasource.DataSourceInitializer; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.Job; @@ -56,8 +54,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.jdbc.support.JdbcTransactionManager; @@ -121,23 +117,11 @@ public SimpleFlow simpleFlow() { } @Bean - public BasicDataSource dataSource() { - BasicDataSource dataSource = new BasicDataSource(); - dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); - dataSource.setUrl("jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true;hsqldb.tx=mvcc"); - dataSource.setUsername("sa"); - dataSource.setPassword(""); - return dataSource; - } - - @Bean - public DataSourceInitializer dataSourceInitializer() { - DataSourceInitializer dataSourceInitializer = new DataSourceInitializer(); - dataSourceInitializer.setDataSource(dataSource()); - dataSourceInitializer.setInitScripts( - new Resource[] { new ClassPathResource("org/springframework/batch/core/schema-drop-hsqldb.sql"), - new ClassPathResource("org/springframework/batch/core/schema-hsqldb.sql") }); - return dataSourceInitializer; + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); } @Bean diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java index c3a1cbe11c..3af2f3cde6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/resource/JdbcCursorItemReaderPreparedStatementIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2022 the original author or authors. + * Copyright 2008-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -@SpringJUnitConfig(locations = "/org/springframework/batch/core/repository/dao/data-source-context.xml") +@SpringJUnitConfig(locations = "classpath:data-source-context.xml") public class JdbcCursorItemReaderPreparedStatementIntegrationTests { JdbcCursorItemReader itemReader; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/RestartInPriorStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/RestartInPriorStepTests.java index 4345d3177a..f0816f42ca 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/RestartInPriorStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/RestartInPriorStepTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.step; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; @@ -26,7 +27,6 @@ import org.springframework.batch.core.job.flow.FlowExecutionStatus; import org.springframework.batch.core.job.flow.JobExecutionDecider; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; @@ -45,12 +45,9 @@ */ @SpringJUnitConfig // FIXME this test fails when upgrading the batch xsd from 2.2 to 3.0: -// https://github.com/spring-projects/spring-batch/issues/1287 +@Disabled("https://github.com/spring-projects/spring-batch/issues/1287") class RestartInPriorStepTests { - @Autowired - private JobRepository jobRepository; - @Autowired private JobLauncher jobLauncher; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java index 88f430e5a7..2a69fc1d36 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java @@ -110,7 +110,7 @@ public FaultTolerantStepFactoryBeanTests() throws Exception { void setUp() throws Exception { EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder().generateUniqueName(true) .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") - .addScript("/org/springframework/batch/core/schema-hsqldb-extended.sql") + .addScript("/schema-hsqldb-extended.sql") .build(); JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanUnexpectedRollbackTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanUnexpectedRollbackTests.java index 20c263f3a4..e8f64b6cb3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanUnexpectedRollbackTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanUnexpectedRollbackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 the original author or authors. + * Copyright 2010-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ /** * Tests for {@link FaultTolerantStepFactoryBean} with unexpected rollback. */ -@SpringJUnitConfig(locations = "classpath:/org/springframework/batch/core/repository/dao/data-source-context.xml") +@SpringJUnitConfig(locations = "classpath:data-source-context.xml") class FaultTolerantStepFactoryBeanUnexpectedRollbackTests { protected final Log logger = LogFactory.getLog(getClass()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/AbstractIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/AbstractIntegrationTests.java deleted file mode 100644 index a487985a43..0000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/AbstractIntegrationTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2006-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.test; - -import javax.sql.DataSource; - -import org.junit.jupiter.api.BeforeEach; - -import org.springframework.core.io.ClassPathResource; -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; - -/** - * @author Mahmoud Ben Hassine - */ -public class AbstractIntegrationTests { - - protected DataSource dataSource; - - @BeforeEach - void setUp() { - ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); - databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-drop-hsqldb.sql")); - databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-hsqldb.sql")); - databasePopulator.addScript(new ClassPathResource("/business-schema-hsqldb.sql")); - databasePopulator.execute(this.dataSource); - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobIntegrationTests.java index 362c281872..03c6ab6330 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.sql.DataSource; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; @@ -29,7 +27,6 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.test.AbstractIntegrationTests; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @@ -39,7 +36,7 @@ * */ @SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/META-INF/batch/footballJob.xml" }) -public class FootballJobIntegrationTests extends AbstractIntegrationTests { +public class FootballJobIntegrationTests { /** Logger */ private final Log logger = LogFactory.getLog(getClass()); @@ -50,11 +47,6 @@ public class FootballJobIntegrationTests extends AbstractIntegrationTests { @Autowired private Job job; - @Autowired - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } - @Test void testLaunchJob() throws Exception { JobExecution execution = jobLauncher.run(job, diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobSkipIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobSkipIntegrationTests.java index 9b4736ba4a..ac63f1209d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobSkipIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/FootballJobSkipIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.sql.DataSource; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; @@ -29,10 +27,7 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.test.AbstractIntegrationTests; -import org.springframework.batch.support.DatabaseType; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** @@ -41,40 +36,19 @@ * */ @SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/META-INF/batch/footballSkipJob.xml" }) -public class FootballJobSkipIntegrationTests extends AbstractIntegrationTests { +public class FootballJobSkipIntegrationTests { /** Logger */ private final Log logger = LogFactory.getLog(getClass()); - private JdbcTemplate jdbcTemplate; - @Autowired private JobLauncher jobLauncher; @Autowired private Job job; - private DatabaseType databaseType; - - @Autowired - public void setDataSource(DataSource dataSource) throws Exception { - this.dataSource = dataSource; - this.jdbcTemplate = new JdbcTemplate(dataSource); - databaseType = DatabaseType.fromMetaData(dataSource); - } - @Test void testLaunchJob() throws Exception { - try { - if (databaseType == DatabaseType.POSTGRES || databaseType == DatabaseType.ORACLE) { - // Extra special test for these platforms (would have failed - // the job with UNKNOWN status in Batch 2.0): - jdbcTemplate.update("SET CONSTRAINTS ALL DEFERRED"); - } - } - catch (Exception e) { - // Ignore (wrong platform) - } JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("skip.limit", 0L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java index 66a039616d..6afbdd6de7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/JdbcJobRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ import java.util.List; import java.util.Set; -import javax.sql.DataSource; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.BeforeEach; @@ -34,7 +32,6 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.test.AbstractIntegrationTests; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @@ -46,7 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml" }) -class JdbcJobRepositoryTests extends AbstractIntegrationTests { +class JdbcJobRepositoryTests { private JobSupport job; @@ -56,6 +53,7 @@ class JdbcJobRepositoryTests extends AbstractIntegrationTests { private final List list = new ArrayList<>(); + @Autowired private JdbcTemplate jdbcTemplate; @Autowired @@ -64,16 +62,12 @@ class JdbcJobRepositoryTests extends AbstractIntegrationTests { /** Logger */ private final Log logger = LogFactory.getLog(getClass()); - @Autowired - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - this.jdbcTemplate = new JdbcTemplate(dataSource); - } - @BeforeEach void onSetUpInTransaction() { job = new JobSupport("test-job"); job.setRestartable(true); + JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION_CONTEXT", + "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_EXECUTION_PARAMS", "BATCH_JOB_INSTANCE"); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/TimeoutJobIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/TimeoutJobIntegrationTests.java index 50e9464632..3a28174745 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/TimeoutJobIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/TimeoutJobIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,29 +15,20 @@ */ package org.springframework.batch.core.test.timeout; -import javax.sql.DataSource; - import static org.junit.jupiter.api.Assertions.assertEquals; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.test.AbstractIntegrationTests; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @SpringJUnitConfig(locations = { "/simple-job-launcher-context.xml", "/META-INF/batch/timeoutJob.xml" }) -public class TimeoutJobIntegrationTests extends AbstractIntegrationTests { - - /** Logger */ - @SuppressWarnings("unused") - private final Log logger = LogFactory.getLog(getClass()); +public class TimeoutJobIntegrationTests { @Autowired private JobLauncher jobLauncher; @@ -50,11 +41,6 @@ public class TimeoutJobIntegrationTests extends AbstractIntegrationTests { @Qualifier("taskletTimeoutJob") private Job taskletTimeoutJob; - @Autowired - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } - @Test void testChunkTimeoutShouldFail() throws Exception { JobExecution execution = jobLauncher.run(chunkTimeoutJob, diff --git a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java deleted file mode 100644 index d723bf9b2e..0000000000 --- a/spring-batch-core/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2006-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package test.jdbc.datasource; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.beans.factory.BeanInitializationException; -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.support.JdbcTransactionManager; -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 - * @author Mahmoud Ben Hassine - * - */ -public class DataSourceInitializer implements InitializingBean { - - private static final Log logger = LogFactory.getLog(DataSourceInitializer.class); - - private Resource[] initScripts; - - private DataSource dataSource; - - private boolean ignoreFailedDrop = true; - - private boolean initialized = false; - - /** - * Main method as convenient entry point. - * @param args - */ - @SuppressWarnings("resource") - public static void main(String... args) { - new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(DataSourceInitializer.class, - DataSourceInitializer.class.getSimpleName() + "-context.xml")); - } - - @Override - public void afterPropertiesSet() throws Exception { - Assert.state(dataSource != null, "A DataSource is required"); - initialize(); - } - - private void initialize() { - if (!initialized) { - if (initScripts != null) { - for (Resource script : initScripts) { - doExecuteScript(script); - } - } - initialized = true; - } - } - - @SuppressWarnings({ "unchecked" }) - private void doExecuteScript(final Resource scriptResource) { - if (scriptResource == null || !scriptResource.exists()) { - throw new IllegalArgumentException("Script resource is null or does not exist"); - } - - TransactionTemplate transactionTemplate = new TransactionTemplate(new JdbcTransactionManager(dataSource)); - transactionTemplate.execute((TransactionCallback) status -> { - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - String[] scripts; - try { - scripts = StringUtils.delimitedListToStringArray( - stripComments(IOUtils.readLines(scriptResource.getInputStream(), StandardCharsets.UTF_8)), ";"); - } - catch (IOException e) { - throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); - } - for (String s : scripts) { - String script = s.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; - } - } - } - } - return null; - }); - - } - - private String stripComments(List list) { - StringBuilder buffer = new StringBuilder(); - for (String line : list) { - if (!line.startsWith("//") && !line.startsWith("--")) { - buffer.append(line).append("\n"); - } - } - return buffer.toString(); - } - - public void setInitScripts(Resource[] initScripts) { - this.initScripts = initScripts; - } - - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } - - public void setIgnoreFailedDrop(boolean ignoreFailedDrop) { - this.ignoreFailedDrop = ignoreFailedDrop; - } - -} diff --git a/spring-batch-core/src/test/resources/META-INF/batch/footballJob.xml b/spring-batch-core/src/test/resources/META-INF/batch/footballJob.xml index a566e3abe3..47885c998a 100644 --- a/spring-batch-core/src/test/resources/META-INF/batch/footballJob.xml +++ b/spring-batch-core/src/test/resources/META-INF/batch/footballJob.xml @@ -1,11 +1,12 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> + + + + @@ -80,7 +81,7 @@ - + diff --git a/spring-batch-core/src/test/resources/META-INF/batch/footballSkipJob.xml b/spring-batch-core/src/test/resources/META-INF/batch/footballSkipJob.xml index 1381281abc..47999e601b 100644 --- a/spring-batch-core/src/test/resources/META-INF/batch/footballSkipJob.xml +++ b/spring-batch-core/src/test/resources/META-INF/batch/footballSkipJob.xml @@ -1,9 +1,12 @@ - + + + + + @@ -99,7 +102,7 @@ - + diff --git a/spring-batch-core/src/test/resources/META-INF/batch/parallelJob.xml b/spring-batch-core/src/test/resources/META-INF/batch/parallelJob.xml index aa1368a71a..217fb90844 100644 --- a/spring-batch-core/src/test/resources/META-INF/batch/parallelJob.xml +++ b/spring-batch-core/src/test/resources/META-INF/batch/parallelJob.xml @@ -1,11 +1,12 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> + + + + @@ -87,7 +88,7 @@ - + diff --git a/spring-batch-core/src/test/resources/applicationContext-test2.xml b/spring-batch-core/src/test/resources/applicationContext-test2.xml index 7167d05067..fe27a3211d 100644 --- a/spring-batch-core/src/test/resources/applicationContext-test2.xml +++ b/spring-batch-core/src/test/resources/applicationContext-test2.xml @@ -5,6 +5,8 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> + + @@ -51,17 +53,6 @@ - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/batch-derby.properties b/spring-batch-core/src/test/resources/batch-derby.properties deleted file mode 100644 index 251e37c728..0000000000 --- a/spring-batch-core/src/test/resources/batch-derby.properties +++ /dev/null @@ -1,17 +0,0 @@ -# Placeholders batch.* -# for Derby: -batch.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver -batch.jdbc.url=jdbc:derby:target/derby-home/test;create=true -batch.jdbc.user=sa -batch.jdbc.password= -batch.jdbc.testWhileIdle=false -batch.jdbc.validationQuery= -batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-derby.sql -batch.schema.script=classpath:/org/springframework/batch/core/schema-derby.sql -batch.business.schema.script=business-schema-derby.sql -batch.data.source.init=true -batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer -batch.database.incrementer.parent=columnIncrementerParent -batch.grid.size=2 -batch.verify.cursor.position=false -batch.jdbc.validationQuery=values 1 diff --git a/spring-batch-core/src/test/resources/batch-hsql.properties b/spring-batch-core/src/test/resources/batch-hsql.properties deleted file mode 100644 index fefbc812fd..0000000000 --- a/spring-batch-core/src/test/resources/batch-hsql.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Placeholders batch.* -# for HSQLDB: -batch.jdbc.driver=org.hsqldb.jdbcDriver -batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true;hsqldb.tx=mvcc -# use this one for a separate server process so you can inspect the results -# (or add it to system properties with -D to override at run time). -# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples -batch.jdbc.user=sa -batch.jdbc.password= -batch.jdbc.testWhileIdle=false -batch.jdbc.validationQuery= -batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-hsqldb.sql -batch.schema.script=classpath:/org/springframework/batch/core/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.database.incrementer.parent=columnIncrementerParent -batch.grid.size=2 -batch.verify.cursor.position=true -batch.jdbc.validationQuery=SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS -batch.table.prefix=BATCH_ diff --git a/spring-batch-core/src/test/resources/batch-mysql.properties b/spring-batch-core/src/test/resources/batch-mysql.properties deleted file mode 100644 index 1c157a6ed5..0000000000 --- a/spring-batch-core/src/test/resources/batch-mysql.properties +++ /dev/null @@ -1,14 +0,0 @@ -# Placeholders batch.* -# 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.script=classpath:/org/springframework/batch/core/schema-mysql.sql -batch.business.schema.script=classpath:/business-schema-mysql.sql -batch.data.source.init=false -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.verify.cursor.position=true -batch.jdbc.validationQuery=SELECT 1 diff --git a/spring-batch-core/src/test/resources/batch-postgres.properties b/spring-batch-core/src/test/resources/batch-postgres.properties deleted file mode 100644 index 32c580e59b..0000000000 --- a/spring-batch-core/src/test/resources/batch-postgres.properties +++ /dev/null @@ -1,17 +0,0 @@ -# Placeholders batch.* -# for Postgres: -batch.jdbc.driver=org.postgresql.Driver -batch.jdbc.url=jdbc:postgresql://localhost/test -batch.jdbc.user=test -batch.jdbc.password=test -batch.jdbc.testWhileIdle=false -batch.jdbc.validationQuery= -batch.schema.script=classpath:/org/springframework/batch/core/schema-postgresql.sql -batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-postgresql.sql -batch.business.schema.script=classpath:/business-schema-postgresql.sql -batch.data.source.init=true -batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer -batch.database.incrementer.parent=sequenceIncrementerParent -batch.grid.size=2 -batch.verify.cursor.position=true -batch.jdbc.validationQuery=SELECT 1 diff --git a/spring-batch-core/src/test/resources/business-schema-derby.sql b/spring-batch-core/src/test/resources/business-schema-derby.sql deleted file mode 100644 index 3ddc496b04..0000000000 --- a/spring-batch-core/src/test/resources/business-schema-derby.sql +++ /dev/null @@ -1,96 +0,0 @@ --- Autogenerated: do not edit this file -DROP TABLE BATCH_STAGING_SEQ ; -DROP TABLE TRADE_SEQ ; -DROP TABLE CUSTOMER_SEQ ; -DROP TABLE BATCH_STAGING ; -DROP TABLE TRADE ; -DROP TABLE CUSTOMER ; -DROP TABLE PLAYERS ; -DROP TABLE GAMES ; -DROP TABLE PLAYER_SUMMARY ; -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 (5); -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, - JOB_ID BIGINT NOT NULL, - VALUE BLOB NOT NULL, - PROCESSED CHAR(1) NOT NULL -) ; - -CREATE TABLE TRADE ( - ID BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, - VERSION BIGINT , - ISIN VARCHAR(45) NOT NULL, - QUANTITY BIGINT , - PRICE DECIMAL(8,2) , - CUSTOMER VARCHAR(45) -) ; - -CREATE TABLE CUSTOMER ( - ID BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, - VERSION BIGINT , - NAME VARCHAR(45) , - CREDIT DECIMAL(10,2) -) ; - -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (1, 0, 'customer1', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (2, 0, 'customer2', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (3, 0, 'customer3', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (4, 0, 'customer4', 100000); - -CREATE TABLE PLAYERS ( - PLAYER_ID CHAR(8) NOT NULL PRIMARY KEY, - LAST_NAME VARCHAR(35) NOT NULL, - FIRST_NAME VARCHAR(25) NOT NULL, - POS VARCHAR(10) , - YEAR_OF_BIRTH BIGINT NOT NULL, - YEAR_DRAFTED BIGINT NOT NULL -) ; - -CREATE TABLE GAMES ( - PLAYER_ID CHAR(8) NOT NULL, - YEAR_NO BIGINT NOT NULL, - TEAM CHAR(3) NOT NULL, - WEEK BIGINT NOT NULL, - OPPONENT CHAR(3) , - COMPLETES BIGINT , - ATTEMPTS BIGINT , - PASSING_YARDS BIGINT , - PASSING_TD BIGINT , - INTERCEPTIONS BIGINT , - RUSHES BIGINT , - RUSH_YARDS BIGINT , - RECEPTIONS BIGINT , - RECEPTIONS_YARDS BIGINT , - TOTAL_TD BIGINT -) ; - -CREATE TABLE PLAYER_SUMMARY ( - ID CHAR(8) NOT NULL, - YEAR_NO BIGINT NOT NULL, - COMPLETES BIGINT NOT NULL , - ATTEMPTS BIGINT NOT NULL , - PASSING_YARDS BIGINT NOT NULL , - PASSING_TD BIGINT NOT NULL , - INTERCEPTIONS BIGINT NOT NULL , - RUSHES BIGINT NOT NULL , - RUSH_YARDS BIGINT NOT NULL , - RECEPTIONS BIGINT NOT NULL , - RECEPTIONS_YARDS BIGINT NOT NULL , - TOTAL_TD BIGINT NOT NULL -) ; - -CREATE TABLE ERROR_LOG ( - JOB_NAME CHAR(20) , - STEP_NAME CHAR(20) , - MESSAGE VARCHAR(300) NOT NULL -) ; diff --git a/spring-batch-core/src/test/resources/business-schema-mysql.sql b/spring-batch-core/src/test/resources/business-schema-mysql.sql deleted file mode 100644 index 99fd85c657..0000000000 --- a/spring-batch-core/src/test/resources/business-schema-mysql.sql +++ /dev/null @@ -1,96 +0,0 @@ --- Autogenerated: do not edit this file -DROP TABLE IF EXISTS BATCH_STAGING_SEQ ; -DROP TABLE IF EXISTS TRADE_SEQ ; -DROP TABLE IF EXISTS CUSTOMER_SEQ ; -DROP TABLE IF EXISTS BATCH_STAGING ; -DROP TABLE IF EXISTS TRADE ; -DROP TABLE IF EXISTS CUSTOMER ; -DROP TABLE IF EXISTS PLAYERS ; -DROP TABLE IF EXISTS GAMES ; -DROP TABLE IF EXISTS PLAYER_SUMMARY ; -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(5); -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; -INSERT INTO TRADE_SEQ values(0); - -CREATE TABLE BATCH_STAGING ( - ID BIGINT NOT NULL PRIMARY KEY , - JOB_ID BIGINT NOT NULL, - VALUE BLOB NOT NULL, - PROCESSED CHAR(1) NOT NULL -) type=InnoDB; - -CREATE TABLE TRADE ( - ID BIGINT NOT NULL PRIMARY KEY , - VERSION BIGINT , - ISIN VARCHAR(45) NOT NULL, - QUANTITY BIGINT , - PRICE DECIMAL(8,2) , - CUSTOMER VARCHAR(45) -) type=InnoDB; - -CREATE TABLE CUSTOMER ( - ID BIGINT NOT NULL PRIMARY KEY , - VERSION BIGINT , - NAME VARCHAR(45) , - CREDIT DECIMAL(10,2) -) type=InnoDB; - -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (1, 0, 'customer1', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (2, 0, 'customer2', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (3, 0, 'customer3', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (4, 0, 'customer4', 100000); - -CREATE TABLE PLAYERS ( - PLAYER_ID CHAR(8) NOT NULL PRIMARY KEY, - LAST_NAME VARCHAR(35) NOT NULL, - FIRST_NAME VARCHAR(25) NOT NULL, - POS VARCHAR(10) , - YEAR_OF_BIRTH BIGINT NOT NULL, - YEAR_DRAFTED BIGINT NOT NULL -) type=InnoDB; - -CREATE TABLE GAMES ( - PLAYER_ID CHAR(8) NOT NULL, - YEAR_NO BIGINT NOT NULL, - TEAM CHAR(3) NOT NULL, - WEEK BIGINT NOT NULL, - OPPONENT CHAR(3) , - COMPLETES BIGINT , - ATTEMPTS BIGINT , - PASSING_YARDS BIGINT , - PASSING_TD BIGINT , - INTERCEPTIONS BIGINT , - RUSHES BIGINT , - RUSH_YARDS BIGINT , - RECEPTIONS BIGINT , - RECEPTIONS_YARDS BIGINT , - TOTAL_TD BIGINT -) type=InnoDB; - -CREATE TABLE PLAYER_SUMMARY ( - ID CHAR(8) NOT NULL, - YEAR_NO BIGINT NOT NULL, - COMPLETES BIGINT NOT NULL , - ATTEMPTS BIGINT NOT NULL , - PASSING_YARDS BIGINT NOT NULL , - PASSING_TD BIGINT NOT NULL , - INTERCEPTIONS BIGINT NOT NULL , - RUSHES BIGINT NOT NULL , - RUSH_YARDS BIGINT NOT NULL , - RECEPTIONS BIGINT NOT NULL , - RECEPTIONS_YARDS BIGINT NOT NULL , - TOTAL_TD BIGINT NOT NULL -) type=InnoDB; - -CREATE TABLE ERROR_LOG ( - JOB_NAME CHAR(20) , - STEP_NAME CHAR(20) , - MESSAGE VARCHAR(300) NOT NULL -) type=InnoDB; diff --git a/spring-batch-core/src/test/resources/business-schema-postgresql.sql b/spring-batch-core/src/test/resources/business-schema-postgresql.sql deleted file mode 100644 index c7a27de5d3..0000000000 --- a/spring-batch-core/src/test/resources/business-schema-postgresql.sql +++ /dev/null @@ -1,94 +0,0 @@ --- Autogenerated: do not edit this file -DROP SEQUENCE BATCH_STAGING_SEQ ; -DROP SEQUENCE TRADE_SEQ ; -DROP SEQUENCE CUSTOMER_SEQ ; -DROP TABLE BATCH_STAGING ; -DROP TABLE TRADE ; -DROP TABLE CUSTOMER ; -DROP TABLE PLAYERS ; -DROP TABLE GAMES ; -DROP TABLE PLAYER_SUMMARY ; -DROP TABLE ERROR_LOG ; - --- Autogenerated: do not edit this file - -CREATE SEQUENCE CUSTOMER_SEQ; -CREATE SEQUENCE BATCH_STAGING_SEQ; -CREATE SEQUENCE TRADE_SEQ; - -CREATE TABLE BATCH_STAGING ( - ID BIGINT NOT NULL PRIMARY KEY , - JOB_ID BIGINT NOT NULL, - VALUE BYTEA NOT NULL, - PROCESSED CHAR(1) NOT NULL -) ; - -CREATE TABLE TRADE ( - ID BIGINT NOT NULL PRIMARY KEY , - VERSION BIGINT , - ISIN VARCHAR(45) NOT NULL, - QUANTITY BIGINT , - PRICE DECIMAL(8,2) , - CUSTOMER VARCHAR(45) -) ; - -CREATE TABLE CUSTOMER ( - ID BIGINT NOT NULL PRIMARY KEY , - VERSION BIGINT , - NAME VARCHAR(45) , - CREDIT DECIMAL(10,2) -) ; - -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (1, 0, 'customer1', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (2, 0, 'customer2', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (3, 0, 'customer3', 100000); -INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (4, 0, 'customer4', 100000); - -CREATE TABLE PLAYERS ( - PLAYER_ID CHAR(8) NOT NULL PRIMARY KEY, - LAST_NAME VARCHAR(35) NOT NULL, - FIRST_NAME VARCHAR(25) NOT NULL, - POS VARCHAR(10) , - YEAR_OF_BIRTH BIGINT NOT NULL, - YEAR_DRAFTED BIGINT NOT NULL -) ; - -CREATE TABLE GAMES ( - PLAYER_ID CHAR(8) NOT NULL, - YEAR_NO BIGINT NOT NULL, - TEAM CHAR(3) NOT NULL, - WEEK BIGINT NOT NULL, - OPPONENT CHAR(3) , - COMPLETES BIGINT , - ATTEMPTS BIGINT , - PASSING_YARDS BIGINT , - PASSING_TD BIGINT , - INTERCEPTIONS BIGINT , - RUSHES BIGINT , - RUSH_YARDS BIGINT , - RECEPTIONS BIGINT , - RECEPTIONS_YARDS BIGINT , - TOTAL_TD BIGINT -) ; - -CREATE TABLE PLAYER_SUMMARY ( - ID CHAR(8) NOT NULL, - YEAR_NO BIGINT NOT NULL, - COMPLETES BIGINT NOT NULL , - ATTEMPTS BIGINT NOT NULL , - PASSING_YARDS BIGINT NOT NULL , - PASSING_TD BIGINT NOT NULL , - INTERCEPTIONS BIGINT NOT NULL , - RUSHES BIGINT NOT NULL , - RUSH_YARDS BIGINT NOT NULL , - RECEPTIONS BIGINT NOT NULL , - RECEPTIONS_YARDS BIGINT NOT NULL , - TOTAL_TD BIGINT NOT NULL -) ; - -CREATE TABLE ERROR_LOG ( - JOB_NAME CHAR(20) , - STEP_NAME CHAR(20) , - MESSAGE VARCHAR(300) NOT NULL -); - diff --git a/spring-batch-core/src/test/resources/data-source-context.xml b/spring-batch-core/src/test/resources/data-source-context.xml index 1014809991..369a918610 100644 --- a/spring-batch-core/src/test/resources/data-source-context.xml +++ b/spring-batch-core/src/test/resources/data-source-context.xml @@ -1,57 +1,17 @@ + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - - - - - - ${batch.drop.script} - ${batch.schema.script} - ${batch.business.schema.script} - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + - - - - - - - - diff --git a/spring-batch-core/src/test/resources/foo.sql b/spring-batch-core/src/test/resources/foo.sql index 8fafa4173a..1c32c772d2 100644 --- a/spring-batch-core/src/test/resources/foo.sql +++ b/spring-batch-core/src/test/resources/foo.sql @@ -1,4 +1,5 @@ -DROP TABLE T_FOOS; +DROP TABLE T_FOOS if exists; +DROP TABLE ERROR_LOG IF EXISTS; CREATE TABLE T_FOOS ( ID BIGINT NOT NULL, @@ -8,6 +9,12 @@ CREATE TABLE T_FOOS ( ALTER TABLE T_FOOS ADD PRIMARY KEY (ID); +CREATE TABLE ERROR_LOG ( + JOB_NAME CHAR(20) , + STEP_NAME CHAR(20) , + MESSAGE VARCHAR(300) NOT NULL +) ; + 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); diff --git a/spring-batch-core/src/test/resources/business-schema-hsqldb.sql b/spring-batch-core/src/test/resources/football-schema-hsqldb.sql similarity index 89% rename from spring-batch-core/src/test/resources/business-schema-hsqldb.sql rename to spring-batch-core/src/test/resources/football-schema-hsqldb.sql index f3e15e0549..3ab21d7c0e 100644 --- a/spring-batch-core/src/test/resources/business-schema-hsqldb.sql +++ b/spring-batch-core/src/test/resources/football-schema-hsqldb.sql @@ -2,7 +2,6 @@ DROP TABLE PLAYERS IF EXISTS; DROP TABLE GAMES IF EXISTS; DROP TABLE PLAYER_SUMMARY IF EXISTS; -DROP TABLE ERROR_LOG IF EXISTS; CREATE TABLE PLAYERS ( PLAYER_ID CHAR(8) NOT NULL PRIMARY KEY, @@ -45,9 +44,3 @@ CREATE TABLE PLAYER_SUMMARY ( RECEPTIONS_YARDS BIGINT NOT NULL , TOTAL_TD BIGINT NOT NULL ) ; - -CREATE TABLE ERROR_LOG ( - JOB_NAME CHAR(20) , - STEP_NAME CHAR(20) , - MESSAGE VARCHAR(300) NOT NULL -) ; diff --git a/spring-batch-core/src/test/resources/log4j.properties b/spring-batch-core/src/test/resources/log4j.properties deleted file mode 100644 index f54d89e450..0000000000 --- a/spring-batch-core/src/test/resources/log4j.properties +++ /dev/null @@ -1,18 +0,0 @@ -log4j.rootCategory=INFO, stdout - -log4j.appender.stdout=org.apache.logging.log4j.core.appender.ConsoleAppender -log4j.appender.stdout.layout=org.apache.logging.log4j.core.layout.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - -log4j.category.org.apache.activemq=ERROR -#log4j.category.org.springframework.retry=DEBUG -#log4j.category.org.springframework.batch=DEBUG -#log4j.category.org.springframework.batch.support=INFO -#log4j.category.org.springframework.batch.support.transaction.ResourcelessTransactionManager=DEBUG -#log4j.category.org.springframework.core.repository=DEBUG -# log4j.category.org.springframework.transaction=INFO -#log4j.category.org.springframework.beans=DEBUG - -# log4j.category.org.hibernate.SQL=DEBUG -# for debugging datasource initialization -# log4j.category.test.jdbc=DEBUG diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml index 55b384a917..0537f41739 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml @@ -1,9 +1,11 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + + @@ -15,17 +17,6 @@ - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml index 93f55bef03..8f37b1f017 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml @@ -16,16 +16,7 @@ - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml index 102f232f2f..75b47c1bfd 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml @@ -2,20 +2,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml index 44e43a48c4..ecbf6bbf36 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml @@ -1,20 +1,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml index bc45a20cdc..aaaa975868 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml @@ -1,9 +1,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + + @@ -17,17 +18,6 @@ - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml index 0aae9eb982..70eea0caf3 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml @@ -2,20 +2,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml index 1be26b5822..ae511d9818 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml @@ -2,9 +2,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + + @@ -48,17 +49,6 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml index 0712a01f47..fd430bd623 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml @@ -2,10 +2,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + + @@ -23,17 +23,6 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml index 1e96f98082..276e0740d2 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml @@ -4,10 +4,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:test="http://www.springframework.org/schema/batch/test" - xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd - http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -37,16 +35,7 @@ - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests-context.xml index b3870f2ca3..8620593d3d 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests-context.xml @@ -1,20 +1,11 @@ + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd"> - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml index 8514a6557d..2e75c547f7 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml @@ -1,20 +1,11 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/launch/JobLauncherIntegrationTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/launch/JobLauncherIntegrationTests-context.xml index da6490d2ab..f3a9f902a2 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/launch/JobLauncherIntegrationTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/launch/JobLauncherIntegrationTests-context.xml @@ -1,8 +1,8 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -16,15 +16,10 @@ - - - - - org/springframework/batch/core/schema-drop-hsqldb.sql - org/springframework/batch/core/schema-hsqldb.sql - - - + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/partition/launch-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/partition/launch-context.xml index 2fdbc767eb..19b72c493f 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/partition/launch-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/partition/launch-context.xml @@ -1,13 +1,9 @@ + xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/OptimisticLockingFailureTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/OptimisticLockingFailureTests-context.xml index 07a2eb0c76..e6573aa452 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/OptimisticLockingFailureTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/OptimisticLockingFailureTests-context.xml @@ -2,11 +2,11 @@ + https://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -62,15 +62,10 @@ - - - - - org/springframework/batch/core/schema-drop-hsqldb.sql - org/springframework/batch/core/schema-hsqldb.sql - - - + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/TablePrefixTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/TablePrefixTests-context.xml index 068dbd1460..b4cb71d746 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/TablePrefixTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/TablePrefixTests-context.xml @@ -1,6 +1,7 @@ + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -19,14 +20,9 @@ - - - - - org/springframework/batch/core/repository/dao/schema-prefix-hsqldb.sql - - - + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/data-source-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/data-source-context.xml deleted file mode 100644 index aa1f06eb49..0000000000 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/data-source-context.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - org/springframework/batch/core/schema-drop-hsqldb.sql - org/springframework/batch/core/schema-hsqldb.sql - foo.sql - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml index dd3ab71cbf..a219d0902f 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml @@ -1,8 +1,23 @@ + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + + + + + + + + + + + + + + + @@ -21,16 +36,34 @@ + + + + + + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/support/SimpleJobRepositoryProxyTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/support/SimpleJobRepositoryProxyTests-context.xml index eb5bb99267..de1393f9cb 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/support/SimpleJobRepositoryProxyTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/support/SimpleJobRepositoryProxyTests-context.xml @@ -4,8 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml index 6627619b60..9aedb09cc9 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml @@ -1,21 +1,11 @@ + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd"> - - - - - - - - - - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml index bc867a58f1..07f9bbdc1c 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml @@ -1,12 +1,14 @@ + https://www.springframework.org/schema/batch/spring-batch.xsd"> + + @@ -74,17 +76,6 @@ - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml index fc538a3eae..dc180f6cbc 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml @@ -1,10 +1,11 @@ - + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd"> + + + @@ -23,17 +24,6 @@ - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml index 2b74dd6fec..9ff38cd470 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml @@ -2,9 +2,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + + @@ -145,17 +146,6 @@ - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTests-context.xml index 81c9afb183..8062abe751 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTests-context.xml @@ -2,10 +2,12 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> + + @@ -15,17 +17,6 @@ - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml index bcdc56d015..05bf854a92 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml @@ -1,10 +1,10 @@ + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd"> + + @@ -44,16 +44,5 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/schema-hsqldb-extended.sql b/spring-batch-core/src/test/resources/schema-hsqldb-extended.sql similarity index 100% rename from spring-batch-core/src/test/resources/org/springframework/batch/core/schema-hsqldb-extended.sql rename to spring-batch-core/src/test/resources/schema-hsqldb-extended.sql diff --git a/spring-batch-core/src/test/resources/simple-job-launcher-context.xml b/spring-batch-core/src/test/resources/simple-job-launcher-context.xml index dc613fee92..4e9986d0f6 100644 --- a/spring-batch-core/src/test/resources/simple-job-launcher-context.xml +++ b/spring-batch-core/src/test/resources/simple-job-launcher-context.xml @@ -4,7 +4,7 @@ xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> - + diff --git a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java deleted file mode 100644 index 057af5b504..0000000000 --- a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2006-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package test.jdbc.datasource; - -import java.io.IOException; -import java.util.List; -import javax.sql.DataSource; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -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.support.JdbcTransactionManager; -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 - * @author Mahmoud Ben Hassine - * - */ -public class DataSourceInitializer implements InitializingBean, DisposableBean { - - private static final Log logger = LogFactory.getLog(DataSourceInitializer.class); - - private Resource[] initScripts; - - private Resource[] destroyScripts; - - private DataSource dataSource; - - private boolean ignoreFailedDrop = true; - - private boolean initialized = false; - - /** - * Main method as convenient entry point. - * @param args - */ - @SuppressWarnings("resource") - public static void main(String... args) { - new ClassPathXmlApplicationContext(ClassUtils.addResourcePathToPackagePath(DataSourceInitializer.class, - DataSourceInitializer.class.getSimpleName() + "-context.xml")); - } - - @Override - public void destroy() { - logger.info("destroy called for " + dataSource); - doDestroy(); - } - - public void doDestroy() { - if (destroyScripts == null) - return; - for (Resource destroyScript : destroyScripts) { - try { - doExecuteScript(destroyScript); - } - catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Could not execute destroy script [" + destroyScript + "]", e); - } - else { - logger.warn("Could not execute destroy script [" + destroyScript + "]"); - } - } - } - } - - @Override - public void afterPropertiesSet() throws Exception { - Assert.state(dataSource != null, "A DataSource is required"); - initialize(); - } - - private void initialize() { - if (!initialized) { - doDestroy(); - if (initScripts != null) { - for (Resource initScript : initScripts) { - doExecuteScript(initScript); - } - } - initialized = true; - } - } - - private void doExecuteScript(final Resource scriptResource) { - if (scriptResource == null || !scriptResource.exists()) - return; - final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - - TransactionTemplate transactionTemplate = new TransactionTemplate(new JdbcTransactionManager(dataSource)); - transactionTemplate.execute((TransactionCallback) status -> { - String[] scripts; - try { - scripts = StringUtils.delimitedListToStringArray( - stripComments(IOUtils.readLines(scriptResource.getInputStream(), "UTF-8")), ";"); - } - catch (IOException e) { - throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); - } - for (String s : scripts) { - String script = s.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; - } - } - } - } - return null; - }); - - } - - private String stripComments(List list) { - StringBuilder buffer = new StringBuilder(); - for (String line : list) { - if (!line.startsWith("//") && !line.startsWith("--")) { - buffer.append(line).append("\n"); - } - } - return buffer.toString(); - } - - public void setInitScripts(Resource[] initScripts) { - this.initScripts = initScripts; - } - - public void setDestroyScripts(Resource[] destroyScripts) { - this.destroyScripts = destroyScripts; - } - - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } - - public void setIgnoreFailedDrop(boolean ignoreFailedDrop) { - this.ignoreFailedDrop = ignoreFailedDrop; - } - -}