/** * Copyright (C) 2008 Mathieu Carbou <mathieu.carbou@gmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mycila.testing.plugin.db.api; import java.math.BigDecimal; import java.net.URL; import java.sql.Array; import java.sql.Blob; import java.sql.Clob; import java.sql.Date; import java.sql.Ref; import java.sql.Struct; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; /** * <P>The class that defines the constants that are used to identify generic * SQL types, called JDBC types. * The actual type constant values are equivalent to those in XOPEN. * <p/> * This class is never instantiated. * <p/> * See http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/mapping.html */ public enum SqlType { /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>BIT</code>. */ BIT(Types.BIT, Boolean.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>TINYINT</code>. */ TINYINT(Types.TINYINT, Byte.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>SMALLINT</code>. */ SMALLINT(Types.SMALLINT, Short.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>INTEGER</code>. */ INTEGER(Types.INTEGER, Integer.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>BIGINT</code>. */ BIGINT(Types.BIGINT, Long.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>FLOAT</code>. */ FLOAT(Types.FLOAT, Double.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>REAL</code>. */ REAL(Types.REAL, Float.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>DOUBLE</code>. */ DOUBLE(Types.DOUBLE, Double.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>NUMERIC</code>. */ NUMERIC(Types.NUMERIC, BigDecimal.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>DECIMAL</code>. */ DECIMAL(Types.DECIMAL, BigDecimal.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>CHAR</code>. */ CHAR(Types.CHAR, String.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>VARCHAR</code>. */ VARCHAR(Types.VARCHAR, String.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>LONGVARCHAR</code>. */ LONGVARCHAR(Types.LONGVARCHAR, String.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>DATE</code>. */ DATE(Types.DATE, Date.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>TIME</code>. */ TIME(Types.TIME, Time.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>TIMESTAMP</code>. */ TIMESTAMP(Types.TIMESTAMP, Timestamp.class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>BINARY</code>. */ BINARY(Types.BINARY, byte[].class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>VARBINARY</code>. */ VARBINARY(Types.VARBINARY, byte[].class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>LONGVARBINARY</code>. */ LONGVARBINARY(Types.LONGVARBINARY, byte[].class), /** * <P>The constant in the Java programming language, sometimes referred * to as a type code, that identifies the generic SQL type * <code>NULL</code>. */ NULL(Types.NULL, Void.class), /** * The constant in the Java programming language that indicates * that the SQL type is database-specific and * gets mapped to a Java object that can be accessed via * the methods <code>getObject</code> and <code>setObject</code>. */ OTHER(Types.OTHER, Object.class), /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type * <code>JAVA_OBJECT</code>. * * @since 1.2 */ JAVA_OBJECT(Types.JAVA_OBJECT, Class.class), /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type * <code>DISTINCT</code>. * * @since 1.2 */ DISTINCT(Types.DISTINCT, Object.class), /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type * <code>STRUCT</code>. * * @since 1.2 */ STRUCT(Types.STRUCT, Struct.class), /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type * <code>ARRAY</code>. * * @since 1.2 */ ARRAY(Types.ARRAY, Array.class), /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type * <code>BLOB</code>. * * @since 1.2 */ BLOB(Types.BLOB, Blob.class), /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type * <code>CLOB</code>. * * @since 1.2 */ CLOB(Types.CLOB, Clob.class), /** * The constant in the Java programming language, sometimes referred to * as a type code, that identifies the generic SQL type * <code>REF</code>. * * @since 1.2 */ REF(Types.REF, Ref.class), /** * The constant in the Java programming language, somtimes referred to * as a type code, that identifies the generic SQL type <code>DATALINK</code>. * * @since 1.4 */ DATALINK(Types.DATALINK, URL.class), /** * The constant in the Java programming language, somtimes referred to * as a type code, that identifies the generic SQL type <code>BOOLEAN</code>. * * @since 1.4 */ BOOLEAN(Types.BOOLEAN, Boolean.class), UNKNOWN(-1, Object.class); private final Class<?> javaType; private final int sqlType; private SqlType(int sqlType, Class<?> javaType) { this.sqlType = sqlType; this.javaType = javaType; } public int sqlType() { return sqlType; } public Class<?> javaType() { return javaType; } public static SqlType fromSqlType(int sqlType) { for (SqlType type : values()) { if (type.sqlType() == sqlType) { return type; } } return UNKNOWN; } }