EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.explore.support]

COVERAGE SUMMARY FOR SOURCE FILE [JobExplorerFactoryBean.java]

nameclass, %method, %block, %line, %
JobExplorerFactoryBean.java100% (2/2)79%  (11/14)92%  (149/162)89%  (41/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

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

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