EMMA Coverage Report (generated Tue May 06 07:29:23 PDT 2008)
[all classes][org.springframework.batch.core.repository.support]

COVERAGE SUMMARY FOR SOURCE FILE [JobRepositoryFactoryBean.java]

nameclass, %method, %block, %line, %
JobRepositoryFactoryBean.java100% (1/1)83%  (10/12)78%  (147/188)88%  (35/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JobRepositoryFactoryBean100% (1/1)83%  (10/12)78%  (147/188)88%  (35/40)
getObjectType (): Class 0%   (0/1)0%   (0/9)0%   (0/1)
isSingleton (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
afterPropertiesSet (): void 100% (1/1)19%  (7/37)40%  (2/5)
JobRepositoryFactoryBean (): void 100% (1/1)100% (6/6)100% (2/2)
createJobExecutionDao (JdbcTemplate): JobExecutionDao 100% (1/1)100% (31/31)100% (6/6)
createJobInstanceDao (JdbcTemplate): JobInstanceDao 100% (1/1)100% (31/31)100% (6/6)
createStepExecutionDao (JdbcTemplate): StepExecutionDao 100% (1/1)100% (31/31)100% (6/6)
getObject (): Object 100% (1/1)100% (25/25)100% (5/5)
setDataSource (DataSource): void 100% (1/1)100% (4/4)100% (2/2)
setDatabaseType (String): void 100% (1/1)100% (4/4)100% (2/2)
setIncrementerFactory (DataFieldMaxValueIncrementerFactory): void 100% (1/1)100% (4/4)100% (2/2)
setTablePrefix (String): void 100% (1/1)100% (4/4)100% (2/2)

1/*
2 * Copyright 2002-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.core.repository.support;
18 
19import javax.sql.DataSource;
20 
21import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
22import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao;
23import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao;
24import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao;
25import org.springframework.batch.core.repository.dao.JobExecutionDao;
26import org.springframework.batch.core.repository.dao.JobInstanceDao;
27import org.springframework.batch.core.repository.dao.StepExecutionDao;
28import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory;
29import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueIncrementerFactory;
30import org.springframework.beans.factory.FactoryBean;
31import org.springframework.beans.factory.InitializingBean;
32import org.springframework.jdbc.core.JdbcTemplate;
33import org.springframework.util.Assert;
34import org.springframework.util.StringUtils;
35 
36/**
37 * A {@link FactoryBean} that automates the creation of a {@link SimpleJobRepository}. Requires the
38 * user to describe what kind of database they are using.
39 * 
40 * @author Ben Hale
41 * @author Lucas Ward
42 */
43public class JobRepositoryFactoryBean implements FactoryBean, InitializingBean {
44 
45        private DataSource dataSource;
46 
47        private String databaseType;
48 
49        private String tablePrefix = AbstractJdbcBatchMetadataDao.DEFAULT_TABLE_PREFIX;
50 
51        private DataFieldMaxValueIncrementerFactory incrementerFactory;
52 
53        public void setDataSource(DataSource dataSource) {
54                this.dataSource = dataSource;
55        }
56 
57        public void setDatabaseType(String dbType) {
58                this.databaseType = dbType;
59        }
60 
61        public void setTablePrefix(String tablePrefix) {
62                this.tablePrefix = tablePrefix;
63        }
64 
65        public void setIncrementerFactory(DataFieldMaxValueIncrementerFactory incrementerFactory) {
66                this.incrementerFactory = incrementerFactory;
67        }
68 
69        public void afterPropertiesSet() throws Exception {
70                Assert.notNull(dataSource, "Datasource must not be null.");
71 
72                if (incrementerFactory == null) {
73                        incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
74                }
75 
76                Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType
77                        + "' is an unsupported database type.  The supported database types are "
78                        + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes()));
79        }
80 
81        public Object getObject() throws Exception {
82                JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
83                JobInstanceDao jobInstanceDao = createJobInstanceDao(jdbcTemplate);
84                JobExecutionDao jobExecutionDao = createJobExecutionDao(jdbcTemplate);
85                StepExecutionDao stepExecutionDao = createStepExecutionDao(jdbcTemplate);
86                return new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao);
87        }
88 
89        public Class getObjectType() {
90                return SimpleJobRepository.class;
91        }
92 
93        public boolean isSingleton() {
94                return true;
95        }
96 
97        private JobInstanceDao createJobInstanceDao(JdbcTemplate jdbcTemplate) throws Exception {
98                JdbcJobInstanceDao dao = new JdbcJobInstanceDao();
99                dao.setJdbcTemplate(jdbcTemplate);
100                dao.setJobIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ"));
101                dao.setTablePrefix(tablePrefix);
102                dao.afterPropertiesSet();
103                return dao;
104        }
105 
106        private JobExecutionDao createJobExecutionDao(JdbcTemplate jdbcTemplate) throws Exception {
107                JdbcJobExecutionDao dao = new JdbcJobExecutionDao();
108                dao.setJdbcTemplate(jdbcTemplate);
109                dao.setJobExecutionIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ"));
110                dao.setTablePrefix(tablePrefix);
111                dao.afterPropertiesSet();
112                return dao;
113        }
114 
115        private StepExecutionDao createStepExecutionDao(JdbcTemplate jdbcTemplate) throws Exception {
116                JdbcStepExecutionDao dao = new JdbcStepExecutionDao();
117                dao.setJdbcTemplate(jdbcTemplate);
118                dao.setStepExecutionIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ"));
119                dao.setTablePrefix(tablePrefix);
120                dao.afterPropertiesSet();
121                return dao;
122        }
123}

[all classes][org.springframework.batch.core.repository.support]
EMMA 2.0.5312 (C) Vladimir Roubtsov