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

COVERAGE SUMMARY FOR SOURCE FILE [IbatisKeyCollector.java]

nameclass, %method, %block, %line, %
IbatisKeyCollector.java100% (1/1)75%  (6/8)85%  (70/82)82%  (18/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IbatisKeyCollector100% (1/1)75%  (6/8)85%  (70/82)82%  (18/22)
afterPropertiesSet (): void 0%   (0/1)0%   (0/9)0%   (0/3)
getSqlMapClientTemplate (): SqlMapClientTemplate 0%   (0/1)0%   (0/3)0%   (0/1)
IbatisKeyCollector (): void 100% (1/1)100% (14/14)100% (3/3)
retrieveKeys (ExecutionContext): List 100% (1/1)100% (25/25)100% (4/4)
setDrivingQueryId (String): void 100% (1/1)100% (4/4)100% (2/2)
setRestartQueryId (String): void 100% (1/1)100% (4/4)100% (2/2)
setSqlMapClient (SqlMapClient): void 100% (1/1)100% (10/10)100% (3/3)
updateContext (Object, ExecutionContext): void 100% (1/1)100% (13/13)100% (4/4)

1package org.springframework.batch.item.database.support;
2 
3import java.util.List;
4 
5import org.springframework.batch.item.ExecutionContext;
6import org.springframework.batch.item.database.DrivingQueryItemReader;
7import org.springframework.batch.item.database.KeyCollector;
8import org.springframework.batch.item.util.ExecutionContextUserSupport;
9import org.springframework.orm.ibatis.SqlMapClientTemplate;
10import org.springframework.util.Assert;
11import org.springframework.util.ClassUtils;
12 
13import com.ibatis.sqlmap.client.SqlMapClient;
14 
15/**
16 * {@link KeyCollector} based on iBATIS ORM framework. It is functionally
17 * similar to {@link SingleColumnJdbcKeyCollector} but does not make assumptions
18 * about the primary key structure. A separate restart query is necessary to
19 * ensure that only the required keys remaining for processing are returned,
20 * rather than the entire original list.</p>
21 * 
22 * The writer is thread safe after its properties are set (normal singleton
23 * behaviour).
24 * 
25 * @author Robert Kasanicky
26 * @author Lucas Ward
27 * @see DrivingQueryItemReader
28 */
29public class IbatisKeyCollector extends ExecutionContextUserSupport implements KeyCollector {
30 
31        private static final String RESTART_KEY = "key.index";
32 
33        private SqlMapClientTemplate sqlMapClientTemplate;
34 
35        private String drivingQuery;
36 
37        private String restartQueryId;
38 
39        public IbatisKeyCollector() {
40                setName(ClassUtils.getShortName(IbatisKeyCollector.class));
41        }
42 
43        /*
44         * Retrieve the keys using the provided driving query id.
45         * 
46         * @see KeyCollector#retrieveKeys()
47         */
48        public List retrieveKeys(ExecutionContext executionContext) {
49                if (executionContext.containsKey(getKey(RESTART_KEY))) {
50                        Object key = executionContext.get(getKey(RESTART_KEY));
51                        return sqlMapClientTemplate.queryForList(restartQueryId, key);
52                }
53                else {
54                        return sqlMapClientTemplate.queryForList(drivingQuery);
55                }
56        }
57 
58        /*
59         * (non-Javadoc)
60         * 
61         * @see KeyCollector#saveState(Object, ExecutionContext)
62         */
63        public void updateContext(Object key, ExecutionContext executionContext) {
64                Assert.notNull(key, "Key must not be null");
65                Assert.notNull(executionContext, "ExecutionContext must be null");
66                executionContext.put(getKey(RESTART_KEY), key);
67        }
68 
69        /*
70         * (non-Javadoc)
71         * 
72         * @see
73         * org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
74         */
75        public void afterPropertiesSet() throws Exception {
76                Assert.notNull(sqlMapClientTemplate, "SqlMaperClientTemplate must not be null.");
77                Assert.hasText(drivingQuery, "The DrivingQuery must not be null or empty.");
78        }
79 
80        /**
81         * @param sqlMapClient configured iBATIS client
82         */
83        public void setSqlMapClient(SqlMapClient sqlMapClient) {
84                this.sqlMapClientTemplate = new SqlMapClientTemplate();
85                this.sqlMapClientTemplate.setSqlMapClient(sqlMapClient);
86        }
87 
88        /**
89         * @param drivingQueryId id of the iBATIS select statement that will be used
90         * to retrieve the list of primary keys
91         */
92        public void setDrivingQueryId(String drivingQueryId) {
93                this.drivingQuery = drivingQueryId;
94        }
95 
96        /**
97         * Set the id of the restart query.
98         * 
99         * @param restartQueryId id of the iBatis select statement that will be used
100         * to retrieve the list of primary keys after a restart.
101         */
102        public void setRestartQueryId(String restartQueryId) {
103                this.restartQueryId = restartQueryId;
104        }
105 
106        public final SqlMapClientTemplate getSqlMapClientTemplate() {
107                return sqlMapClientTemplate;
108        }
109 
110}

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