java/sql-dk/src/main/java/info/globalcode/sql/dk/formatting/ColumnDescriptor.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/sql-dk/src/main/java/info/globalcode/sql/dk/formatting/ColumnDescriptor.java Mon Mar 04 20:15:24 2019 +0100
1.3 @@ -0,0 +1,122 @@
1.4 +/**
1.5 + * SQL-DK
1.6 + * Copyright © 2013 František Kučera (frantovo.cz)
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation, either version 3 of the License, or
1.11 + * (at your option) any later version.
1.12 + *
1.13 + * This program is distributed in the hope that it will be useful,
1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.16 + * GNU General Public License for more details.
1.17 + *
1.18 + * You should have received a copy of the GNU General Public License
1.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.20 + */
1.21 +package info.globalcode.sql.dk.formatting;
1.22 +
1.23 +import java.sql.Types;
1.24 +
1.25 +/**
1.26 + *
1.27 + * @author Ing. František Kučera (frantovo.cz)
1.28 + */
1.29 +public class ColumnDescriptor {
1.30 +
1.31 + private String name;
1.32 + private String label;
1.33 + private int type;
1.34 + private String typeName;
1.35 + private boolean firstColumn;
1.36 + private boolean lastColumn;
1.37 + private int columnNumber;
1.38 +
1.39 + /**
1.40 + * @return column name
1.41 + * @see #getLabel()
1.42 + */
1.43 + public String getName() {
1.44 + return name;
1.45 + }
1.46 +
1.47 + public void setName(String name) {
1.48 + this.name = name;
1.49 + }
1.50 +
1.51 + /**
1.52 + * @return label specified by the SQL AS clause
1.53 + */
1.54 + public String getLabel() {
1.55 + return label;
1.56 + }
1.57 +
1.58 + public void setLabel(String label) {
1.59 + this.label = label;
1.60 + }
1.61 +
1.62 + public int getType() {
1.63 + return type;
1.64 + }
1.65 +
1.66 + public void setType(int type) {
1.67 + this.type = type;
1.68 + }
1.69 +
1.70 + public String getTypeName() {
1.71 + return typeName;
1.72 + }
1.73 +
1.74 + public void setTypeName(String typeName) {
1.75 + this.typeName = typeName;
1.76 + }
1.77 +
1.78 + public boolean isFirstColumn() {
1.79 + return firstColumn;
1.80 + }
1.81 +
1.82 + public void setFirstColumn(boolean firstColumn) {
1.83 + this.firstColumn = firstColumn;
1.84 + }
1.85 +
1.86 + public boolean isLastColumn() {
1.87 + return lastColumn;
1.88 + }
1.89 +
1.90 + public void setLastColumn(boolean lastColumn) {
1.91 + this.lastColumn = lastColumn;
1.92 + }
1.93 +
1.94 + /**
1.95 + * @return number of this column, 1 = first
1.96 + */
1.97 + public int getColumnNumber() {
1.98 + return columnNumber;
1.99 + }
1.100 +
1.101 + public void setColumnNumber(int columnNumber) {
1.102 + this.columnNumber = columnNumber;
1.103 + }
1.104 +
1.105 + public boolean isBoolean() {
1.106 + return type == Types.BOOLEAN;
1.107 + }
1.108 +
1.109 + public boolean isNumeric() {
1.110 + switch (type) {
1.111 + case Types.BIGINT:
1.112 + case Types.DECIMAL:
1.113 + case Types.DOUBLE:
1.114 + case Types.FLOAT:
1.115 + case Types.INTEGER:
1.116 + case Types.NUMERIC:
1.117 + case Types.REAL:
1.118 + case Types.SMALLINT:
1.119 + case Types.TINYINT:
1.120 + return true;
1.121 + default:
1.122 + return false;
1.123 + }
1.124 + }
1.125 +}