java/sql-dk/src/info/globalcode/sql/dk/formatting/ColumnsHeader.java
branchv_0
changeset 39 be8db46a38c3
parent 37 9e6f8e5d5f98
equal deleted inserted replaced
38:ff5bbc06ed29 39:be8db46a38c3
    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 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 				cd.setFirstColumn(i == 1);
    53 				cd.setFirstColumn(i == 1);
    53 				cd.setLastColumn(i == count);
    54 				cd.setLastColumn(i == count);
       
    55 				cd.setColumnNumber(i);
       
    56 				
    54 				cd.setLabel(metaData.getColumnLabel(i));
    57 				cd.setLabel(metaData.getColumnLabel(i));
    55 				cd.setName(metaData.getColumnName(i));
    58 				cd.setName(metaData.getColumnName(i));
    56 				cd.setType(metaData.getColumnType(i));
    59 				cd.setType(metaData.getColumnType(i));
    57 				cd.setTypeName(metaData.getColumnTypeName(i));
    60 				cd.setTypeName(metaData.getColumnTypeName(i));
    58 				/** TODO: more properties */
    61 				/** TODO: more properties */
    59 				list.add(cd);
    62 				list.add(cd);
    60 			}
    63 			}
    61 
    64 			
    62 			return list;
    65 			return list;
    63 		} catch (SQLException e) {
    66 		} catch (SQLException e) {
    64 			throw new IllegalStateException("Error during building column descriptors.", e);
    67 			throw new IllegalStateException("Error during building column descriptors.", e);
    65 		}
    68 		}
    66 	}
    69 	}