java/sql-dk/src/info/globalcode/sql/dk/SQLType.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 26 Dec 2013 11:58:14 +0100
branchv_0
changeset 68 574cd7fbb5b2
child 92 1399ac70a5bd
permissions -rw-r--r--
SQLType enum wrapper for java.sql.Types
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * SQL-DK
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
package info.globalcode.sql.dk;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
import java.sql.Types;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
 *
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
 * @author Ing. František Kučera (frantovo.cz)
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
 */
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
public enum SQLType {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	VARCHAR(Types.VARCHAR),
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
	BOOLEAN(Types.BOOLEAN),
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
	INTEGER(Types.INTEGER),
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	DECIMAL(Types.DECIMAL);
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	 * TODO: more types
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	 */
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	private int code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	private SQLType(int code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		this.code = code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	 * @see java.sql.Types.Types
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	 */
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	public int getCode() {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		return code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	 * @param code see {@linkplain java.sql.Types.Types}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	 * @return found SQLType
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	 * @throws IllegalArgumentException if no data type has given code
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	 */
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	public SQLType valueOf(int code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		for (SQLType t : values()) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
			if (t.code == code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
				return t;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
			}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		throw new IllegalArgumentException("No data type has code: " + code);
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
}