1 | package org.springframework.batch.core.repository.dao; |
2 | |
3 | import org.springframework.beans.factory.InitializingBean; |
4 | import org.springframework.jdbc.core.JdbcOperations; |
5 | import org.springframework.util.Assert; |
6 | import org.springframework.util.StringUtils; |
7 | |
8 | /** |
9 | * Encapsulates common functionality needed by JDBC batch metadata DAOs - |
10 | * provides jdbcTemplate for subclasses and handles table prefixes. |
11 | * |
12 | * @author Robert Kasanicky |
13 | */ |
14 | public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { |
15 | |
16 | /** |
17 | * Default value for the table prefix property. |
18 | */ |
19 | public static final String DEFAULT_TABLE_PREFIX = "BATCH_"; |
20 | |
21 | public static final int DEFAULT_EXIT_MESSAGE_LENGTH = 2500; |
22 | |
23 | private String tablePrefix = DEFAULT_TABLE_PREFIX; |
24 | |
25 | private JdbcOperations jdbcTemplate; |
26 | |
27 | protected String getQuery(String base) { |
28 | return StringUtils.replace(base, "%PREFIX%", tablePrefix); |
29 | } |
30 | |
31 | protected String getTablePrefix() { |
32 | return tablePrefix; |
33 | } |
34 | |
35 | /** |
36 | * Public setter for the table prefix property. This will be prefixed to all |
37 | * the table names before queries are executed. Defaults to |
38 | * {@link #DEFAULT_TABLE_PREFIX}. |
39 | * |
40 | * @param tablePrefix the tablePrefix to set |
41 | */ |
42 | public void setTablePrefix(String tablePrefix) { |
43 | this.tablePrefix = tablePrefix; |
44 | } |
45 | |
46 | public void setJdbcTemplate(JdbcOperations jdbcTemplate) { |
47 | this.jdbcTemplate = jdbcTemplate; |
48 | } |
49 | |
50 | protected JdbcOperations getJdbcTemplate() { |
51 | return jdbcTemplate; |
52 | } |
53 | |
54 | public void afterPropertiesSet() throws Exception { |
55 | Assert.notNull(jdbcTemplate); |
56 | } |
57 | |
58 | } |