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 | private String tablePrefix = DEFAULT_TABLE_PREFIX; |
22 | |
23 | private JdbcOperations jdbcTemplate; |
24 | |
25 | protected String getQuery(String base) { |
26 | return StringUtils.replace(base, "%PREFIX%", tablePrefix); |
27 | } |
28 | |
29 | /** |
30 | * Public setter for the table prefix property. This will be prefixed to all |
31 | * the table names before queries are executed. Defaults to |
32 | * {@link #DEFAULT_TABLE_PREFIX}. |
33 | * |
34 | * @param tablePrefix the tablePrefix to set |
35 | */ |
36 | public void setTablePrefix(String tablePrefix) { |
37 | this.tablePrefix = tablePrefix; |
38 | } |
39 | |
40 | public void setJdbcTemplate(JdbcOperations jdbcTemplate) { |
41 | this.jdbcTemplate = jdbcTemplate; |
42 | } |
43 | |
44 | protected JdbcOperations getJdbcTemplate() { |
45 | return jdbcTemplate; |
46 | } |
47 | |
48 | public void afterPropertiesSet() throws Exception { |
49 | Assert.notNull(jdbcTemplate); |
50 | } |
51 | |
52 | } |