Java Reference
In-Depth Information
In either configuration, using the bean tag or the job-repository tag, you reference the second of
two job repository factories provided with Spring Batch. The first is , which you use for
an in-memory job repository. The second is . The
JobRepositoryFactoryBean that this configuration demonstrates uses a database as the method for
maintaining state in the job repository. To access the underlying database, you need to satisfy its two
dependencies: a datasource and a transaction manager, both of which are configured in Listing 5-2.
Database Schema Configuration
Spring does a good job of allowing you to be flexible with your configurations. One of the things Spring
Batch allows you to change up is the table prefix. By default, every table is prefixed with BATCH_ , but
this may not be what you or your enterprise want. With that in mind, the developers of Spring Batch let
you configure the table prefix for the tables in the job repository. To do that, you use the table-prefix
attribute of the job-repository tag as shown in Listing 5-3. With the configuration updated as it is in the
example, Spring Batch expects the tables to be named SAMPLE_JOB_EXECUTION, and so on.
Listing 5-3. Changing the Table Prefix
<job-repository id="jobRepository" data-source="dataSource"
transaction-manager="transactionManager" table-prefix="SAMPLE_"/>
Note Spring Batch only lets you configure the table prefix. You can't change the complete name of the tables or
column names.
The other aspect of the database schema that Spring Batch allows you to configure is the maximum
length of the varchar data type. By default, the schema scripts in Spring Batch set the length of the larger
varchar columns to 2500 (EXIT_MESSAGE columns in the execution tables and the SHORT_CONTEXT
columns in the execution context tables). If you're using a character set that uses more than a byte for a
character, or modify the schema, you can use this to allow Spring Batch to store larger values. Listing 5-4
shows the job repository being configured for 3000 as the maximum.
Listing 5-4. Configuring the Maximum varchar Length
<job-repository id="jobRepository" data-source="dataSource"
transaction-manager="transactionManager" max-varchar-length="3000"/>
It's important to note that the max-varchar-length configuration in Listing 5-4 doesn't actually
change the database. Instead, it truncates any messages that are too long to fit in the EXIT_MESSAGE
column. The last and probably most important piece of configuring the job repository is how
transactions are configured, which you look at next.
Search WWH ::

Custom Search