All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jooq.impl.SQLDataType Maven / Gradle / Ivy

There is a newer version: 3.19.9
Show newest version
/*
 * 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.
 *
 * Other licenses:
 * -----------------------------------------------------------------------------
 * Commercial licenses for this work are available. These replace the above
 * ASL 2.0 and offer limited warranties, support, maintenance, and commercial
 * database integrations.
 *
 * For more information, please visit: http://www.jooq.org/licenses
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
package org.jooq.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZonedDateTime;
import java.util.UUID;

import org.jooq.DataType;
import org.jooq.Record;
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.types.DayToSecond;
import org.jooq.types.UByte;
import org.jooq.types.UInteger;
import org.jooq.types.ULong;
import org.jooq.types.UShort;
import org.jooq.types.YearToMonth;
// ...
// ...
import org.jooq.util.cubrid.CUBRIDDataType;
// ...
import org.jooq.util.derby.DerbyDataType;
import org.jooq.util.firebird.FirebirdDataType;
import org.jooq.util.h2.H2DataType;
// ...
import org.jooq.util.hsqldb.HSQLDBDataType;
// ...
// ...
import org.jooq.util.mariadb.MariaDBDataType;
import org.jooq.util.mysql.MySQLDataType;
// ...
import org.jooq.util.postgres.PostgresDataType;
// ...
import org.jooq.util.sqlite.SQLiteDataType;
// ...
// ...
// ...



/**
 * The SQL standard data types, as described in {@link Types}.
 * 

* These types are usually the ones that are referenced by generated source * code. Most RDBMS have an almost 1:1 mapping between their vendor-specific * types and the ones in this class (except Oracle). Some RDBMS also have * extensions, e.g. for geospacial data types. See the dialect-specific data * type classes for more information. * * @author Lukas Eder */ public final class SQLDataType { // ------------------------------------------------------------------------- // String types // ------------------------------------------------------------------------- /** * The {@link Types#VARCHAR} type. */ public static final DataType VARCHAR = new DefaultDataType(null, String.class, "varchar"); /** * The {@link Types#VARCHAR} type. */ public static final DataType VARCHAR(int length) { return VARCHAR.length(length); } /** * The {@link Types#CHAR} type. */ public static final DataType CHAR = new DefaultDataType(null, String.class, "char"); /** * The {@link Types#CHAR} type. */ public static final DataType CHAR(int length) { return CHAR.length(length); } /** * The {@link Types#LONGVARCHAR} type. */ public static final DataType LONGVARCHAR = new DefaultDataType(null, String.class, "longvarchar"); /** * The {@link Types#LONGVARCHAR} type. */ public static final DataType LONGVARCHAR(int length) { return LONGVARCHAR.length(length); } /** * The {@link Types#CLOB} type. */ public static final DataType CLOB = new DefaultDataType(null, String.class, "clob"); /** * The {@link Types#CLOB} type. */ public static final DataType CLOB(int length) { return CLOB.length(length); } /** * The {@link Types#NVARCHAR} type. */ public static final DataType NVARCHAR = new DefaultDataType(null, String.class, "nvarchar"); /** * The {@link Types#NVARCHAR} type. */ public static final DataType NVARCHAR(int length) { return NVARCHAR.length(length); } /** * The {@link Types#NCHAR} type. */ public static final DataType NCHAR = new DefaultDataType(null, String.class, "nchar"); /** * The {@link Types#NCHAR} type. */ public static final DataType NCHAR(int length) { return NCHAR.length(length); } /** * The {@link Types#LONGNVARCHAR} type. */ public static final DataType LONGNVARCHAR = new DefaultDataType(null, String.class, "longnvarchar"); /** * The {@link Types#LONGNVARCHAR} type. */ public static final DataType LONGNVARCHAR(int length) { return LONGNVARCHAR.length(length); } /** * The {@link Types#NCLOB} type. */ public static final DataType NCLOB = new DefaultDataType(null, String.class, "nclob"); /** * The {@link Types#NCLOB} type. */ public static final DataType NCLOB(int length) { return NCLOB.length(length); } // ------------------------------------------------------------------------- // Boolean types // ------------------------------------------------------------------------- /** * The {@link Types#BOOLEAN} type. */ public static final DataType BOOLEAN = new DefaultDataType(null, Boolean.class, "boolean"); /** * The {@link Types#BIT} type. */ public static final DataType BIT = new DefaultDataType(null, Boolean.class, "bit"); // ------------------------------------------------------------------------- // Integer types // ------------------------------------------------------------------------- /** * The {@link Types#TINYINT} type. */ public static final DataType TINYINT = new DefaultDataType(null, Byte.class, "tinyint"); /** * The {@link Types#SMALLINT} type. */ public static final DataType SMALLINT = new DefaultDataType(null, Short.class, "smallint"); /** * The {@link Types#INTEGER} type. */ public static final DataType INTEGER = new DefaultDataType(null, Integer.class, "integer"); /** * The {@link Types#BIGINT} type. */ public static final DataType BIGINT = new DefaultDataType(null, Long.class, "bigint"); /** * The zero-scale {@link Types#DECIMAL} type. */ public static final DataType DECIMAL_INTEGER = new DefaultDataType(null, BigInteger.class, "decimal_integer"); // ------------------------------------------------------------------------- // Unsigned integer types // ------------------------------------------------------------------------- /** * The unsigned {@link Types#TINYINT} type. */ public static final DataType TINYINTUNSIGNED = new DefaultDataType(null, UByte.class, "tinyint unsigned"); /** * The unsigned {@link Types#SMALLINT} type. */ public static final DataType SMALLINTUNSIGNED = new DefaultDataType(null, UShort.class, "smallint unsigned"); /** * The unsigned {@link Types#INTEGER} type. */ public static final DataType INTEGERUNSIGNED = new DefaultDataType(null, UInteger.class, "integer unsigned"); /** * The unsigned {@link Types#BIGINT} type. */ public static final DataType BIGINTUNSIGNED = new DefaultDataType(null, ULong.class, "bigint unsigned"); // ------------------------------------------------------------------------- // Floating point types // ------------------------------------------------------------------------- /** * The {@link Types#DOUBLE} type. */ public static final DataType DOUBLE = new DefaultDataType(null, Double.class, "double"); /** * The {@link Types#FLOAT} type. */ public static final DataType FLOAT = new DefaultDataType(null, Double.class, "float"); /** * The {@link Types#REAL} type. */ public static final DataType REAL = new DefaultDataType(null, Float.class, "real"); // ------------------------------------------------------------------------- // Numeric types // ------------------------------------------------------------------------- /** * The {@link Types#NUMERIC} type. */ public static final DataType NUMERIC = new DefaultDataType(null, BigDecimal.class, "numeric"); /** * The {@link Types#NUMERIC} type. */ public static final DataType NUMERIC(int precision) { return NUMERIC.precision(precision); } /** * The {@link Types#NUMERIC} type. */ public static final DataType NUMERIC(int precision, int scale) { return NUMERIC.precision(precision, scale); } /** * The {@link Types#DECIMAL} type. */ public static final DataType DECIMAL = new DefaultDataType(null, BigDecimal.class, "decimal"); /** * The {@link Types#DECIMAL} type. */ public static final DataType DECIMAL(int precision) { return DECIMAL.precision(precision); } /** * The {@link Types#DECIMAL} type. */ public static final DataType DECIMAL(int precision, int scale) { return DECIMAL.precision(precision, scale); } // ------------------------------------------------------------------------- // Datetime types // ------------------------------------------------------------------------- /** * The {@link Types#DATE} type. */ public static final DataType DATE = new DefaultDataType(null, Date.class, "date"); /** * The {@link Types#TIMESTAMP} type. */ public static final DataType TIMESTAMP = new DefaultDataType(null, Timestamp.class, "timestamp"); /** * The {@link Types#TIME} type. */ public static final DataType

* The behaviour of this data type is influenced by the JDBC driver and the * database that is used. Some databases support actual time zones (as in * {@link ZonedDateTime}), other databases support only offsets (as in * {@link OffsetDateTime}). Some databases retain the actual time zone * information that is stored and reproduce it with every fetch (e.g. * {@link SQLDialect#ORACLE}), others use this type as a synonym for a * timestamp in UTC (e.g. {@link SQLDialect#POSTGRES}), producing possibly a * value in the current time zone of the database or the client. Please * refer to your database for more information about the behaviour of this * data type. */ public static final DataType OFFSETTIME = new DefaultDataType(null, OffsetTime.class, "time with time zone"); /** * The {@link Types#TIMESTAMP_WITH_TIMEZONE} type. *

* The behaviour of this data type is influenced by the JDBC driver and the * database that is used. Some databases support actual time zones (as in * {@link ZonedDateTime}), other databases support only offsets (as in * {@link OffsetDateTime}). Some databases retain the actual time zone * information that is stored and reproduce it with every fetch (e.g. * {@link SQLDialect#ORACLE}), others use this type as a synonym for a * timestamp in UTC (e.g. {@link SQLDialect#POSTGRES}), producing possibly a * value in the current time zone of the database or the client. Please * refer to your database for more information about the behaviour of this * data type. */ public static final DataType OFFSETDATETIME = new DefaultDataType(null, OffsetDateTime.class, "timestamp with time zone"); /** * The {@link Types#TIME_WITH_TIMEZONE} type. *

* An alias for {@link #OFFSETTIME} */ public static final DataType TIMEWITHTIMEZONE = OFFSETTIME; /** * The {@link Types#TIMESTAMP_WITH_TIMEZONE} type. *

* An alias for {@link #OFFSETDATETIME} */ public static final DataType TIMESTAMPWITHTIMEZONE = OFFSETDATETIME; // ------------------------------------------------------------------------- // Binary types // ------------------------------------------------------------------------- /** * The {@link Types#BINARY} type. */ public static final DataType BINARY = new DefaultDataType(null, byte[].class, "binary"); /** * The {@link Types#BINARY} type. */ public static final DataType BINARY(int length) { return BINARY.length(length); } /** * The {@link Types#VARBINARY} type. */ public static final DataType VARBINARY = new DefaultDataType(null, byte[].class, "varbinary"); /** * The {@link Types#VARBINARY} type. */ public static final DataType VARBINARY(int length) { return VARBINARY.length(length); } /** * The {@link Types#LONGVARBINARY} type. */ public static final DataType LONGVARBINARY = new DefaultDataType(null, byte[].class, "longvarbinary"); /** * The {@link Types#LONGVARBINARY} type. */ public static final DataType LONGVARBINARY(int length) { return LONGVARBINARY.length(length); } /** * The {@link Types#BLOB} type. */ public static final DataType BLOB = new DefaultDataType(null, byte[].class, "blob"); /** * The {@link Types#BLOB} type. */ public static final DataType BLOB(int length) { return BLOB.length(length); } // ------------------------------------------------------------------------- // Other types // ------------------------------------------------------------------------- /** * The {@link Types#OTHER} type. */ public static final DataType OTHER = new DefaultDataType(null, Object.class, "other"); /** * The {@link Types#STRUCT} type. */ public static final DataType RECORD = new DefaultDataType(null, Record.class, "record"); /** * The {@link ResultSet} type. *

* This is not a SQL or JDBC standard. This type emulates REF CURSOR types * and similar constructs */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static final DataType> RESULT = new DefaultDataType>(null, (Class) Result.class, "result"); /** * The {@link UUID} type. *

* This is not a SQL or JDBC standard. This type handles UUID types where * they are supported */ public static final DataType UUID = new DefaultDataType(null, UUID.class, "uuid"); // ------------------------------------------------------------------------- // Static initialisation of dialect-specific data types // ------------------------------------------------------------------------- static { // Load all dialect-specific data types // TODO [#650] Make this more reliable using a data type registry try { Class.forName(CUBRIDDataType.class.getName()); Class.forName(DerbyDataType.class.getName()); Class.forName(FirebirdDataType.class.getName()); Class.forName(H2DataType.class.getName()); Class.forName(HSQLDBDataType.class.getName()); Class.forName(MariaDBDataType.class.getName()); Class.forName(MySQLDataType.class.getName()); Class.forName(PostgresDataType.class.getName()); Class.forName(SQLiteDataType.class.getName()); } catch (Exception ignore) {} } /** * No instances */ private SQLDataType() {} }