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

COVERAGE SUMMARY FOR SOURCE FILE [ListPreparedStatementSetter.java]

nameclass, %method, %block, %line, %
ListPreparedStatementSetter.java100% (1/1)100% (4/4)100% (32/32)100% (8/8)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListPreparedStatementSetter100% (1/1)100% (4/4)100% (32/32)100% (8/8)
ListPreparedStatementSetter (): void 100% (1/1)100% (3/3)100% (1/1)
afterPropertiesSet (): void 100% (1/1)100% (5/5)100% (2/2)
setParameters (List): void 100% (1/1)100% (4/4)100% (2/2)
setValues (PreparedStatement): void 100% (1/1)100% (20/20)100% (3/3)

1/*
2 * Copyright 2006-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.resource;
17 
18import java.sql.PreparedStatement;
19import java.sql.SQLException;
20import java.util.List;
21 
22import org.springframework.batch.item.database.JdbcCursorItemReader;
23import org.springframework.beans.factory.InitializingBean;
24import org.springframework.jdbc.core.PreparedStatementSetter;
25import org.springframework.jdbc.core.SqlTypeValue;
26import org.springframework.jdbc.core.StatementCreatorUtils;
27import org.springframework.util.Assert;
28 
29/**
30 * Implementation of the {@link PreparedStatementSetter} interface that accepts
31 * a list of values to be set on a PreparedStatement.  This is usually used in
32 * conjunction with the {@link JdbcCursorItemReader} to allow for the replacement
33 * of bind variables when generating the cursor.  The order of the list will be
34 * used to determine the ordering of setting variables.  For example, the first
35 * item in the list will be the first bind variable set.  (i.e. it will
36 * correspond to the first '?' in the SQL statement)
37 *
38 * @author Lucas Ward
39 *
40 */
41public class ListPreparedStatementSetter implements
42PreparedStatementSetter, InitializingBean {
43 
44        private List<?> parameters;
45 
46        @Override
47        public void setValues(PreparedStatement ps) throws SQLException {
48                for (int i = 0; i < parameters.size(); i++) {
49                        StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, parameters.get(i));
50                }
51        }
52 
53        /**
54         * The parameter values that will be set on the PreparedStatement.
55         * It is assumed that their order in the List is the order of the parameters
56         * in the PreparedStatement.
57         */
58        public void setParameters(List<?> parameters) {
59                this.parameters = parameters;
60        }
61 
62        @Override
63        public void afterPropertiesSet() throws Exception {
64                Assert.notNull(parameters, "Parameters must be provided");
65        }
66}

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