25 /** |
25 /** |
26 * |
26 * |
27 * @author Ing. František Kučera (frantovo.cz) |
27 * @author Ing. František Kučera (frantovo.cz) |
28 */ |
28 */ |
29 public class ColumnsHeader { |
29 public class ColumnsHeader { |
30 |
30 |
31 private ResultSetMetaData metaData; |
31 private final ResultSetMetaData metaData; |
32 |
32 |
33 public ColumnsHeader(ResultSetMetaData metaData) { |
33 public ColumnsHeader(ResultSetMetaData metaData) { |
34 this.metaData = metaData; |
34 this.metaData = metaData; |
35 } |
35 } |
36 |
36 |
37 public int getColumnCount() { |
37 public int getColumnCount() { |
38 try { |
38 try { |
39 return metaData.getColumnCount(); |
39 return metaData.getColumnCount(); |
40 } catch (SQLException e) { |
40 } catch (SQLException e) { |
41 throw new IllegalStateException("Error during getting column count.", e); |
41 throw new IllegalStateException("Error during getting column count.", e); |
42 } |
42 } |
43 } |
43 } |
44 |
44 |
45 public List<ColumnDescriptor> getColumnDescriptors() { |
45 public List<ColumnDescriptor> getColumnDescriptors() { |
46 try { |
46 try { |
47 int count = metaData.getColumnCount(); |
47 int count = metaData.getColumnCount(); |
48 List<ColumnDescriptor> list = new ArrayList<>(count); |
48 List<ColumnDescriptor> list = new ArrayList<>(count); |
49 |
49 |
50 for (int i = 1; i <= count; i++) { |
50 for (int i = 1; i <= count; i++) { |
51 ColumnDescriptor cd = new ColumnDescriptor(); |
51 ColumnDescriptor cd = new ColumnDescriptor(); |
52 |
52 |
53 cd.setFirstColumn(i == 1); |
53 cd.setFirstColumn(i == 1); |
54 cd.setLastColumn(i == count); |
54 cd.setLastColumn(i == count); |
55 cd.setColumnNumber(i); |
55 cd.setColumnNumber(i); |
56 |
56 |
57 cd.setLabel(metaData.getColumnLabel(i)); |
57 cd.setLabel(metaData.getColumnLabel(i)); |
58 cd.setName(metaData.getColumnName(i)); |
58 cd.setName(metaData.getColumnName(i)); |
59 cd.setType(metaData.getColumnType(i)); |
59 cd.setType(metaData.getColumnType(i)); |
60 cd.setTypeName(metaData.getColumnTypeName(i)); |
60 cd.setTypeName(metaData.getColumnTypeName(i)); |
61 /** TODO: more properties */ |
61 cd.setTableName(metaData.getTableName(i)); |
62 list.add(cd); |
62 list.add(cd); |
63 } |
63 } |
64 |
64 |
65 return list; |
65 return list; |
66 } catch (SQLException e) { |
66 } catch (SQLException e) { |
67 throw new IllegalStateException("Error during building column descriptors.", e); |
67 throw new IllegalStateException("Error during building column descriptors.", e); |
68 } |
68 } |
69 } |
69 } |