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

org.jooq.DataType Maven / Gradle / Ivy

There is a newer version: 3.19.11
Show newest version
/**
 * Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com)
 * All rights reserved.
 *
 * 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;

import java.io.Serializable;
import java.sql.Types;
import java.util.Collection;
import java.util.List;

import org.jooq.exception.DataTypeException;
import org.jooq.impl.SQLDataType;
import org.jooq.tools.Convert;
import org.jooq.types.DayToSecond;
import org.jooq.types.YearToMonth;

/**
 * A common interface to all dialect-specific data types.
 *
 * @param  The Java type associated with this SQL data type
 * @author Lukas Eder
 */
public interface DataType extends Serializable {

    /**
     * Get the standard SQL data type of this (dialect-specific) data type if
     * available.
     */
    DataType getSQLDataType();

    /**
     * The dialect-specific data type representing this data type.
     */
    DataType getDataType(Configuration configuration);

    /**
     * Get JDBC {@link Types} value.
     */
    int getSQLType();

    /**
     * Get the data type binding associated with this data type.
     */
    Binding getBinding();

    /**
     * Get the converter associated with this data type.
     */
    Converter getConverter();

    /**
     * Retrieve the Java type associated with this data type.
     */
    Class getType();

    /**
     * Retrieve the Java type associated with ARRAYs of this data type.
     */
    Class getArrayType();

    /**
     * Retrieve the data type for an ARRAY of this data type.
     */
    DataType getArrayDataType();








    /**
     * Retrieve the data type for a given enum data type.
     */
     DataType asEnumDataType(Class enumDataType);

    /**
     * Retrieve the data type for a given converter.
     */
     DataType asConvertedDataType(Converter converter);

    /**
     * Retrieve the data type for a given binding.
     */
     DataType asConvertedDataType(Binding binding);

    /**
     * Retrieve the dialect-specific type name associated with this data type.
     */
    String getTypeName();

    /**
     * Retrieve the dialect-specific type name associated with this data type.
     */
    String getTypeName(Configuration configuration);

    /**
     * Retrieve the dialect-specific type name associated with this data type
     * used for casting.
     * 

* This is useful for some dialects that have specialised type names for * cast expressions. Other dialects require type-length binding when * casting, (e.g. VARCHAR(32767)) */ String getCastTypeName(); /** * Retrieve the dialect-specific type name associated with this data type * used for casting. *

* This is useful for some dialects that have specialised type names for * cast expressions. Other dialects require type-length binding when * casting, (e.g. VARCHAR(32767)) */ String getCastTypeName(Configuration configuration); /** * Retrieve the underlying {@link SQLDialect}. */ SQLDialect getDialect(); /** * Convert an arbitrary object into <T>. *

* See {@link Convert#convert(Object, Class)} for details about conversion rules. * * @param object The object to be converted * @return The converted object * @throws DataTypeException If conversion fails. */ T convert(Object object); /** * Convert an arbitrary set of objects into <T>. *

* See {@link Convert#convert(Object, Class)} for details about conversion rules. * * @param objects The objects to be converted * @return The converted objects * @throws DataTypeException If conversion fails. */ T[] convert(Object... objects); /** * Convert an arbitrary set of objects into <T>. *

* See {@link Convert#convert(Object, Class)} for details about conversion rules. * * @param objects The objects to be converted * @return The converted objects * @throws DataTypeException If conversion fails. */ List convert(Collection objects); /** * Return a new data type like this, with a new nullability. * * @param nullable The new nullability * @return The new data type */ DataType nullable(boolean nullable); /** * Get the nullability of this data type. * * @return The nullability */ boolean nullable(); /** * Specify an expression to be applied as the DEFAULT value for * this data type. * * @see #defaultValue(Field) */ DataType defaultValue(T defaultValue); /** * Specify an expression to be applied as the DEFAULT value for * this data type. *

* A default value of a data type applies to DDL statements, such as *

    *
  • CREATE TABLE
  • *
  • ALTER TABLE
  • *
*

* The distinct types of possible DEFAULT expressions is * defined by the underlying database. Please refer to your database manual * to learn what expressions are possible. */ DataType defaultValue(Field defaultValue); /** * The expression to be applied as the DEFAULT value for this * data type. * * @return The default value if present, or null if no default * value is specified for this data type. * @see #defaultValue(Field) */ Field defaultValue(); /** * Return a new data type like this, with a new defaultability. * * @param defaulted The new defaultability * @return The new data type * * @deprecated - [#3852] - 3.8.0 - Use {@link #defaultValue(Field)} instead. */ @Deprecated DataType defaulted(boolean defaulted); /** * Get the defaultability of this data type. * * @return The defaultability */ boolean defaulted(); /** * Return a new data type like this, with a new precision value. *

* This will have no effect if {@link #hasPrecision()} is false *

* This is the same as calling {@link #precision(int, int)} with * scale == 0 * * @param precision The new precision value * @return The new data type */ DataType precision(int precision); /** * Return a new data type like this, with a new precision and scale value. *

* This will have no effect if {@link #hasPrecision()} is false * , or if scale > 0 and {@link #hasScale()} is * false * * @param precision The new precision value * @param scale The new scale value * @return The new data type */ DataType precision(int precision, int scale); /** * Get the precision of this data type. * * @return The precision of this data type */ int precision(); /** * Whether this data type has a precision. * * @return Whether this data type has a precision */ boolean hasPrecision(); /** * Return a new data type like this, with a new scale value. *

* This will have no effect if {@link #hasScale()} is false * * @param scale The new scale value * @return The new data type */ DataType scale(int scale); /** * Get the scale of this data type. * * @return The scale of this data type */ int scale(); /** * Whether this data type has a scale. * * @return Whether this data type has a scale */ boolean hasScale(); /** * Return a new data type like this, with a new length value. *

* This will have no effect if {@link #hasLength()} is false * * @param length The new length value * @return The new data type */ DataType length(int length); /** * Get the length of this data type. * * @return The length of this data type */ int length(); /** * Whether this data type has a length. * * @return Whether this data type has a length */ boolean hasLength(); /** * Whether this data type is any numeric data type. *

* This applies to any of these types: *

    *
  • {@link SQLDataType#TINYINT}
  • *
  • {@link SQLDataType#SMALLINT}
  • *
  • {@link SQLDataType#INTEGER}
  • *
  • {@link SQLDataType#BIGINT}
  • *
  • {@link SQLDataType#FLOAT}
  • *
  • {@link SQLDataType#DOUBLE}
  • *
  • {@link SQLDataType#REAL}
  • *
  • {@link SQLDataType#DECIMAL}
  • *
  • {@link SQLDataType#DECIMAL_INTEGER}
  • *
  • {@link SQLDataType#NUMERIC}
  • *
*/ boolean isNumeric(); /** * Whether this data type is any character data type. *

* This applies to any of these types: *

    *
  • {@link SQLDataType#CHAR}
  • *
  • {@link SQLDataType#CLOB}
  • *
  • {@link SQLDataType#LONGNVARCHAR}
  • *
  • {@link SQLDataType#LONGVARCHAR}
  • *
  • {@link SQLDataType#NCHAR}
  • *
  • {@link SQLDataType#NCLOB}
  • *
  • {@link SQLDataType#NVARCHAR}
  • *
  • {@link SQLDataType#VARCHAR}
  • *
*/ boolean isString(); /** * Whether this data type is any date or time type. *

* This applies to any of these types. *

    *
  • {@link SQLDataType#DATE}
  • *
  • {@link SQLDataType#TIME}
  • *
  • {@link SQLDataType#TIMESTAMP}
  • *
  • {@link SQLDataType#LOCALDATE}
  • *
  • {@link SQLDataType#LOCALTIME}
  • *
  • {@link SQLDataType#LOCALDATETIME}
  • *
  • {@link SQLDataType#OFFSETTIME}
  • *
  • {@link SQLDataType#OFFSETDATETIME}
  • *
*/ boolean isDateTime(); /** * Whether this data type is any date or time type. *

* This applies to any of these types. *

    *
  • {@link SQLDataType#DATE}
  • *
  • {@link SQLDataType#TIME}
  • *
  • {@link SQLDataType#TIMESTAMP}
  • *
  • {@link SQLDataType#LOCALDATE}
  • *
  • {@link SQLDataType#LOCALTIME}
  • *
  • {@link SQLDataType#LOCALDATETIME}
  • *
  • {@link SQLDataType#OFFSETTIME}
  • *
  • {@link SQLDataType#OFFSETDATETIME}
  • *
  • {@link YearToMonth}
  • *
  • {@link DayToSecond}
  • *
*

* This is a combination of {@link #isDateTime()} or {@link #isInterval()} */ boolean isTemporal(); /** * Whether this data type is any interval type. *

* This applies to any of these types. *

    *
  • {@link YearToMonth}
  • *
  • {@link DayToSecond}
  • *
*/ boolean isInterval(); /** * Whether this data type is any binary type. *

* This applies to any of these types. *

    *
  • {@link SQLDataType#BINARY}
  • *
  • {@link SQLDataType#BLOB}
  • *
  • {@link SQLDataType#LONGVARBINARY}
  • *
  • {@link SQLDataType#VARBINARY}
  • *
*/ boolean isBinary(); /** * Whether this data type is best deserialised as a LOB. *

* This applies to any of these types. *

    *
  • {@link SQLDataType#BLOB}
  • *
  • {@link SQLDataType#CLOB}
  • *
  • {@link SQLDataType#NCLOB}
  • *
*/ boolean isLob(); /** * Whether this data type is an array type. */ boolean isArray(); }