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 deleted file mode 100644 index 237d98e8c..000000000 --- a/spring-batch-samples/src/main/java/test/jdbc/datasource/DataSourceInitializer.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2006-2007 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 - * - * http://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.Arrays; -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.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.StringUtils; - -public class DataSourceInitializer implements InitializingBean, DisposableBean { - - private Resource[] initScripts; - - private Resource destroyScript; - - private DataSource dataSource; - - private boolean initialize = false; - - private Log logger = LogFactory.getLog(getClass()); - - private boolean initialized = false; - - public void setInitialize(boolean initialize) { - this.initialize = initialize; - } - - public void destroy() throws Exception { - if (!initialized) { - return; - } - try { - if (destroyScript!=null) { - doExecuteScript(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 + "]"); - } - } - } - - public void afterPropertiesSet() throws Exception { - Assert.notNull(dataSource); - 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); - } - } - initialized = true; - } - } - - private void doExecuteScript(final Resource scriptResource) { - if (scriptResource == null || !scriptResource.exists()) - return; - TransactionTemplate transactionTemplate = new TransactionTemplate(new DataSourceTransactionManager(dataSource)); - transactionTemplate.execute(new TransactionCallback() { - - @SuppressWarnings("unchecked") - public Object doInTransaction(TransactionStatus status) { - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - String[] scripts; - try { - scripts = StringUtils.delimitedListToStringArray(stripComments(IOUtils.readLines(scriptResource - .getInputStream())), ";"); - } - catch (IOException e) { - throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); - } - for (int i = 0; i < scripts.length; i++) { - String script = scripts[i].trim(); - if (StringUtils.hasText(script)) { - try { - jdbcTemplate.execute(scripts[i]); - } catch (DataAccessException e) { - if (!script.toUpperCase().startsWith("DROP")) { - throw e; - } - } - } - } - return null; - } - - }); - - } - - private String stripComments(List list) { - StringBuffer buffer = new StringBuffer(); - for (String line : list) { - if (!line.startsWith("//") && !line.startsWith("--")) { - buffer.append(line + "\n"); - } - } - return buffer.toString(); - } - - public Class getObjectType() { - return DataSource.class; - } - - public void setInitScripts(Resource[] initScripts) { - this.initScripts = initScripts; - } - - public void setDestroyScript(Resource destroyScript) { - this.destroyScript = destroyScript; - } - - public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - } - -} diff --git a/spring-batch-samples/src/main/resources/batch-derby.properties b/spring-batch-samples/src/main/resources/batch-derby.properties index 7d6798854..97302789d 100644 --- a/spring-batch-samples/src/main/resources/batch-derby.properties +++ b/spring-batch-samples/src/main/resources/batch-derby.properties @@ -6,11 +6,9 @@ batch.jdbc.user=app batch.jdbc.password= batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.jdbc.verifyCursorPosition=false 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.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler diff --git a/spring-batch-samples/src/main/resources/batch-h2.properties b/spring-batch-samples/src/main/resources/batch-h2.properties index 56737c533..f8cedeb70 100644 --- a/spring-batch-samples/src/main/resources/batch-h2.properties +++ b/spring-batch-samples/src/main/resources/batch-h2.properties @@ -6,11 +6,9 @@ batch.jdbc.user=sa batch.jdbc.password= batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.jdbc.verifyCursorPosition=true batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-h2.sql batch.schema.script=classpath:/org/springframework/batch/core/schema-h2.sql batch.business.schema.script=classpath:/business-schema-h2.sql -batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.H2SequenceMaxValueIncrementer batch.database.incrementer.parent=sequenceIncrementerParent batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler diff --git a/spring-batch-samples/src/main/resources/batch-hsql.properties b/spring-batch-samples/src/main/resources/batch-hsql.properties index 6ffc76fa5..b4ca5b5b3 100644 --- a/spring-batch-samples/src/main/resources/batch-hsql.properties +++ b/spring-batch-samples/src/main/resources/batch-hsql.properties @@ -9,11 +9,9 @@ batch.jdbc.user=sa batch.jdbc.password= batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.jdbc.verifyCursorPosition=true 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.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler diff --git a/spring-batch-samples/src/main/resources/batch-mysql.properties b/spring-batch-samples/src/main/resources/batch-mysql.properties index 9e92c2efc..a39515564 100644 --- a/spring-batch-samples/src/main/resources/batch-mysql.properties +++ b/spring-batch-samples/src/main/resources/batch-mysql.properties @@ -6,11 +6,9 @@ batch.jdbc.user=test batch.jdbc.password=test batch.jdbc.testWhileIdle=true batch.jdbc.validationQuery=SELECT 1 -batch.jdbc.verifyCursorPosition=true batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-mysql.sql batch.schema.script=classpath:/org/springframework/batch/core/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.database.incrementer.parent=columnIncrementerParent batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler diff --git a/spring-batch-samples/src/main/resources/batch-oracle.properties b/spring-batch-samples/src/main/resources/batch-oracle.properties index 69785e621..811284365 100644 --- a/spring-batch-samples/src/main/resources/batch-oracle.properties +++ b/spring-batch-samples/src/main/resources/batch-oracle.properties @@ -6,11 +6,9 @@ batch.jdbc.user=spring batch.jdbc.password=spring batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.jdbc.verifyCursorPosition=true batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-oracle10g.sql batch.schema.script=classpath:/org/springframework/batch/core/schema-oracle10g.sql batch.business.schema.script=business-schema-oracle10g.sql -batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer batch.database.incrementer.parent=sequenceIncrementerParent batch.lob.handler.class=org.springframework.jdbc.support.lob.OracleLobHandler diff --git a/spring-batch-samples/src/main/resources/batch-sqlserver.properties b/spring-batch-samples/src/main/resources/batch-sqlserver.properties index 0694ae002..a79606c7f 100644 --- a/spring-batch-samples/src/main/resources/batch-sqlserver.properties +++ b/spring-batch-samples/src/main/resources/batch-sqlserver.properties @@ -6,11 +6,9 @@ batch.jdbc.user=sa batch.jdbc.password=sa batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.jdbc.verifyCursorPosition=true batch.drop.script=/org/springframework/batch/core/schema-drop-sqlserver.sql batch.schema.script=/org/springframework/batch/core/schema-sqlserver.sql batch.business.schema.script=business-schema-sqlserver.sql -batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.database.incrementer.parent=columnIncrementerParent diff --git a/spring-batch-samples/src/main/resources/batch-sybase.properties b/spring-batch-samples/src/main/resources/batch-sybase.properties index 7d8419d66..922ba570c 100644 --- a/spring-batch-samples/src/main/resources/batch-sybase.properties +++ b/spring-batch-samples/src/main/resources/batch-sybase.properties @@ -6,11 +6,9 @@ batch.jdbc.user=spring batch.jdbc.password=spring batch.jdbc.testWhileIdle=false batch.jdbc.validationQuery= -batch.jdbc.verifyCursorPosition=true batch.drop.script=/org/springframework/batch/core/schema-drop-sybase.sql batch.schema.script=/org/springframework/batch/core/schema-sybase.sql batch.business.schema.script=business-schema-sybase.sql -batch.data.source.init=true batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.SybaseMaxValueIncrementer batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.database.incrementer.parent=columnIncrementerParent 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 5e0f2d083..9c34cc82c 100644 --- a/spring-batch-samples/src/main/resources/data-source-context.xml +++ b/spring-batch-samples/src/main/resources/data-source-context.xml @@ -1,21 +1,15 @@ + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd"> - - - - - - ${batch.drop.script} - ${batch.schema.script} - ${batch.business.schema.script} - - - + + + + + @@ -72,5 +66,4 @@ -