java/sql-dk/src/info/globalcode/sql/dk/SQLType.java
author František Kučera <franta-hg@frantovo.cz>
Fri, 27 Dec 2013 19:33:46 +0100
branchv_0
changeset 86 6b0eb3b22eb8
parent 68 574cd7fbb5b2
child 92 1399ac70a5bd
permissions -rw-r--r--
log SQLWarnings
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@68
    23
 *
franta-hg@68
    24
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@68
    25
 */
franta-hg@68
    26
public enum SQLType {
franta-hg@68
    27
franta-hg@68
    28
	VARCHAR(Types.VARCHAR),
franta-hg@68
    29
	BOOLEAN(Types.BOOLEAN),
franta-hg@68
    30
	INTEGER(Types.INTEGER),
franta-hg@68
    31
	DECIMAL(Types.DECIMAL);
franta-hg@68
    32
	/**
franta-hg@68
    33
	 * TODO: more types
franta-hg@68
    34
	 */
franta-hg@68
    35
	private int code;
franta-hg@68
    36
franta-hg@68
    37
	private SQLType(int code) {
franta-hg@68
    38
		this.code = code;
franta-hg@68
    39
	}
franta-hg@68
    40
franta-hg@68
    41
	/**
franta-hg@68
    42
	 * @see java.sql.Types.Types
franta-hg@68
    43
	 */
franta-hg@68
    44
	public int getCode() {
franta-hg@68
    45
		return code;
franta-hg@68
    46
	}
franta-hg@68
    47
franta-hg@68
    48
	/**
franta-hg@68
    49
	 * @param code see {@linkplain java.sql.Types.Types}
franta-hg@68
    50
	 * @return found SQLType
franta-hg@68
    51
	 * @throws IllegalArgumentException if no data type has given code
franta-hg@68
    52
	 */
franta-hg@68
    53
	public SQLType valueOf(int code) {
franta-hg@68
    54
		for (SQLType t : values()) {
franta-hg@68
    55
			if (t.code == code) {
franta-hg@68
    56
				return t;
franta-hg@68
    57
			}
franta-hg@68
    58
		}
franta-hg@68
    59
		throw new IllegalArgumentException("No data type has code: " + code);
franta-hg@68
    60
	}
franta-hg@68
    61
}