15 * You should have received a copy of the GNU General Public License |
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/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 package info.globalcode.sql.dk.formatting; |
18 package info.globalcode.sql.dk.formatting; |
19 |
19 |
|
20 import java.sql.ResultSetMetaData; |
|
21 import java.sql.SQLException; |
|
22 import java.util.ArrayList; |
|
23 import java.util.List; |
|
24 |
20 /** |
25 /** |
21 * |
26 * |
22 * @author Ing. František Kučera (frantovo.cz) |
27 * @author Ing. František Kučera (frantovo.cz) |
23 */ |
28 */ |
24 public class ColumnsHeader { |
29 public class ColumnsHeader { |
25 |
30 |
|
31 ResultSetMetaData metaData; |
|
32 |
|
33 public ColumnsHeader(ResultSetMetaData metaData) { |
|
34 this.metaData = metaData; |
|
35 } |
|
36 |
26 public int getColumnCount() { |
37 public int getColumnCount() { |
27 /** |
38 try { |
28 * TODO: getColumnCount |
39 return metaData.getColumnCount(); |
29 */ |
40 } catch (SQLException e) { |
30 throw new RuntimeException("Not yet implemented"); |
41 throw new IllegalStateException("Error during getting column count.", e); |
|
42 } |
31 } |
43 } |
32 /** |
44 |
33 * TODO: columns descriptor |
45 public List<ColumnDescriptor> getColumnDescriptors() { |
34 */ |
46 try { |
|
47 int count = metaData.getColumnCount(); |
|
48 List<ColumnDescriptor> list = new ArrayList<>(count); |
|
49 |
|
50 for (int i = 1; i <= count; i++) { |
|
51 ColumnDescriptor cd = new ColumnDescriptor(); |
|
52 cd.setLabel(metaData.getColumnLabel(i)); |
|
53 cd.setName(metaData.getColumnName(i)); |
|
54 cd.setType(metaData.getColumnType(i)); |
|
55 cd.setTypeName(metaData.getColumnTypeName(i)); |
|
56 /** TODO: more properties */ |
|
57 list.add(cd); |
|
58 } |
|
59 |
|
60 return list; |
|
61 } catch (SQLException e) { |
|
62 throw new IllegalStateException("Error during building column descriptors.", e); |
|
63 } |
|
64 } |
35 } |
65 } |