EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.item.database.support]

COVERAGE SUMMARY FOR SOURCE FILE [SqlPagingQueryProviderFactoryBean.java]

nameclass, %method, %block, %line, %
SqlPagingQueryProviderFactoryBean.java100% (1/1)91%  (10/11)97%  (188/193)95%  (42/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SqlPagingQueryProviderFactoryBean100% (1/1)91%  (10/11)97%  (188/193)95%  (42/44)
setAscending (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)
getObject (): Object 100% (1/1)99%  (69/70)100% (14/14)
SqlPagingQueryProviderFactoryBean (): void 100% (1/1)100% (91/91)100% (14/14)
getObjectType (): Class 100% (1/1)100% (2/2)100% (1/1)
isSingleton (): boolean 100% (1/1)100% (2/2)100% (1/1)
setDataSource (DataSource): void 100% (1/1)100% (4/4)100% (2/2)
setDatabaseType (String): void 100% (1/1)100% (4/4)100% (2/2)
setFromClause (String): void 100% (1/1)100% (4/4)100% (2/2)
setSelectClause (String): void 100% (1/1)100% (4/4)100% (2/2)
setSortKey (String): void 100% (1/1)100% (4/4)100% (2/2)
setWhereClause (String): void 100% (1/1)100% (4/4)100% (2/2)

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.item.database.support;
17 
18import static org.springframework.batch.support.DatabaseType.DB2;
19import static org.springframework.batch.support.DatabaseType.DB2ZOS;
20import static org.springframework.batch.support.DatabaseType.DERBY;
21import static org.springframework.batch.support.DatabaseType.HSQL;
22import static org.springframework.batch.support.DatabaseType.H2;
23import static org.springframework.batch.support.DatabaseType.MYSQL;
24import static org.springframework.batch.support.DatabaseType.ORACLE;
25import static org.springframework.batch.support.DatabaseType.POSTGRES;
26import static org.springframework.batch.support.DatabaseType.SQLSERVER;
27import static org.springframework.batch.support.DatabaseType.SYBASE;
28 
29import java.util.HashMap;
30import java.util.Map;
31 
32import javax.sql.DataSource;
33 
34import org.springframework.batch.item.database.PagingQueryProvider;
35import org.springframework.batch.support.DatabaseType;
36import org.springframework.beans.factory.FactoryBean;
37import org.springframework.jdbc.support.MetaDataAccessException;
38import org.springframework.util.Assert;
39import org.springframework.util.StringUtils;
40 
41/**
42 * Factory bean for {@link PagingQueryProvider} interface. The database type
43 * will be determined from the data source if not provided explicitly. Valid
44 * types are given by the {@link DatabaseType} enum.
45 * 
46 * @author Dave Syer
47 */
48public class SqlPagingQueryProviderFactoryBean implements FactoryBean {
49 
50        private DataSource dataSource;
51 
52        private String databaseType;
53 
54        private String fromClause;
55 
56        private String whereClause;
57 
58        private String selectClause;
59 
60        private String sortKey;
61 
62        private boolean ascending = true;
63 
64        private Map<DatabaseType, AbstractSqlPagingQueryProvider> providers = new HashMap<DatabaseType, AbstractSqlPagingQueryProvider>();
65 
66 
67        {
68                providers.put(DB2, new Db2PagingQueryProvider());
69                providers.put(DB2ZOS, new Db2PagingQueryProvider());
70                providers.put(DERBY,new DerbyPagingQueryProvider());
71                providers.put(HSQL,new HsqlPagingQueryProvider());
72                providers.put(H2,new H2PagingQueryProvider());
73                providers.put(MYSQL,new MySqlPagingQueryProvider());
74                providers.put(ORACLE,new OraclePagingQueryProvider());
75                providers.put(POSTGRES,new PostgresPagingQueryProvider());
76                providers.put(SQLSERVER,new SqlServerPagingQueryProvider());
77                providers.put(SYBASE,new SybasePagingQueryProvider());
78        }
79 
80        /**
81         * @param databaseType the databaseType to set
82         */
83        public void setDatabaseType(String databaseType) {
84                this.databaseType = databaseType;
85        }
86 
87        /**
88         * @param dataSource the dataSource to set
89         */
90        public void setDataSource(DataSource dataSource) {
91                this.dataSource = dataSource;
92        }
93 
94        /**
95         * @param fromClause the fromClause to set
96         */
97        public void setFromClause(String fromClause) {
98                this.fromClause = fromClause;
99        }
100 
101        /**
102         * @param whereClause the whereClause to set
103         */
104        public void setWhereClause(String whereClause) {
105                this.whereClause = whereClause;
106        }
107 
108        /**
109         * @param selectClause the selectClause to set
110         */
111        public void setSelectClause(String selectClause) {
112                this.selectClause = selectClause;
113        }
114 
115        /**
116         * @param sortKey the sortKey to set
117         */
118        public void setSortKey(String sortKey) {
119                this.sortKey = sortKey;
120        }
121 
122        /**
123         * @param ascending
124         */
125        public void setAscending(boolean ascending) {
126                this.ascending = ascending;        
127        }
128 
129        /**
130         * Get a {@link PagingQueryProvider} instance using the provided properties
131         * and appropriate for the given database type.
132         * 
133         * @see FactoryBean#getObject()
134         */
135        public Object getObject() throws Exception {
136 
137                DatabaseType type;
138                try {
139                        type = databaseType != null ? DatabaseType.valueOf(databaseType.toUpperCase()) : DatabaseType
140                                        .fromMetaData(dataSource);
141                }
142                catch (MetaDataAccessException e) {
143                        throw new IllegalArgumentException(
144                                        "Could not inspect meta data for database type.  You have to supply it explicitly.", e);
145                }
146 
147                AbstractSqlPagingQueryProvider provider = providers.get(type);
148                Assert.state(provider!=null, "Should not happen: missing PagingQueryProvider for DatabaseType="+type);
149 
150                provider.setFromClause(fromClause);
151                provider.setWhereClause(whereClause);
152                provider.setSortKey(sortKey);
153                provider.setAscending(ascending);
154                if (StringUtils.hasText(selectClause)) {
155                        provider.setSelectClause(selectClause);
156                }
157 
158                provider.init(dataSource);
159 
160                return provider;
161 
162        }
163 
164        /**
165         * Always returns {@link PagingQueryProvider}.
166         * 
167         * @see FactoryBean#getObjectType()
168         */
169        public Class<PagingQueryProvider> getObjectType() {
170                return PagingQueryProvider.class;
171        }
172 
173        /**
174         * Always returns true.
175         * @see FactoryBean#isSingleton()
176         */
177        public boolean isSingleton() {
178                return true;
179        }
180 
181}

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