tabular formatter: new option 'separateBy' to print horizontal separator on each change of given column
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, version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package info.globalcode.sql.dk.formatting;
19 import java.sql.ResultSetMetaData;
20 import java.sql.SQLException;
21 import java.util.ArrayList;
22 import java.util.List;
26 * @author Ing. František Kučera (frantovo.cz)
28 public class ColumnsHeader {
30 private final ResultSetMetaData metaData;
32 public ColumnsHeader(ResultSetMetaData metaData) {
33 this.metaData = metaData;
36 public int getColumnCount() {
38 return metaData.getColumnCount();
39 } catch (SQLException e) {
40 throw new IllegalStateException("Error during getting column count.", e);
44 public List<ColumnDescriptor> getColumnDescriptors() {
46 int count = metaData.getColumnCount();
47 List<ColumnDescriptor> list = new ArrayList<>(count);
49 for (int i = 1; i <= count; i++) {
50 ColumnDescriptor cd = new ColumnDescriptor();
52 cd.setFirstColumn(i == 1);
53 cd.setLastColumn(i == count);
54 cd.setColumnNumber(i);
56 cd.setLabel(metaData.getColumnLabel(i));
57 cd.setName(metaData.getColumnName(i));
58 cd.setType(metaData.getColumnType(i));
59 cd.setTypeName(metaData.getColumnTypeName(i));
60 cd.setTableName(metaData.getTableName(i));
65 } catch (SQLException e) {
66 throw new IllegalStateException("Error during building column descriptors.", e);