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/SQLType.java Mon Mar 04 20:15:24 2019 +0100
1.3 @@ -0,0 +1,95 @@
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;
1.22 +
1.23 +import java.sql.Types;
1.24 +
1.25 +/**
1.26 + * Data types of SQL parameters.
1.27 + *
1.28 + * @author Ing. František Kučera (frantovo.cz)
1.29 + */
1.30 +public enum SQLType {
1.31 +
1.32 + /**
1.33 + * Names must be upper case – user input is also converted to upper case → case insensitive
1.34 + */
1.35 + BIT(Types.BIT),
1.36 + TINYINT(Types.TINYINT),
1.37 + SMALLINT(Types.SMALLINT),
1.38 + INTEGER(Types.INTEGER),
1.39 + BIGINT(Types.BIGINT),
1.40 + FLOAT(Types.FLOAT),
1.41 + REAL(Types.REAL),
1.42 + DOUBLE(Types.DOUBLE),
1.43 + NUMERIC(Types.NUMERIC),
1.44 + DECIMAL(Types.DECIMAL),
1.45 + CHAR(Types.CHAR),
1.46 + VARCHAR(Types.VARCHAR),
1.47 + LONGVARCHAR(Types.LONGVARCHAR),
1.48 + DATE(Types.DATE),
1.49 + TIME(Types.TIME),
1.50 + TIMESTAMP(Types.TIMESTAMP),
1.51 + BINARY(Types.BINARY),
1.52 + VARBINARY(Types.VARBINARY),
1.53 + LONGVARBINARY(Types.LONGVARBINARY),
1.54 + NULL(Types.NULL),
1.55 + OTHER(Types.OTHER),
1.56 + JAVA_OBJECT(Types.JAVA_OBJECT),
1.57 + DISTINCT(Types.DISTINCT),
1.58 + STRUCT(Types.STRUCT),
1.59 + ARRAY(Types.ARRAY),
1.60 + BLOB(Types.BLOB),
1.61 + CLOB(Types.CLOB),
1.62 + REF(Types.REF),
1.63 + DATALINK(Types.DATALINK),
1.64 + BOOLEAN(Types.BOOLEAN),
1.65 + ROWID(Types.ROWID),
1.66 + NCHAR(Types.NCHAR),
1.67 + NVARCHAR(Types.NVARCHAR),
1.68 + LONGNVARCHAR(Types.LONGNVARCHAR),
1.69 + NCLOB(Types.NCLOB),
1.70 + SQLXML(Types.SQLXML);
1.71 + /** value from java.sql.Types */
1.72 + private int code;
1.73 +
1.74 + private SQLType(int code) {
1.75 + this.code = code;
1.76 + }
1.77 +
1.78 + /**
1.79 + * @see java.sql.Types.Types
1.80 + */
1.81 + public int getCode() {
1.82 + return code;
1.83 + }
1.84 +
1.85 + /**
1.86 + * @param code see {@linkplain java.sql.Types.Types}
1.87 + * @return found SQLType
1.88 + * @throws IllegalArgumentException if no data type has given code
1.89 + */
1.90 + public static SQLType valueOf(int code) {
1.91 + for (SQLType t : values()) {
1.92 + if (t.code == code) {
1.93 + return t;
1.94 + }
1.95 + }
1.96 + throw new IllegalArgumentException("No data type has code: " + code);
1.97 + }
1.98 +}