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

COVERAGE SUMMARY FOR SOURCE FILE [AbstractBatchConfiguration.java]

nameclass, %method, %block, %line, %
AbstractBatchConfiguration.java100% (2/2)100% (8/8)77%  (109/141)92%  (23/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractBatchConfiguration100% (1/1)100% (6/6)75%  (94/126)90%  (19/21)
getConfigurer (Collection): BatchConfigurer 100% (1/1)63%  (54/86)86%  (12/14)
AbstractBatchConfiguration (): void 100% (1/1)100% (3/3)100% (1/1)
jobBuilders (): JobBuilderFactory 100% (1/1)100% (6/6)100% (1/1)
jobRegistry (): JobRegistry 100% (1/1)100% (4/4)100% (1/1)
setImportMetadata (AnnotationMetadata): void 100% (1/1)100% (19/19)100% (3/3)
stepBuilders (): StepBuilderFactory 100% (1/1)100% (8/8)100% (1/1)
     
class StepScopeConfiguration100% (1/1)100% (2/2)100% (15/15)100% (4/4)
StepScopeConfiguration (): void 100% (1/1)100% (8/8)100% (2/2)
stepScope (): StepScope 100% (1/1)100% (7/7)100% (2/2)

1/*
2 * Copyright 2012-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 */
16package org.springframework.batch.core.configuration.annotation;
17 
18import java.util.Collection;
19 
20import javax.sql.DataSource;
21 
22import org.springframework.batch.core.configuration.JobRegistry;
23import org.springframework.batch.core.configuration.support.MapJobRegistry;
24import org.springframework.batch.core.launch.JobLauncher;
25import org.springframework.batch.core.repository.JobRepository;
26import org.springframework.batch.core.scope.StepScope;
27import org.springframework.beans.factory.annotation.Autowired;
28import org.springframework.context.ApplicationContext;
29import org.springframework.context.annotation.Bean;
30import org.springframework.context.annotation.Configuration;
31import org.springframework.context.annotation.Import;
32import org.springframework.context.annotation.ImportAware;
33import org.springframework.core.annotation.AnnotationAttributes;
34import org.springframework.core.type.AnnotationMetadata;
35import org.springframework.transaction.PlatformTransactionManager;
36import org.springframework.util.Assert;
37 
38/**
39 * Base {@code Configuration} class providing common structure for enabling and using Spring Batch. Customization is
40 * available by implementing the {@link BatchConfigurer} interface. {@link BatchConfigurer}.
41 * 
42 * @author Dave Syer
43 * @since 2.2
44 * @see EnableBatchProcessing
45 */
46@Configuration
47@Import(StepScopeConfiguration.class)
48public abstract class AbstractBatchConfiguration implements ImportAware {
49 
50        @Autowired
51        private ApplicationContext context;
52 
53        @Autowired(required = false)
54        private Collection<DataSource> dataSources;
55 
56        private BatchConfigurer configurer;
57 
58        @Bean
59        public JobBuilderFactory jobBuilders() throws Exception {
60                return new JobBuilderFactory(jobRepository());
61        }
62 
63        @Bean
64        public StepBuilderFactory stepBuilders() throws Exception {
65                return new StepBuilderFactory(jobRepository(), transactionManager());
66        }
67 
68        @Bean
69        public abstract JobRepository jobRepository() throws Exception;
70 
71        @Bean
72        public abstract JobLauncher jobLauncher() throws Exception;
73 
74        @Bean
75        public JobRegistry jobRegistry() throws Exception {
76                return new MapJobRegistry();
77        }
78 
79        @Bean
80        public abstract PlatformTransactionManager transactionManager() throws Exception;
81 
82        @Override
83        public void setImportMetadata(AnnotationMetadata importMetadata) {
84                AnnotationAttributes enabled = AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(
85                                EnableBatchProcessing.class.getName(), false));
86                Assert.notNull(enabled,
87                                "@EnableBatchProcessing is not present on importing class " + importMetadata.getClassName());
88        }
89 
90        protected BatchConfigurer getConfigurer(Collection<BatchConfigurer> configurers) throws Exception {
91                if (this.configurer != null) {
92                        return this.configurer;
93                }
94                if (configurers == null || configurers.isEmpty()) {
95                        if (dataSources == null || dataSources.isEmpty() || dataSources.size() > 1) {
96                                throw new IllegalStateException(
97                                                "To use the default BatchConfigurer the context must contain precisely one DataSource, found "
98                                                                + (dataSources == null ? 0 : dataSources.size()));
99                        }
100                        DataSource dataSource = dataSources.iterator().next();
101                        DefaultBatchConfigurer configurer = new DefaultBatchConfigurer(dataSource);
102                        configurer.initialize();
103                        this.configurer = configurer;
104                        return configurer;
105                }
106                if (configurers.size() > 1) {
107                        throw new IllegalStateException(
108                                        "To use a custom BatchConfigurer the context must contain precisely one, found "
109                                                        + configurers.size());
110                }
111                this.configurer = configurers.iterator().next();
112                return this.configurer;
113        }
114 
115}
116 
117/**
118 * Extract step scope configuration into a separate unit so that it can be non-static.
119 * 
120 * @author Dave Syer
121 * 
122 */
123@Configuration
124class StepScopeConfiguration {
125 
126        private StepScope stepScope = new StepScope();
127 
128        @Bean
129        public StepScope stepScope() {
130                stepScope.setAutoProxy(false);
131                return stepScope;
132        }
133 
134}

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