diff --git a/README.src.md b/README.ftl.md similarity index 72% rename from README.src.md rename to README.ftl.md index 5824fe8217..b11bb0fa6d 100644 --- a/README.src.md +++ b/README.ftl.md @@ -1,43 +1,38 @@ -# Getting Started: Creating a Batch Service +<#assign project_id="gs-batch-processing"> +This guide walks you through creating a basic batch-driven solution. What you'll build ----------------- -This guide walks you through creating a basic batch-driven solution. You build a service that imports data from a CSV spreadsheet, transforms it with custom code, and stores the final results in a database. +You build a service that imports data from a CSV spreadsheet, transforms it with custom code, and stores the final results in a database. What you'll need ---------------- - About 15 minutes - - {!include#prereq-editor-jdk-buildtools} + - <@prereq_editor_jdk_buildtools/> + +## <@how_to_complete_this_guide jump_ahead='Create a business class'/> -## {!include#how-to-complete-this-guide} Set up the project ------------------ -{!include#build-system-intro} +<@build_system_intro/> -{!include#create-directory-structure-hello} +<@create_directory_structure_hello/> ### Create a Maven POM - {!include:initial/pom.xml} + <@snippet path="pom.xml" prefix="initial"/> -{!include#bootstrap-starter-pom-disclaimer} +<@bootstrap_starter_pom_disclaimer/> ### Create business data Typically your customer or a business analyst supplies a spreadsheet. In this case, you make it up. -`src/main/resources/sample-data.csv` -```text -Jill,Doe -Joe,Doe -Justin,Doe -Jane,Doe -John,Doe -``` + <@snippet path="src/main/resources/sample-data.csv" prefix="initial"/> This spreadsheet contains a first name and a last name on each row, separated by a comma. This is a fairly common pattern that Spring handles out-of-the-box, as you will see. @@ -45,7 +40,9 @@ This spreadsheet contains a first name and a last name on each row, separated by Next, you write a SQL script to create a table to store the data. - {!include:complete/src/main/resources/schema.sql} + <@snippet path="src/main/resources/schema-all.sql" prefix="initial"/> + +> **Note:** Spring Boot runs `schema-@@platform@@.sql` automatically during startup. `-all` is the default for all platforms. Create a business class @@ -53,7 +50,7 @@ Create a business class Now that you see the format of data inputs and outputs, you write code to represent a row of data. - {!include:complete/src/main/java/hello/Person.java} + <@snippet path="src/main/java/hello/Person.java" prefix="complete"/> You can instantiate the `Person` class either with first and last name through a constructor, or by setting the properties. @@ -62,7 +59,7 @@ Create an intermediate processor A common paradigm in batch processing is to ingest data, transform it, and then pipe it out somewhere else. Here you write a simple transformer that converts the names to uppercase. - {!include:complete/src/main/java/hello/PersonItemProcessor.java} + <@snippet path="src/main/java/hello/PersonItemProcessor.java" prefix="complete"/> `PersonItemProcessor` implements Spring Batch's `ItemProcessor` interface. This makes it easy to wire the code into a batch job that you define further down in this guide. According to the interface, you receive an incoming `Person` object, after which you transform it to an upper-cased `Person`. @@ -73,13 +70,13 @@ Put together a batch job Now you put together the actual batch job. Spring Batch provides many utility classes that reduce the need to write custom code. Instead, you can focus on the business logic. - {!include:complete/src/main/java/hello/BatchConfiguration.java} + <@snippet path="src/main/java/hello/BatchConfiguration.java" prefix="complete"/> For starters, the `@EnableBatchProcessing` annotation adds many critical beans that support jobs and saves you a lot of leg work. Break it down: - {!include:complete/src/main/java/hello/BatchConfiguration.java#reader-writer-processor} + <@snippet "src/main/java/hello/BatchConfiguration.java" "readerwriterprocessor" "/complete"/> The first chunk of code defines the input, processor, and output. - `reader()` creates an `ItemReader`. It looks for a file called `sample-data.csv` and parses each line item with enough information to turn it into a `Person`. @@ -88,7 +85,7 @@ The first chunk of code defines the input, processor, and output. The next chunk focuses on the actual job configuration. - {!include:complete/src/main/java/hello/BatchConfiguration.java#job-step} + <@snippet "src/main/java/hello/BatchConfiguration.java" "jobstep" "/complete"/> The first method defines the job and the second one defines a single step. Jobs are built from steps, where each step can involve a reader, a processor, and a writer. @@ -100,29 +97,13 @@ In the step definition, you define how much data to write at a time. In this cas Finally, you run the application. - {!include:complete/src/main/java/hello/BatchConfiguration.java#template-main} + <@snippet "src/main/java/hello/BatchConfiguration.java" "templatemain" "/complete"/> This example uses a memory-based database (provided by `@EnableBatchProcessing`), meaning that when it's done, the data is gone. For demonstration purposes, there is extra code to create a `JdbcTemplate`, query the database, and print out the names of people the batch job inserts. +## <@build_an_executable_jar/> -Build an executable JAR ------------------------ -Add the following to your `pom.xml` file, keeping existing properties and plugins intact: - - {!include:complete/pom.xml#shade-config} - -Create a single executable JAR file containing all necessary dependency classes: - - $ mvn package - - -Run the batch job ------------------ - -Now you can run the job from the JAR as well, and distribute that as an executable artifact: - - $ java -jar target/gs-batch-processing-complete-0.1.0.jar - +<@run_the_application_with_maven module="batch job"/> The job prints out a line for each person that gets transformed. After the job runs, you can also see the output from querying the database. @@ -130,5 +111,3 @@ Summary ------- Congratulations! You built a batch job that ingested data from a spreadsheet, processed it, and wrote it to a database. - -[zip]: https://github.com/springframework-meta/gs-batch-processing/archive/master.zip diff --git a/SIDEBAR.md b/SIDEBAR.md new file mode 100644 index 0000000000..5ff3c47a74 --- /dev/null +++ b/SIDEBAR.md @@ -0,0 +1,31 @@ +### Related Resources + +There's more to data integration than is covered here. You may want to continue your exploration of Spring messaging and integration with the following + +### Getting Started Guides + +* [Integrating Data][gs-integration] +* [Capturing Stream Data][gs-capturing-stream-data] +* [Messaging with JMS][gs-messaging-jms] +* [Messaging with RabbitMQ][gs-messaging-rabbitmq] +* [Messaging with Redis][gs-messaging-redis] + +[gs-integration]: /guides/gs/integration/ +[gs-capturing-stream-data]: /guides/gs/capturing-stream-data/ +[gs-messaging-jms]: /guides/gs/messaging-jms/ +[gs-messaging-rabbitmq]: /guides/gs/messaging-rabbitmq/ +[gs-messaging-redis]: /guides/gs/messaging-redis/ + +### Tutorials + +* [Designing and Implementing RESTful Web Services with Spring][tut-rest] + +[tut-rest]: /guides/tutorials/rest + +### Understanding + +* [REST][u-rest] +* [JSON][u-json] + +[u-rest]: /understanding/REST +[u-json]: /understanding/JSON \ No newline at end of file diff --git a/complete/build.gradle b/complete/build.gradle new file mode 100644 index 0000000000..4302c323d4 --- /dev/null +++ b/complete/build.gradle @@ -0,0 +1,34 @@ +buildscript { + repositories { + maven { url "http://repo.springsource.org/libs-snapshot" } + mavenLocal() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.BUILD-SNAPSHOT") + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'spring-boot' + +jar { + baseName = 'gs-batch-processing' + version = '0.1.0' +} + +repositories { + mavenCentral() + maven { url "http://repo.springsource.org/libs-snapshot" } +} + +dependencies { + compile("org.springframework.boot:spring-boot-starter-batch:0.5.0.BUILD-SNAPSHOT") + compile("org.hsqldb:hsqldb") + testCompile("junit:junit:4.11") +} + +task wrapper(type: Wrapper) { + gradleVersion = '1.7' +} diff --git a/complete/gradle/wrapper/gradle-wrapper.jar b/complete/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..b979729db0 Binary files /dev/null and b/complete/gradle/wrapper/gradle-wrapper.jar differ diff --git a/complete/gradle/wrapper/gradle-wrapper.properties b/complete/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..d2d8306c1b --- /dev/null +++ b/complete/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Aug 09 11:38:26 CDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip diff --git a/complete/gradlew b/complete/gradlew new file mode 100755 index 0000000000..91a7e269e1 --- /dev/null +++ b/complete/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/complete/gradlew.bat b/complete/gradlew.bat new file mode 100644 index 0000000000..8a0b282aa6 --- /dev/null +++ b/complete/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/complete/pom.xml b/complete/pom.xml index 3348c3f432..ede9dde20d 100644 --- a/complete/pom.xml +++ b/complete/pom.xml @@ -1,61 +1,60 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.springframework - gs-batch-processing-complete - 0.1.0 + org.springframework + gs-batch-processing + 0.1.0 - org.springframework.bootstrap - spring-bootstrap-starters + org.springframework.boot + spring-boot-starter-parent 0.5.0.BUILD-SNAPSHOT - + - org.springframework.bootstrap - spring-bootstrap-batch-starter + org.springframework.boot + spring-boot-starter-batch org.hsqldb hsqldb - + - - - hello.BatchConfiguration - + + hello.BatchConfiguration + - - - - org.apache.maven.plugins - maven-shade-plugin - - - - + + + + maven-compiler-plugin + 2.3.2 + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + http://repo.springsource.org/libs-snapshot + true + + + + + + spring-snapshots + http://repo.springsource.org/libs-snapshot + true + + - - - spring-snapshots - http://repo.springsource.org/snapshot - true - - - spring-milestones - http://repo.springsource.org/milestone - true - - - - - spring-snapshots - http://repo.springsource.org/snapshot - true - - diff --git a/complete/src/main/java/hello/BatchConfiguration.java b/complete/src/main/java/hello/BatchConfiguration.java index 1dd67ae470..f5e9230719 100644 --- a/complete/src/main/java/hello/BatchConfiguration.java +++ b/complete/src/main/java/hello/BatchConfiguration.java @@ -6,6 +6,7 @@ import java.util.List; import javax.sql.DataSource; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; @@ -21,8 +22,7 @@ import org.springframework.batch.item.file.FlatFileItemReader; import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper; import org.springframework.batch.item.file.mapping.DefaultLineMapper; import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; -import org.springframework.bootstrap.SpringApplication; -import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration; +import org.springframework.boot.SpringApplication; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,76 +35,76 @@ import org.springframework.jdbc.core.RowMapper; @EnableAutoConfiguration public class BatchConfiguration { - // {!begin#reader-writer-processor} - @Bean - public ItemReader reader() { - FlatFileItemReader reader = new FlatFileItemReader(); - reader.setResource(new ClassPathResource("sample-data.csv")); - reader.setLineMapper(new DefaultLineMapper() {{ - setLineTokenizer(new DelimitedLineTokenizer() {{ - setNames(new String[] { "firstName", "lastName" }); - }}); - setFieldSetMapper(new BeanWrapperFieldSetMapper() {{ - setTargetType(Person.class); - }}); - }}); - return reader; - } + // {!begin readerwriterprocessor} + @Bean + public ItemReader reader() { + FlatFileItemReader reader = new FlatFileItemReader(); + reader.setResource(new ClassPathResource("sample-data.csv")); + reader.setLineMapper(new DefaultLineMapper() {{ + setLineTokenizer(new DelimitedLineTokenizer() {{ + setNames(new String[] { "firstName", "lastName" }); + }}); + setFieldSetMapper(new BeanWrapperFieldSetMapper() {{ + setTargetType(Person.class); + }}); + }}); + return reader; + } - @Bean - public ItemProcessor processor() { - return new PersonItemProcessor(); - } + @Bean + public ItemProcessor processor() { + return new PersonItemProcessor(); + } - @Bean - public ItemWriter writer(DataSource dataSource) { - JdbcBatchItemWriter writer = new JdbcBatchItemWriter(); - writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider()); - writer.setSql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)"); - writer.setDataSource(dataSource); - return writer; - } - // {!end#reader-writer-processor} + @Bean + public ItemWriter writer(DataSource dataSource) { + JdbcBatchItemWriter writer = new JdbcBatchItemWriter(); + writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider()); + writer.setSql("INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)"); + writer.setDataSource(dataSource); + return writer; + } + // {!end readerwriterprocessor} - // {!begin#job-step} - @Bean - public Job importUserJob(JobBuilderFactory jobs, Step s1) { - return jobs.get("importUserJob") - .incrementer(new RunIdIncrementer()) - .flow(s1) - .end() - .build(); - } + // {!begin jobstep} + @Bean + public Job importUserJob(JobBuilderFactory jobs, Step s1) { + return jobs.get("importUserJob") + .incrementer(new RunIdIncrementer()) + .flow(s1) + .end() + .build(); + } - @Bean - public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader reader, - ItemWriter writer, ItemProcessor processor) { - return stepBuilderFactory.get("step1") - . chunk(10) - .reader(reader) - .processor(processor) - .writer(writer) - .build(); - } - // {!end#job-step} + @Bean + public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader reader, + ItemWriter writer, ItemProcessor processor) { + return stepBuilderFactory.get("step1") + . chunk(10) + .reader(reader) + .processor(processor) + .writer(writer) + .build(); + } + // {!end jobstep} - // {!begin#template-main} - @Bean - public JdbcTemplate jdbcTemplate(DataSource dataSource) { - return new JdbcTemplate(dataSource); - } + // {!begin templatemain} + @Bean + public JdbcTemplate jdbcTemplate(DataSource dataSource) { + return new JdbcTemplate(dataSource); + } - public static void main(String[] args) { - ApplicationContext ctx = SpringApplication.run(BatchConfiguration.class, args); - List results = ctx.getBean(JdbcTemplate.class).query("SELECT first_name, last_name FROM people", new RowMapper() { - @Override - public Person mapRow(ResultSet rs, int row) throws SQLException { - return new Person(rs.getString(1), rs.getString(2)); - } - }); - for (Person person : results) { - System.out.println("Found <" + person + "> in the database."); - } - } - // {!end#template-main} + public static void main(String[] args) { + ApplicationContext ctx = SpringApplication.run(BatchConfiguration.class, args); + List results = ctx.getBean(JdbcTemplate.class).query("SELECT first_name, last_name FROM people", new RowMapper() { + @Override + public Person mapRow(ResultSet rs, int row) throws SQLException { + return new Person(rs.getString(1), rs.getString(2)); + } + }); + for (Person person : results) { + System.out.println("Found <" + person + "> in the database."); + } + } + // {!end templatemain} } diff --git a/complete/src/main/java/hello/Person.java b/complete/src/main/java/hello/Person.java index 0cc17ed8a2..745c739150 100644 --- a/complete/src/main/java/hello/Person.java +++ b/complete/src/main/java/hello/Person.java @@ -3,19 +3,19 @@ package hello; public class Person { private String lastName; private String firstName; - + public Person() { - + } - public Person(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } + public Person(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } - public void setFirstName(String firstName) { - this.firstName = firstName; - } + public void setFirstName(String firstName) { + this.firstName = firstName; + } public String getFirstName() { return firstName; @@ -26,11 +26,12 @@ public class Person { } public void setLastName(String lastName) { - this.lastName = lastName; - } + this.lastName = lastName; + } @Override public String toString() { return "firstName: " + firstName + ", lastName: " + lastName; } + } diff --git a/complete/src/main/java/hello/PersonItemProcessor.java b/complete/src/main/java/hello/PersonItemProcessor.java index 5256af777f..0752f5868b 100644 --- a/complete/src/main/java/hello/PersonItemProcessor.java +++ b/complete/src/main/java/hello/PersonItemProcessor.java @@ -3,15 +3,17 @@ package hello; import org.springframework.batch.item.ItemProcessor; public class PersonItemProcessor implements ItemProcessor { + @Override public Person process(final Person person) throws Exception { final String firstName = person.getFirstName().toUpperCase(); final String lastName = person.getLastName().toUpperCase(); - + final Person transformedPerson = new Person(firstName, lastName); System.out.println("Converting (" + person + ") into (" + transformedPerson + ")"); - + return transformedPerson; } + } diff --git a/complete/src/main/resources/schema-all.sql b/complete/src/main/resources/schema-all.sql new file mode 100644 index 0000000000..e472ce1e8c --- /dev/null +++ b/complete/src/main/resources/schema-all.sql @@ -0,0 +1,7 @@ +DROP TABLE people IF EXISTS; + +CREATE TABLE people ( + person_id BIGINT IDENTITY NOT NULL PRIMARY KEY, + first_name VARCHAR(20), + last_name VARCHAR(20) +); diff --git a/complete/src/main/resources/schema.sql b/complete/src/main/resources/schema.sql deleted file mode 100644 index 4e405e6de6..0000000000 --- a/complete/src/main/resources/schema.sql +++ /dev/null @@ -1,7 +0,0 @@ -DROP TABLE people IF EXISTS; - -CREATE TABLE people ( - person_id BIGINT IDENTITY NOT NULL PRIMARY KEY, - first_name VARCHAR(20), - last_name VARCHAR(20) -); diff --git a/initial/build.gradle b/initial/build.gradle new file mode 100644 index 0000000000..eaa5a04b3e --- /dev/null +++ b/initial/build.gradle @@ -0,0 +1,33 @@ +buildscript { + repositories { + maven { url "http://repo.springsource.org/libs-snapshot" } + mavenLocal() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.BUILD-SNAPSHOT") + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'idea' + +jar { + baseName = 'gs-batch-processing' + version = '0.1.0' +} + +repositories { + mavenCentral() + maven { url "http://repo.springsource.org/libs-snapshot" } +} + +dependencies { + compile("org.springframework.boot:spring-boot-starter-batch:0.5.0.BUILD-SNAPSHOT") + compile("org.hsqldb:hsqldb") + testCompile("junit:junit:4.11") +} + +task wrapper(type: Wrapper) { + gradleVersion = '1.7' +} diff --git a/initial/gradle/wrapper/gradle-wrapper.jar b/initial/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..b979729db0 Binary files /dev/null and b/initial/gradle/wrapper/gradle-wrapper.jar differ diff --git a/initial/gradle/wrapper/gradle-wrapper.properties b/initial/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..e3e1d3da4a --- /dev/null +++ b/initial/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Aug 09 11:38:32 CDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip diff --git a/initial/gradlew b/initial/gradlew new file mode 100755 index 0000000000..91a7e269e1 --- /dev/null +++ b/initial/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/initial/gradlew.bat b/initial/gradlew.bat new file mode 100644 index 0000000000..8a0b282aa6 --- /dev/null +++ b/initial/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/initial/pom.xml b/initial/pom.xml index 01fe2eee82..7cf86d5b3a 100644 --- a/initial/pom.xml +++ b/initial/pom.xml @@ -1,46 +1,52 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.springframework - gs-batch-processing-initial - 0.1.0 + org.springframework + gs-batch-processing + 0.1.0 - org.springframework.bootstrap - spring-bootstrap-starters + org.springframework.boot + spring-boot-starter-parent 0.5.0.BUILD-SNAPSHOT - + - org.springframework.bootstrap - spring-bootstrap-batch-starter + org.springframework.boot + spring-boot-starter-batch org.hsqldb hsqldb - + + + + + + maven-compiler-plugin + 2.3.2 + + + + + + + spring-snapshots + http://repo.springsource.org/libs-snapshot + true + + + + + + spring-snapshots + http://repo.springsource.org/libs-snapshot + true + + - - - spring-snapshots - http://repo.springsource.org/snapshot - true - - - spring-milestones - http://repo.springsource.org/milestone - true - - - - - spring-snapshots - http://repo.springsource.org/snapshot - true - - diff --git a/initial/src/main/resources/schema-all.sql b/initial/src/main/resources/schema-all.sql new file mode 100644 index 0000000000..e472ce1e8c --- /dev/null +++ b/initial/src/main/resources/schema-all.sql @@ -0,0 +1,7 @@ +DROP TABLE people IF EXISTS; + +CREATE TABLE people ( + person_id BIGINT IDENTITY NOT NULL PRIMARY KEY, + first_name VARCHAR(20), + last_name VARCHAR(20) +); diff --git a/initial/src/main/resources/schema.sql b/initial/src/main/resources/schema.sql deleted file mode 100644 index 4e405e6de6..0000000000 --- a/initial/src/main/resources/schema.sql +++ /dev/null @@ -1,7 +0,0 @@ -DROP TABLE people IF EXISTS; - -CREATE TABLE people ( - person_id BIGINT IDENTITY NOT NULL PRIMARY KEY, - first_name VARCHAR(20), - last_name VARCHAR(20) -); diff --git a/test/run.sh b/test/run.sh new file mode 100755 index 0000000000..4f3ce42d1e --- /dev/null +++ b/test/run.sh @@ -0,0 +1,36 @@ +#!/bin/sh +cd $(dirname $0) + +cd ../complete + +mvn clean package +ret=$? +if [ $ret -ne 0 ]; then +exit $ret +fi +rm -rf target + +./gradlew build +ret=$? +if [ $ret -ne 0 ]; then +exit $ret +fi +rm -rf build + +cd ../initial + +mvn clean package +ret=$? +if [ $ret -ne 0 ]; then +exit $ret +fi +rm -rf target + +./gradlew build +ret=$? +if [ $ret -ne 0 ]; then +exit $ret +fi +rm -rf build + +exit