author | František Kučera <franta-hg@frantovo.cz> |
Mon, 18 May 2015 00:36:23 +0200 | |
branch | v_0 |
changeset 197 | 7a2f535017e4 |
parent 39 | be8db46a38c3 |
permissions | -rw-r--r-- |
franta-hg@22 | 1 |
/** |
franta-hg@22 | 2 |
* SQL-DK |
franta-hg@22 | 3 |
* Copyright © 2013 František Kučera (frantovo.cz) |
franta-hg@22 | 4 |
* |
franta-hg@22 | 5 |
* This program is free software: you can redistribute it and/or modify |
franta-hg@22 | 6 |
* it under the terms of the GNU General Public License as published by |
franta-hg@22 | 7 |
* the Free Software Foundation, either version 3 of the License, or |
franta-hg@22 | 8 |
* (at your option) any later version. |
franta-hg@22 | 9 |
* |
franta-hg@22 | 10 |
* This program is distributed in the hope that it will be useful, |
franta-hg@22 | 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
franta-hg@22 | 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
franta-hg@22 | 13 |
* GNU General Public License for more details. |
franta-hg@22 | 14 |
* |
franta-hg@22 | 15 |
* You should have received a copy of the GNU General Public License |
franta-hg@22 | 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
franta-hg@22 | 17 |
*/ |
franta-hg@22 | 18 |
package info.globalcode.sql.dk.formatting; |
franta-hg@22 | 19 |
|
franta-hg@23 | 20 |
import java.sql.ResultSetMetaData; |
franta-hg@23 | 21 |
import java.sql.SQLException; |
franta-hg@23 | 22 |
import java.util.ArrayList; |
franta-hg@23 | 23 |
import java.util.List; |
franta-hg@23 | 24 |
|
franta-hg@22 | 25 |
/** |
franta-hg@22 | 26 |
* |
franta-hg@22 | 27 |
* @author Ing. František Kučera (frantovo.cz) |
franta-hg@22 | 28 |
*/ |
franta-hg@22 | 29 |
public class ColumnsHeader { |
franta-hg@39 | 30 |
|
franta-hg@37 | 31 |
private ResultSetMetaData metaData; |
franta-hg@39 | 32 |
|
franta-hg@23 | 33 |
public ColumnsHeader(ResultSetMetaData metaData) { |
franta-hg@23 | 34 |
this.metaData = metaData; |
franta-hg@23 | 35 |
} |
franta-hg@39 | 36 |
|
franta-hg@22 | 37 |
public int getColumnCount() { |
franta-hg@23 | 38 |
try { |
franta-hg@23 | 39 |
return metaData.getColumnCount(); |
franta-hg@23 | 40 |
} catch (SQLException e) { |
franta-hg@23 | 41 |
throw new IllegalStateException("Error during getting column count.", e); |
franta-hg@23 | 42 |
} |
franta-hg@22 | 43 |
} |
franta-hg@39 | 44 |
|
franta-hg@23 | 45 |
public List<ColumnDescriptor> getColumnDescriptors() { |
franta-hg@23 | 46 |
try { |
franta-hg@23 | 47 |
int count = metaData.getColumnCount(); |
franta-hg@23 | 48 |
List<ColumnDescriptor> list = new ArrayList<>(count); |
franta-hg@39 | 49 |
|
franta-hg@23 | 50 |
for (int i = 1; i <= count; i++) { |
franta-hg@23 | 51 |
ColumnDescriptor cd = new ColumnDescriptor(); |
franta-hg@39 | 52 |
|
franta-hg@37 | 53 |
cd.setFirstColumn(i == 1); |
franta-hg@37 | 54 |
cd.setLastColumn(i == count); |
franta-hg@39 | 55 |
cd.setColumnNumber(i); |
franta-hg@39 | 56 |
|
franta-hg@23 | 57 |
cd.setLabel(metaData.getColumnLabel(i)); |
franta-hg@23 | 58 |
cd.setName(metaData.getColumnName(i)); |
franta-hg@23 | 59 |
cd.setType(metaData.getColumnType(i)); |
franta-hg@23 | 60 |
cd.setTypeName(metaData.getColumnTypeName(i)); |
franta-hg@23 | 61 |
/** TODO: more properties */ |
franta-hg@23 | 62 |
list.add(cd); |
franta-hg@23 | 63 |
} |
franta-hg@39 | 64 |
|
franta-hg@23 | 65 |
return list; |
franta-hg@23 | 66 |
} catch (SQLException e) { |
franta-hg@23 | 67 |
throw new IllegalStateException("Error during building column descriptors.", e); |
franta-hg@23 | 68 |
} |
franta-hg@23 | 69 |
} |
franta-hg@22 | 70 |
} |