java/sql-dk/src/info/globalcode/sql/dk/SQLType.java
author František Kučera <franta-hg@frantovo.cz>
Wed, 08 Jan 2014 19:18:52 +0100
branchv_0
changeset 146 4f4f515df807
parent 93 5a4dbe6f962c
child 155 eb3676c6929b
permissions -rw-r--r--
BatchDecoder: basic decoder
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
93
5a4dbe6f962c Type names in --types option are case insensitive
František Kučera <franta-hg@frantovo.cz>
parents: 92
diff changeset
    28
	/**
5a4dbe6f962c Type names in --types option are case insensitive
František Kučera <franta-hg@frantovo.cz>
parents: 92
diff changeset
    29
	 * Names must be upper case – user input is also converted to upper case → case insensitive
5a4dbe6f962c Type names in --types option are case insensitive
František Kučera <franta-hg@frantovo.cz>
parents: 92
diff changeset
    30
	 */
92
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    31
	BIT(Types.BIT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    32
	TINYINT(Types.TINYINT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    33
	SMALLINT(Types.SMALLINT),
68
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	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
    35
	BIGINT(Types.BIGINT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    36
	FLOAT(Types.FLOAT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    37
	REAL(Types.REAL),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    38
	DOUBLE(Types.DOUBLE),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    39
	NUMERIC(Types.NUMERIC),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    40
	DECIMAL(Types.DECIMAL),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    41
	CHAR(Types.CHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    42
	VARCHAR(Types.VARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    43
	LONGVARCHAR(Types.LONGVARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    44
	DATE(Types.DATE),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    45
	TIME(Types.TIME),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    46
	TIMESTAMP(Types.TIMESTAMP),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    47
	BINARY(Types.BINARY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    48
	VARBINARY(Types.VARBINARY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    49
	LONGVARBINARY(Types.LONGVARBINARY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    50
	NULL(Types.NULL),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    51
	OTHER(Types.OTHER),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    52
	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
    53
	DISTINCT(Types.DISTINCT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    54
	STRUCT(Types.STRUCT),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    55
	ARRAY(Types.ARRAY),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    56
	BLOB(Types.BLOB),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    57
	CLOB(Types.CLOB),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    58
	REF(Types.REF),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    59
	DATALINK(Types.DATALINK),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    60
	BOOLEAN(Types.BOOLEAN),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    61
	ROWID(Types.ROWID),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    62
	NCHAR(Types.NCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    63
	NVARCHAR(Types.NVARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    64
	LONGNVARCHAR(Types.LONGNVARCHAR),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    65
	NCLOB(Types.NCLOB),
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    66
	SQLXML(Types.SQLXML);
1399ac70a5bd support all types from java.sql.Types.Types
František Kučera <franta-hg@frantovo.cz>
parents: 68
diff changeset
    67
	/** 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
    68
	private int 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
	private SQLType(int code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
		this.code = code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
	}
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
	/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
	 * @see java.sql.Types.Types
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
	public int getCode() {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
		return code;
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
	/**
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
	 * @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
    83
	 * @return found SQLType
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
	 * @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
    85
	 */
146
4f4f515df807 BatchDecoder: basic decoder
František Kučera <franta-hg@frantovo.cz>
parents: 93
diff changeset
    86
	public static SQLType valueOf(int code) {
68
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
		for (SQLType t : values()) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
			if (t.code == code) {
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
				return t;
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
		}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
		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
    93
	}
574cd7fbb5b2 SQLType enum wrapper for java.sql.Types
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
}