EMMA Coverage Report (generated Fri Jan 30 13:20:29 EST 2009)
[all classes][org.springframework.batch.core.resource]

COVERAGE SUMMARY FOR SOURCE FILE [StepExecutionPreparedStatementSetter.java]

nameclass, %method, %block, %line, %
StepExecutionPreparedStatementSetter.java100% (1/1)80%  (4/5)92%  (59/64)86%  (12/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StepExecutionPreparedStatementSetter100% (1/1)80%  (4/5)92%  (59/64)86%  (12/14)
afterPropertiesSet (): void 0%   (0/1)0%   (0/5)0%   (0/2)
StepExecutionPreparedStatementSetter (): void 100% (1/1)100% (3/3)100% (1/1)
beforeStep (StepExecution): void 100% (1/1)100% (5/5)100% (2/2)
setParameterKeys (List): void 100% (1/1)100% (4/4)100% (2/2)
setValues (PreparedStatement): void 100% (1/1)100% (47/47)100% (7/7)

1/*
2 * Copyright 2006-2008 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.resource;
17 
18import java.sql.PreparedStatement;
19import java.sql.SQLException;
20import java.util.List;
21import java.util.Map;
22 
23import org.springframework.batch.core.JobParameters;
24import org.springframework.batch.core.StepExecution;
25import org.springframework.batch.core.StepExecutionListener;
26import org.springframework.batch.core.listener.StepExecutionListenerSupport;
27import org.springframework.beans.factory.InitializingBean;
28import org.springframework.jdbc.core.PreparedStatementSetter;
29import org.springframework.jdbc.core.SqlTypeValue;
30import org.springframework.jdbc.core.StatementCreatorUtils;
31import org.springframework.util.Assert;
32 
33/**
34 * Implementation of the {@link PreparedStatementSetter} interface that also implements
35 * {@link StepExecutionListener} and uses {@link JobParameters} to set the parameters on a 
36 * PreparedStatement.
37 * 
38 * @author Lucas Ward
39 *
40 */
41public class StepExecutionPreparedStatementSetter extends StepExecutionListenerSupport implements
42                PreparedStatementSetter, InitializingBean {
43 
44        private List parameterKeys;
45        private JobParameters jobParameters;
46        
47        public void setValues(PreparedStatement ps) throws SQLException {
48                Map parameters = jobParameters.getParameters();
49                for(int i = 0; i < parameterKeys.size(); i++){
50                        Object arg = parameters.get(parameterKeys.get(i));
51                        if(arg == null){
52                                throw new IllegalStateException("No job parameter found for with key of: [" + parameterKeys.get(i) + "]");
53                        }
54                        StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg);
55                }
56        }
57        
58        public void beforeStep(StepExecution stepExecution) {
59                this.jobParameters = stepExecution.getJobParameters();
60        }
61        
62        /**
63         * The parameter names that will be pulled from the {@link JobParameters}.  It is
64         * assumed that their order in the List is the order of the parameters in the 
65         * PreparedStatement.
66         */
67        public void setParameterKeys(List parameterKeys) {
68                this.parameterKeys = parameterKeys;
69        }
70 
71        public void afterPropertiesSet() throws Exception {
72                Assert.notNull(parameterKeys, "Parameters names must be provided");
73        }
74}

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