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