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
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
92
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    28
	BIT(Types.BIT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    29
	TINYINT(Types.TINYINT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    30
	SMALLINT(Types.SMALLINT),
68
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	INTEGER(Types.INTEGER),
92
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    32
	BIGINT(Types.BIGINT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    33
	FLOAT(Types.FLOAT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    34
	REAL(Types.REAL),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    35
	DOUBLE(Types.DOUBLE),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    36
	NUMERIC(Types.NUMERIC),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    37
	DECIMAL(Types.DECIMAL),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    38
	CHAR(Types.CHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    39
	VARCHAR(Types.VARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    40
	LONGVARCHAR(Types.LONGVARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    41
	DATE(Types.DATE),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    42
	TIME(Types.TIME),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    43
	TIMESTAMP(Types.TIMESTAMP),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    44
	BINARY(Types.BINARY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    45
	VARBINARY(Types.VARBINARY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    46
	LONGVARBINARY(Types.LONGVARBINARY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    47
	NULL(Types.NULL),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    48
	OTHER(Types.OTHER),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    49
	JAVA_OBJECT(Types.JAVA_OBJECT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    50
	DISTINCT(Types.DISTINCT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    51
	STRUCT(Types.STRUCT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    52
	ARRAY(Types.ARRAY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    53
	BLOB(Types.BLOB),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    54
	CLOB(Types.CLOB),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    55
	REF(Types.REF),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    56
	DATALINK(Types.DATALINK),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    57
	BOOLEAN(Types.BOOLEAN),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    58
	ROWID(Types.ROWID),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    59
	NCHAR(Types.NCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    60
	NVARCHAR(Types.NVARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    61
	LONGNVARCHAR(Types.LONGNVARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    62
	NCLOB(Types.NCLOB),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    63
	SQLXML(Types.SQLXML);
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    64
	/** value from java.sql.Types */
68
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
	private int code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
	private SQLType(int code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		this.code = code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
	/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
	 * @see java.sql.Types.Types
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	 */
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	public int getCode() {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
		return code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
	/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
	 * @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
    80
	 * @return found SQLType
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
	 * @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
    82
	 */
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
	public SQLType valueOf(int code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		for (SQLType t : values()) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
			if (t.code == code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
				return t;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
			}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
		}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
		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
    90
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
}