diff --git a/archetypes/common-test.xml b/archetypes/common-test.xml
new file mode 100644
index 000000000..cc38edb16
--- /dev/null
+++ b/archetypes/common-test.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/archetypes/pom.xml b/archetypes/pom.xml
new file mode 100644
index 000000000..6acb979a4
--- /dev/null
+++ b/archetypes/pom.xml
@@ -0,0 +1,27 @@
+
+
+ 4.0.0
+ spring-batch-archetypes
+ pom
+ Samples-Archetypes-Parent
+
+
+ org.springframework.batch
+ spring-batch
+ 1.1.0.DEV-SNAPSHOT
+ ..
+
+
+
+ simple-cli
+
+
+
+
+ Codehaus
+ http://repository.codehaus.org/
+
+
+
+
diff --git a/archetypes/simple-cli/.classpath b/archetypes/simple-cli/.classpath
new file mode 100644
index 000000000..1205a46dc
--- /dev/null
+++ b/archetypes/simple-cli/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/archetypes/simple-cli/.project b/archetypes/simple-cli/.project
new file mode 100644
index 000000000..75e326eb6
--- /dev/null
+++ b/archetypes/simple-cli/.project
@@ -0,0 +1,45 @@
+
+
+ simple-cli-archetype
+ This plugin is an archetype that creates a command line batch sample from
+ Spring Batch. Once installed you can create the archetype project
+ using<br/>
+<pre>
+$ mvn archetype:create -DgroupId=com.mycompany -DartifactId=batch \
+ -DarchetypeGroupId=org.springframework.batch \
+ -DarchetypeArtifactId=spring-batch-cli -DarchetypeVersion=1.0-m3-SNAPSHOT
+</pre><br/>
+ Then you should be able to "cd batch; mvn package exec:exec", and see the
+ app run.
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder
+
+
+
+
+ org.springframework.ide.eclipse.core.springbuilder
+
+
+
+
+
+ org.springframework.ide.eclipse.core.springnature
+ org.eclipse.jdt.core.javanature
+ org.devzuz.q.maven.jdt.core.mavenNature
+
+
+
+ archetypes-pom.xml
+ 1
+ C:/Dave/Spring/spring-batch/trunk/archetypes/pom.xml
+
+
+
diff --git a/archetypes/simple-cli/.settings/org.eclipse.jdt.core.prefs b/archetypes/simple-cli/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..b2c78e914
--- /dev/null
+++ b/archetypes/simple-cli/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+#Thu Jan 03 08:57:40 GMT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/archetypes/simple-cli/.settings/org.springframework.ide.eclipse.core.prefs b/archetypes/simple-cli/.settings/org.springframework.ide.eclipse.core.prefs
new file mode 100644
index 000000000..74aada58c
--- /dev/null
+++ b/archetypes/simple-cli/.settings/org.springframework.ide.eclipse.core.prefs
@@ -0,0 +1,64 @@
+#Thu Jun 19 11:05:13 BST 2008
+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.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.sts.bestpractices.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.bestpractices.manifestvalidator=true
+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=true
+org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.applicationSymbolicNameRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.applicationVersionRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.bundleActivationPolicyRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.bundleActivatorRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.bundleManifestVersionRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.bundleNameRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.bundleSymbolicNameRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.bundleVersionRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.exportPackageRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.importRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.parsingProblemsRule-com.springsource.platform.ide.manifest.core.manifestvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.platform.ide.manifest.core.requireBundleRule-com.springsource.platform.ide.manifest.core.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.importPackageVersionRule-com.springsource.sts.bestpractices.manifestvalidator=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.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
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanDefinition-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanDefinitionHolder-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanFactory-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanInitDestroyMethod-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanProperty-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanReference-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.methodOverride-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.parsingProblems-org.springframework.ide.eclipse.beans.core.beansvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.requiredProperty-org.springframework.ide.eclipse.beans.core.beansvalidator=false
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.core.springClasspath-org.springframework.ide.eclipse.core.springvalidator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.action-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.actionstate-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.attribute-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.attributemapper-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.beanaction-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.evaluationaction-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.evaluationresult-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.exceptionhandler-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.import-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.inputattribute-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.mapping-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.outputattribute-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.set-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.state-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.subflowstate-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.transition-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.variable-org.springframework.ide.eclipse.webflow.core.validator=true
+org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.webflowstate-org.springframework.ide.eclipse.webflow.core.validator=true
diff --git a/archetypes/simple-cli/.springBeans b/archetypes/simple-cli/.springBeans
new file mode 100644
index 000000000..84232256b
--- /dev/null
+++ b/archetypes/simple-cli/.springBeans
@@ -0,0 +1,14 @@
+
+
+ 1
+
+
+
+
+
+
+ src/main/resources/example/simpleJob.xml
+
+
+
+
diff --git a/archetypes/simple-cli/pom.xml b/archetypes/simple-cli/pom.xml
new file mode 100644
index 000000000..8d2cd3bb0
--- /dev/null
+++ b/archetypes/simple-cli/pom.xml
@@ -0,0 +1,110 @@
+
+
+ 4.0.0
+ simple-cli-archetype
+ jar
+ Spring Batch Simple Commandline-Archetype
+
+
+ org.springframework.batch
+ spring-batch-archetypes
+ 1.1.0.DEV-SNAPSHOT
+ ..
+
+
+
+
+
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ org.springframework.batch
+ spring-batch-samples
+ ${pom.version}
+
+
+ commons-dbcp
+ commons-dbcp
+ 1.2.1
+
+
+ commons-collections
+ commons-collections
+
+
+
+
+ commons-io
+ commons-io
+ 1.2
+
+
+ hsqldb
+ hsqldb
+ 1.8.0.7
+
+
+ aspectj
+ aspectjweaver
+ 1.5.3
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+
+ **/*Tests.java
+
+
+ **/Abstract*.java
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.1
+
+
+ integration-test
+
+ exec
+
+
+
+
+ java
+
+ -classpath
+
+
+ org.springframework.batch.core.launch.support.CommandLineJobRunner
+
+ example/simpleJob.xml
+
+ job1
+
+
+
+
+
+
+
diff --git a/archetypes/simple-cli/src/main/java/example/ExampleItemReader.java b/archetypes/simple-cli/src/main/java/example/ExampleItemReader.java
new file mode 100644
index 000000000..d74960064
--- /dev/null
+++ b/archetypes/simple-cli/src/main/java/example/ExampleItemReader.java
@@ -0,0 +1,22 @@
+package example;
+
+import org.springframework.batch.item.AbstractItemReader;
+import org.springframework.batch.item.ItemReader;
+
+/**
+ * {@link ItemReader} with hard-coded input data.
+ */
+public class ExampleItemReader extends AbstractItemReader {
+
+ private String[] input = {"Hello world!", null};
+
+ private int index = 0;
+
+ /**
+ * Reads next record from input
+ */
+ public Object read() throws Exception {
+ return input[index++];
+ }
+
+}
diff --git a/archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java b/archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java
new file mode 100644
index 000000000..e83fbc47a
--- /dev/null
+++ b/archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java
@@ -0,0 +1,23 @@
+package example;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.batch.item.AbstractItemWriter;
+import org.springframework.batch.item.ItemWriter;
+
+
+/**
+ * Dummy {@link ItemWriter} which only logs data it receives.
+ */
+public class ExampleItemWriter extends AbstractItemWriter {
+
+ private static final Log log = LogFactory.getLog(ExampleItemWriterTests.class);
+
+ /**
+ * @see ItemWriter#write(Object)
+ */
+ public void write(Object data) throws Exception {
+ log.info(data);
+ }
+
+}
diff --git a/archetypes/simple-cli/src/main/resources/data-source-context.xml b/archetypes/simple-cli/src/main/resources/data-source-context.xml
new file mode 100644
index 000000000..f4e0730cb
--- /dev/null
+++ b/archetypes/simple-cli/src/main/resources/data-source-context.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ environment
+
+
+ environment
+
+
+
+ hsql
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/archetypes/simple-cli/src/main/resources/example/simpleJob.xml b/archetypes/simple-cli/src/main/resources/example/simpleJob.xml
new file mode 100644
index 000000000..b1003f215
--- /dev/null
+++ b/archetypes/simple-cli/src/main/resources/example/simpleJob.xml
@@ -0,0 +1,25 @@
+
+
+
+ Example job to get you started. It provides a skeleton for a typical batch application.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/archetypes/simple-cli/src/main/resources/log4j.properties b/archetypes/simple-cli/src/main/resources/log4j.properties
new file mode 100644
index 000000000..6d5422d74
--- /dev/null
+++ b/archetypes/simple-cli/src/main/resources/log4j.properties
@@ -0,0 +1,13 @@
+log4j.rootCategory=INFO, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
+
+log4j.category.org.apache.activemq=ERROR
+log4j.category.org.springframework.batch=DEBUG
+log4j.category.org.springframework.transaction=INFO
+
+log4j.category.org.hibernate.SQL=DEBUG
+# for debugging datasource initialization
+# log4j.category.test.jdbc=DEBUG
diff --git a/archetypes/simple-cli/src/test/java/test/jdbc/datasource/InitializingDataSourceFactoryBean.java b/archetypes/simple-cli/src/test/java/test/jdbc/datasource/InitializingDataSourceFactoryBean.java
new file mode 100644
index 000000000..b5e410af7
--- /dev/null
+++ b/archetypes/simple-cli/src/test/java/test/jdbc/datasource/InitializingDataSourceFactoryBean.java
@@ -0,0 +1,152 @@
+/*
+ * 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.Iterator;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.io.IOUtils;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.config.AbstractFactoryBean;
+import org.springframework.core.io.Resource;
+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 InitializingDataSourceFactoryBean extends AbstractFactoryBean {
+
+ private Resource[] initScripts;
+
+ private Resource destroyScript;
+
+ DataSource dataSource;
+
+ private static boolean initialized = false;
+
+ /**
+ * @throws Throwable
+ * @see java.lang.Object#finalize()
+ */
+ protected void finalize() throws Throwable {
+ super.finalize();
+ initialized = false;
+ logger.debug("finalize called");
+ }
+
+ protected void destroyInstance(Object instance) throws Exception {
+ try {
+ 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 + "]");
+ }
+ }
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ Assert.notNull(dataSource);
+ super.afterPropertiesSet();
+ }
+
+ protected Object createInstance() throws Exception {
+ Assert.notNull(dataSource);
+ if (!initialized) {
+ 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];
+ doExecuteScript(initScript);
+ }
+ }
+ initialized = true;
+ }
+ return dataSource;
+ }
+
+ private void doExecuteScript(final Resource scriptResource) {
+ if (scriptResource == null || !scriptResource.exists())
+ return;
+ TransactionTemplate transactionTemplate = new TransactionTemplate(new DataSourceTransactionManager(dataSource));
+ transactionTemplate.execute(new TransactionCallback() {
+
+ 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)) {
+ jdbcTemplate.execute(scripts[i]);
+ }
+ }
+ return null;
+ }
+
+ });
+
+ }
+
+ private String stripComments(List list) {
+ StringBuffer buffer = new StringBuffer();
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ String line = (String) iter.next();
+ 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;
+ }
+
+}