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

COVERAGE SUMMARY FOR SOURCE FILE [DerbyPagingQueryProvider.java]

nameclass, %method, %block, %line, %
DerbyPagingQueryProvider.java100% (1/1)100% (7/7)100% (98/98)100% (20/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DerbyPagingQueryProvider100% (1/1)100% (7/7)100% (98/98)100% (20/20)
DerbyPagingQueryProvider (): void 100% (1/1)100% (3/3)100% (1/1)
getOrderedQueryAlias (): String 100% (1/1)100% (2/2)100% (1/1)
getOverClause (): String 100% (1/1)100% (2/2)100% (1/1)
getOverSubstituteClauseEnd (): String 100% (1/1)100% (10/10)100% (1/1)
getOverSubstituteClauseStart (): String 100% (1/1)100% (10/10)100% (1/1)
init (DataSource): void 100% (1/1)100% (31/31)100% (5/5)
isDerbyVersionSupported (String): boolean 100% (1/1)100% (40/40)100% (10/10)

1/*
2 * Copyright 2006-2012 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 */
16 
17package org.springframework.batch.item.database.support;
18 
19import javax.sql.DataSource;
20 
21import org.springframework.batch.item.database.PagingQueryProvider;
22import org.springframework.dao.InvalidDataAccessResourceUsageException;
23import org.springframework.jdbc.support.JdbcUtils;
24 
25/**
26 * Derby implementation of a  {@link PagingQueryProvider} using standard SQL:2003 windowing functions.
27 * These features are supported starting with Apache Derby version 10.4.1.3.
28 *
29 * As the OVER() function does not support the ORDER BY clause a sub query is instead used to order the results
30 * before the ROW_NUM restriction is applied
31 *
32 * @author Thomas Risberg
33 * @author David Thexton
34 * @author Michael Minella
35 * @since 2.0
36 */
37public class DerbyPagingQueryProvider extends SqlWindowingPagingQueryProvider {
38        
39        private static final String MINIMAL_DERBY_VERSION = "10.4.1.3";
40 
41        @Override
42        public void init(DataSource dataSource) throws Exception {
43                super.init(dataSource);
44                String version = JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductVersion").toString();
45                if (!isDerbyVersionSupported(version)) {
46                        throw new InvalidDataAccessResourceUsageException("Apache Derby version " + version + " is not supported by this class,  Only version " + MINIMAL_DERBY_VERSION + " or later is supported");
47                }
48        }
49        
50        // derby version numbering is M.m.f.p [ {alpha|beta} ] see http://db.apache.org/derby/papers/versionupgrade.html#Basic+Numbering+Scheme
51        private boolean isDerbyVersionSupported(String version) {
52                String[] minimalVersionParts = MINIMAL_DERBY_VERSION.split("\\.");
53                String[] versionParts = version.split("[\\. ]");
54                for (int i = 0; i < minimalVersionParts.length; i++) {
55                        int minimalVersionPart = Integer.valueOf(minimalVersionParts[i]);
56                        int versionPart = Integer.valueOf(versionParts[i]);
57                        if (versionPart < minimalVersionPart) {
58                                return false;
59                        } else if (versionPart > minimalVersionPart) {
60                                return true;
61                        }
62                }
63                return true; 
64        }
65        
66        @Override
67        protected String getOrderedQueryAlias() {
68                return "TMP_ORDERED";
69        }
70 
71        @Override
72        protected String getOverClause() {
73                return "";
74        }
75 
76    @Override
77        protected String getOverSubstituteClauseStart() {
78                return " FROM (SELECT " + getSelectClause();
79        }
80 
81    @Override
82        protected String getOverSubstituteClauseEnd() {
83                return " ) AS " + getOrderedQueryAlias();
84        }
85 
86}

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