java/jdbc-loopback-driver/src/main/java/info/globalcode/jdbc/loopback/ResultSetMetaData.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:43:08 +0200
branchv_0
changeset 250 aae5009bd0af
parent 237 7e08730da258
permissions -rw-r--r--
fix license version: GNU GPLv3
     1 /**
     2  * SQL-DK
     3  * Copyright © 2014 František Kučera (frantovo.cz)
     4  *
     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.
     8  *
     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.
    13  *
    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/>.
    16  */
    17 package info.globalcode.jdbc.loopback;
    18 
    19 import java.sql.SQLException;
    20 import java.util.ArrayList;
    21 import java.util.List;
    22 
    23 /**
    24  *
    25  * @author Ing. František Kučera (frantovo.cz)
    26  */
    27 public class ResultSetMetaData extends AbstractResultSetMetaData {
    28 
    29 	private List<ColumnDescriptor> columns = new ArrayList<>();
    30 
    31 	public void addColumn(ColumnDescriptor cd) {
    32 		columns.add(cd);
    33 	}
    34 
    35 	@Override
    36 	public int getColumnCount() throws SQLException {
    37 		return columns.size();
    38 	}
    39 
    40 	@Override
    41 	public String getColumnLabel(int column) throws SQLException {
    42 		return columns.get(column - 1).label;
    43 	}
    44 
    45 	@Override
    46 	public String getColumnName(int column) throws SQLException {
    47 		return columns.get(column - 1).name;
    48 	}
    49 
    50 	@Override
    51 	public int getColumnType(int column) throws SQLException {
    52 		return columns.get(column - 1).type;
    53 	}
    54 
    55 	@Override
    56 	public String getColumnTypeName(int column) throws SQLException {
    57 		return columns.get(column - 1).typeName;
    58 	}
    59 
    60 	public static class ColumnDescriptor {
    61 
    62 		private final int type;
    63 		private final String typeName;
    64 		private final String label;
    65 		private final String name;
    66 
    67 		public ColumnDescriptor(int type, String typeName, String label, String name) {
    68 			this.type = type;
    69 			this.typeName = typeName;
    70 			this.label = label;
    71 			this.name = name;
    72 		}
    73 	}
    74 }