java/sql-dk/src/info/globalcode/sql/dk/SQLType.java
author František Kučera <franta-hg@frantovo.cz>
Wed, 15 Jan 2014 21:06:12 +0100
branchv_0
changeset 159 9632b23df30c
parent 155 eb3676c6929b
permissions -rw-r--r--
InfoLister: list configured and configurable JDBC driver properties – option: --list-jdbc-properties
franta-hg@68
     1
/**
franta-hg@68
     2
 * SQL-DK
franta-hg@68
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@68
     4
 *
franta-hg@68
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@68
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@68
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@68
     8
 * (at your option) any later version.
franta-hg@68
     9
 *
franta-hg@68
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@68
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@68
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@68
    13
 * GNU General Public License for more details.
franta-hg@68
    14
 *
franta-hg@68
    15
 * You should have received a copy of the GNU General Public License
franta-hg@68
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@68
    17
 */
franta-hg@68
    18
package info.globalcode.sql.dk;
franta-hg@68
    19
franta-hg@68
    20
import java.sql.Types;
franta-hg@68
    21
franta-hg@68
    22
/**
franta-hg@155
    23
 * Data types of SQL parameters.
franta-hg@68
    24
 *
franta-hg@68
    25
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@68
    26
 */
franta-hg@68
    27
public enum SQLType {
franta-hg@68
    28
franta-hg@93
    29
	/**
franta-hg@93
    30
	 * Names must be upper case – user input is also converted to upper case → case insensitive
franta-hg@93
    31
	 */
franta-hg@92
    32
	BIT(Types.BIT),
franta-hg@92
    33
	TINYINT(Types.TINYINT),
franta-hg@92
    34
	SMALLINT(Types.SMALLINT),
franta-hg@92
    35
	INTEGER(Types.INTEGER),
franta-hg@92
    36
	BIGINT(Types.BIGINT),
franta-hg@92
    37
	FLOAT(Types.FLOAT),
franta-hg@92
    38
	REAL(Types.REAL),
franta-hg@92
    39
	DOUBLE(Types.DOUBLE),
franta-hg@92
    40
	NUMERIC(Types.NUMERIC),
franta-hg@92
    41
	DECIMAL(Types.DECIMAL),
franta-hg@92
    42
	CHAR(Types.CHAR),
franta-hg@68
    43
	VARCHAR(Types.VARCHAR),
franta-hg@92
    44
	LONGVARCHAR(Types.LONGVARCHAR),
franta-hg@92
    45
	DATE(Types.DATE),
franta-hg@92
    46
	TIME(Types.TIME),
franta-hg@92
    47
	TIMESTAMP(Types.TIMESTAMP),
franta-hg@92
    48
	BINARY(Types.BINARY),
franta-hg@92
    49
	VARBINARY(Types.VARBINARY),
franta-hg@92
    50
	LONGVARBINARY(Types.LONGVARBINARY),
franta-hg@92
    51
	NULL(Types.NULL),
franta-hg@92
    52
	OTHER(Types.OTHER),
franta-hg@92
    53
	JAVA_OBJECT(Types.JAVA_OBJECT),
franta-hg@92
    54
	DISTINCT(Types.DISTINCT),
franta-hg@92
    55
	STRUCT(Types.STRUCT),
franta-hg@92
    56
	ARRAY(Types.ARRAY),
franta-hg@92
    57
	BLOB(Types.BLOB),
franta-hg@92
    58
	CLOB(Types.CLOB),
franta-hg@92
    59
	REF(Types.REF),
franta-hg@92
    60
	DATALINK(Types.DATALINK),
franta-hg@68
    61
	BOOLEAN(Types.BOOLEAN),
franta-hg@92
    62
	ROWID(Types.ROWID),
franta-hg@92
    63
	NCHAR(Types.NCHAR),
franta-hg@92
    64
	NVARCHAR(Types.NVARCHAR),
franta-hg@92
    65
	LONGNVARCHAR(Types.LONGNVARCHAR),
franta-hg@92
    66
	NCLOB(Types.NCLOB),
franta-hg@92
    67
	SQLXML(Types.SQLXML);
franta-hg@92
    68
	/** value from java.sql.Types */
franta-hg@68
    69
	private int code;
franta-hg@68
    70
franta-hg@68
    71
	private SQLType(int code) {
franta-hg@68
    72
		this.code = code;
franta-hg@68
    73
	}
franta-hg@68
    74
franta-hg@68
    75
	/**
franta-hg@68
    76
	 * @see java.sql.Types.Types
franta-hg@68
    77
	 */
franta-hg@68
    78
	public int getCode() {
franta-hg@68
    79
		return code;
franta-hg@68
    80
	}
franta-hg@68
    81
franta-hg@68
    82
	/**
franta-hg@68
    83
	 * @param code see {@linkplain java.sql.Types.Types}
franta-hg@68
    84
	 * @return found SQLType
franta-hg@68
    85
	 * @throws IllegalArgumentException if no data type has given code
franta-hg@68
    86
	 */
franta-hg@146
    87
	public static SQLType valueOf(int code) {
franta-hg@68
    88
		for (SQLType t : values()) {
franta-hg@68
    89
			if (t.code == code) {
franta-hg@68
    90
				return t;
franta-hg@68
    91
			}
franta-hg@68
    92
		}
franta-hg@68
    93
		throw new IllegalArgumentException("No data type has code: " + code);
franta-hg@68
    94
	}
franta-hg@68
    95
}