Java Reference
In-Depth Information
# 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.user=root
batch.jdbc.password=p@ssw0rd
batch.schema=spring_batch_test
#batch.schema.script=schema-mysql.sql
Note that I commented out the batch.schema.script line. When you run your job, the
dataSourceIntializer executes the script specified. This is helpful when you're working in development,
but if you want to persist the data, it's a bit less useful.
With the properties file now pointing to your local instance of MySQL, you need to update your
POM file so that you include the MySQL driver in your classpath. To do that, find the HSQLDB
dependency, and update it as shown in Listing 2-8.
Listing 2-8. Maven MySQL Dependency
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.3</version>
</dependency>
In this dependency, 5.1.3 is the version of MySQL running locally.
With your database connection configured, Spring Batch needs you to create the schema. Using
MySQL, you can create the schema as shown in Listing 2-9.
Listing 2-9. Creating the Database Schema
mysql> create database spring_batch_test;
Query OK, 1 row affected (0.00 sec)
mysql> use spring_batch_test;
Database changed
mysql> source ~/spring_batch/src/main/resources/org/springframework/batch/core/schema-
mysql.sql
That's it. Let's run the job again (be sure to do a mvn clean compile first, to copy your updated
batch.properties file to the target). Using the same command as earlier, you should see the same output.
The difference is that this time, Spring Batch left something behind. Let's look at the database.
The Job Repository Tables
Spring Batch uses the database to maintain state both during a single execution and from execution to
execution. Information is recorded about the job instance, the parameters passed in, the results of the
execution, and the results of each step. Here are the six tables in the job repository; the following
sections describe their relationships: 4
4 Those using MySQL and some other databases may see three additional “tables”:
batch_job_execution_seq, batch_job_seq, and batch_step_execution_seq. These are used to maintain a
database sequence and aren't discussed here.
 
Search WWH ::




Custom Search