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 [DefaultDataFieldMaxValueIncrementerFactory.java]

nameclass, %method, %block, %line, %
DefaultDataFieldMaxValueIncrementerFactory.java100% (1/1)80%  (4/5)77%  (146/190)83%  (30/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DefaultDataFieldMaxValueIncrementerFactory100% (1/1)80%  (4/5)77%  (146/190)83%  (30/36)
getSupportedIncrementerTypes (): String [] 0%   (0/1)0%   (0/32)0%   (0/4)
getIncrementer (String, String): DataFieldMaxValueIncrementer 100% (1/1)90%  (107/119)91%  (20/22)
DefaultDataFieldMaxValueIncrementerFactory (DataSource): void 100% (1/1)100% (9/9)100% (4/4)
isSupportedIncrementerType (String): boolean 100% (1/1)100% (26/26)100% (4/4)
setIncrementerColumnName (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.H2;
22import static org.springframework.batch.support.DatabaseType.HSQL;
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.ArrayList;
30import java.util.List;
31 
32import javax.sql.DataSource;
33 
34import org.springframework.batch.support.DatabaseType;
35import org.springframework.jdbc.support.incrementer.DB2MainframeSequenceMaxValueIncrementer;
36import org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer;
37import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
38import org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer;
39import org.springframework.jdbc.support.incrementer.H2SequenceMaxValueIncrementer;
40import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer;
41import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer;
42import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
43import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer;
44import org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer;
45import org.springframework.jdbc.support.incrementer.SybaseMaxValueIncrementer;
46 
47/**
48 * Default implementation of the {@link DataFieldMaxValueIncrementerFactory}
49 * interface. Valid database types are given by the {@link DatabaseType} enum.
50 * 
51 * @author Lucas Ward
52 * @see DatabaseType
53 */
54public class DefaultDataFieldMaxValueIncrementerFactory implements DataFieldMaxValueIncrementerFactory {
55 
56        private DataSource dataSource;
57 
58        private String incrementerColumnName = "ID";
59 
60        /**
61         * Public setter for the column name (defaults to "ID") in the incrementer.
62         * Only used by some platforms (Derby, HSQL, MySQL, SQL Server and Sybase),
63         * and should be fine for use with Spring Batch meta data as long as the
64         * default batch schema hasn't been changed.
65         * 
66         * @param incrementerColumnName the primary key column name to set
67         */
68        public void setIncrementerColumnName(String incrementerColumnName) {
69                this.incrementerColumnName = incrementerColumnName;
70        }
71 
72        public DefaultDataFieldMaxValueIncrementerFactory(DataSource dataSource) {
73                this.dataSource = dataSource;
74        }
75 
76    @Override
77        public DataFieldMaxValueIncrementer getIncrementer(String incrementerType, String incrementerName) {
78                DatabaseType databaseType = DatabaseType.valueOf(incrementerType.toUpperCase());
79 
80                if (databaseType == DB2) {
81                        return new DB2SequenceMaxValueIncrementer(dataSource, incrementerName);
82                }
83                else if (databaseType == DB2ZOS) {
84                        return new DB2MainframeSequenceMaxValueIncrementer(dataSource, incrementerName);
85                }
86                else if (databaseType == DERBY) {
87                        return new DerbyMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
88                }
89                else if (databaseType == HSQL) {
90                        return new HsqlMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
91                }
92                else if (databaseType == H2) {
93                        return new H2SequenceMaxValueIncrementer(dataSource, incrementerName);
94                }
95                else if (databaseType == MYSQL) {
96                        return new MySQLMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
97                }
98                else if (databaseType == ORACLE) {
99                        return new OracleSequenceMaxValueIncrementer(dataSource, incrementerName);
100                }
101                else if (databaseType == POSTGRES) {
102                        return new PostgreSQLSequenceMaxValueIncrementer(dataSource, incrementerName);
103                }
104                else if (databaseType == SQLSERVER) {
105                        return new SqlServerMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
106                }
107                else if (databaseType == SYBASE) {
108                        return new SybaseMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
109                }
110                throw new IllegalArgumentException("databaseType argument was not on the approved list");
111 
112        }
113 
114    @Override
115        public boolean isSupportedIncrementerType(String incrementerType) {
116                for (DatabaseType type : DatabaseType.values()) {
117                        if (type.name().equals(incrementerType.toUpperCase())) {
118                                return true;
119                        }
120                }
121 
122                return false;
123        }
124 
125    @Override
126        public String[] getSupportedIncrementerTypes() {
127 
128                List<String> types = new ArrayList<String>();
129 
130                for (DatabaseType type : DatabaseType.values()) {
131                        types.add(type.name());
132                }
133 
134                return types.toArray(new String[types.size()]);
135        }
136}

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