3 * Copyright © 2013 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package info.globalcode.sql.dk.formatting;
20 import java.sql.ResultSetMetaData;
21 import java.sql.SQLException;
22 import java.util.ArrayList;
23 import java.util.List;
27 * @author Ing. František Kučera (frantovo.cz)
29 public class ColumnsHeader {
31 private ResultSetMetaData metaData;
33 public ColumnsHeader(ResultSetMetaData metaData) {
34 this.metaData = metaData;
37 public int getColumnCount() {
39 return metaData.getColumnCount();
40 } catch (SQLException e) {
41 throw new IllegalStateException("Error during getting column count.", e);
45 public List<ColumnDescriptor> getColumnDescriptors() {
47 int count = metaData.getColumnCount();
48 List<ColumnDescriptor> list = new ArrayList<>(count);
50 for (int i = 1; i <= count; i++) {
51 ColumnDescriptor cd = new ColumnDescriptor();
53 cd.setFirstColumn(i == 1);
54 cd.setLastColumn(i == count);
55 cd.setColumnNumber(i);
57 cd.setLabel(metaData.getColumnLabel(i));
58 cd.setName(metaData.getColumnName(i));
59 cd.setType(metaData.getColumnType(i));
60 cd.setTypeName(metaData.getColumnTypeName(i));
61 /** TODO: more properties */
66 } catch (SQLException e) {
67 throw new IllegalStateException("Error during building column descriptors.", e);