EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.explore.support]

COVERAGE SUMMARY FOR SOURCE FILE [JobExplorerFactoryBean.java]

nameclass, %method, %block, %line, %
JobExplorerFactoryBean.java100% (2/2)85%  (11/13)94%  (133/142)93%  (39/42)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JobExplorerFactoryBean$1100% (1/1)50%  (1/2)55%  (6/11)67%  (2/3)
getNextKey (): long 0%   (0/1)0%   (0/5)0%   (0/1)
JobExplorerFactoryBean$1 (JobExplorerFactoryBean): void 100% (1/1)100% (6/6)100% (2/2)
     
class JobExplorerFactoryBean100% (1/1)91%  (10/11)97%  (127/131)95%  (38/40)
setLobHandler (LobHandler): void 0%   (0/1)0%   (0/4)0%   (0/2)
JobExplorerFactoryBean (): void 100% (1/1)100% (12/12)100% (3/3)
afterPropertiesSet (): void 100% (1/1)100% (12/12)100% (3/3)
createExecutionContextDao (): ExecutionContextDao 100% (1/1)100% (20/20)100% (6/6)
createJobExecutionDao (): JobExecutionDao 100% (1/1)100% (20/20)100% (6/6)
createJobInstanceDao (): JobInstanceDao 100% (1/1)100% (20/20)100% (6/6)
createStepExecutionDao (): StepExecutionDao 100% (1/1)100% (20/20)100% (6/6)
getObject (): Object 100% (1/1)100% (3/3)100% (1/1)
getTarget (): Object 100% (1/1)100% (12/12)100% (3/3)
setDataSource (DataSource): 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.explore.support;
18 
19import javax.sql.DataSource;
20 
21import org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao;
22import org.springframework.batch.core.repository.dao.ExecutionContextDao;
23import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao;
24import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao;
25import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao;
26import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao;
27import org.springframework.batch.core.repository.dao.JobExecutionDao;
28import org.springframework.batch.core.repository.dao.JobInstanceDao;
29import org.springframework.batch.core.repository.dao.StepExecutionDao;
30import org.springframework.batch.item.ExecutionContext;
31import org.springframework.beans.factory.FactoryBean;
32import org.springframework.beans.factory.InitializingBean;
33import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
34import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
35import org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer;
36import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
37import org.springframework.jdbc.support.lob.LobHandler;
38import org.springframework.util.Assert;
39 
40/**
41 * A {@link FactoryBean} that automates the creation of a
42 * {@link SimpleJobExplorer} using JDBC DAO implementations. Requires the user
43 * to describe what kind of database they are using.
44 * 
45 * @author Dave Syer
46 * @since 2.0
47 */
48public class JobExplorerFactoryBean extends AbstractJobExplorerFactoryBean
49                implements InitializingBean {
50 
51        private DataSource dataSource;
52 
53        private SimpleJdbcOperations jdbcTemplate;
54 
55        private String tablePrefix = AbstractJdbcBatchMetadataDao.DEFAULT_TABLE_PREFIX;
56 
57        private DataFieldMaxValueIncrementer incrementer = new AbstractDataFieldMaxValueIncrementer() {
58                @Override
59                protected long getNextKey() {
60                        throw new IllegalStateException("JobExplorer is read only.");
61                }
62        };
63 
64        private LobHandler lobHandler;
65 
66        /**
67         * Public setter for the {@link DataSource}.
68         * 
69         * @param dataSource
70         *            a {@link DataSource}
71         */
72        public void setDataSource(DataSource dataSource) {
73                this.dataSource = dataSource;
74        }
75 
76        /**
77         * Sets the table prefix for all the batch meta-data tables.
78         * 
79         * @param tablePrefix
80         */
81        public void setTablePrefix(String tablePrefix) {
82                this.tablePrefix = tablePrefix;
83        }
84 
85        /**
86         * The lob handler to use when saving {@link ExecutionContext} instances.
87         * Defaults to null which works for most databases.
88         * 
89         * @param lobHandler
90         */
91        public void setLobHandler(LobHandler lobHandler) {
92                this.lobHandler = lobHandler;
93        }
94 
95        public void afterPropertiesSet() throws Exception {
96 
97                Assert.notNull(dataSource, "DataSource must not be null.");
98 
99                jdbcTemplate = new SimpleJdbcTemplate(dataSource);
100 
101        }
102 
103        private Object getTarget() throws Exception {
104                return new SimpleJobExplorer(createJobInstanceDao(),
105                                createJobExecutionDao(), createStepExecutionDao(),
106                                createExecutionContextDao());
107        }
108 
109        @Override
110        protected ExecutionContextDao createExecutionContextDao() throws Exception {
111                JdbcExecutionContextDao dao = new JdbcExecutionContextDao();
112                dao.setJdbcTemplate(jdbcTemplate);
113                dao.setLobHandler(lobHandler);
114                dao.setTablePrefix(tablePrefix);
115                dao.afterPropertiesSet();
116                return dao;
117        }
118 
119        @Override
120        protected JobInstanceDao createJobInstanceDao() throws Exception {
121                JdbcJobInstanceDao dao = new JdbcJobInstanceDao();
122                dao.setJdbcTemplate(jdbcTemplate);
123                dao.setJobIncrementer(incrementer);
124                dao.setTablePrefix(tablePrefix);
125                dao.afterPropertiesSet();
126                return dao;
127        }
128 
129        @Override
130        protected JobExecutionDao createJobExecutionDao() throws Exception {
131                JdbcJobExecutionDao dao = new JdbcJobExecutionDao();
132                dao.setJdbcTemplate(jdbcTemplate);
133                dao.setJobExecutionIncrementer(incrementer);
134                dao.setTablePrefix(tablePrefix);
135                dao.afterPropertiesSet();
136                return dao;
137        }
138 
139        protected StepExecutionDao createStepExecutionDao() throws Exception {
140                JdbcStepExecutionDao dao = new JdbcStepExecutionDao();
141                dao.setJdbcTemplate(jdbcTemplate);
142                dao.setStepExecutionIncrementer(incrementer);
143                dao.setTablePrefix(tablePrefix);
144                dao.afterPropertiesSet();
145                return dao;
146        }
147 
148        public Object getObject() throws Exception {
149                return getTarget();
150        }
151}

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