# Class TypesMapping

java.lang.Object
org.apache.cayenne.dba.TypesMapping

public class TypesMapping extends Object
A utility class that handles mappings of JDBC data types to the database types and Java types. Also contains methods that provide information about JDBC types.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `JAVA_BIGDECIMAL`
  `static final String`
  `JAVA_BIGINTEGER`
  `static final String`
  `JAVA_BLOB`
  `static final String`
  `JAVA_BOOLEAN`
  `static final String`
  `JAVA_BYTE`
  `static final String`
  `JAVA_BYTES`
  `static final String`
  `JAVA_DOUBLE`
  `static final String`
  `JAVA_FLOAT`
  `static final String`
  `JAVA_INTEGER`
  `static final String`
  `JAVA_LONG`
  `static final String`
  `JAVA_SHORT`
  `static final String`
  `JAVA_SQLDATE`
  `static final String`
  `JAVA_STRING`
  `static final String`
  `JAVA_TIME`
  `static final String`
  `JAVA_TIMESTAMP`
  `static final String`
  `JAVA_UTILDATE`
  `static final int`
  `NOT_DEFINED`
  `static final String`
  `SQL_ARRAY`
  `static final String`
  `SQL_BIGINT`
  `static final String`
  `SQL_BINARY`
  `static final String`
  `SQL_BIT`
  `static final String`
  `SQL_BLOB`
  `static final String`
  `SQL_BOOLEAN`
  `static final String`
  `SQL_CHAR`
  `static final String`
  `SQL_CLOB`
  `static final String`
  `SQL_DATE`
  `static final String`
  `SQL_DECIMAL`
  `static final String`
  `SQL_DOUBLE`
  `static final String`
  `SQL_FLOAT`
  `static final String`
  `SQL_INTEGER`
  `static final String`
  `SQL_LONGNVARCHAR`
  `static final String`
  `SQL_LONGVARBINARY`
  `static final String`
  `SQL_LONGVARCHAR`
  `static final String`
  `SQL_NCHAR`
  `static final String`
  `SQL_NCLOB`
  `static final String`
  `SQL_NULL`
  `static final String`
  `SQL_NUMERIC`
  `static final String`
  `SQL_NVARCHAR`
  `static final String`
  `SQL_OTHER`
  `static final String`
  `SQL_REAL`
  `static final String`
  `SQL_SMALLINT`
  `static final String`
  `SQL_SQLXML`
  `static final String`
  `SQL_TIME`
  `static final String`
  `SQL_TIMESTAMP`
  `static final String`
  `SQL_TINYINT`
  `static final String`
  `SQL_VARBINARY`
  `static final String`
  `SQL_VARCHAR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TypesMapping(DatabaseMetaData metaData)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String[]`
  `getDatabaseTypes()`
  Returns an array of string names of the default JDBC data types.
  `static String`
  `getJavaBySqlType(int type)`
  Get the corresponding Java type by its `Types` counterpart.
  `static String`
  `getJavaBySqlType(DbAttribute attribute)`
  `static String`
  `getSqlNameByType(int type)`
  Returns a String representation of the SQL type from its JDBC code.
  `static int`
  `getSqlTypeByJava(Class<?> javaClass)`
  Guesses a default JDBC type for the Java class.
  `static int`
  `getSqlTypeByJava(String className)`
  Returns default java.sql.Types type by the Java type name.
  `static int`
  `getSqlTypeByName(String typeName)`
  Returns a JDBC int type for SQL typem name.
  `static boolean`
  `isBinary(int type)`
  Returns true if supplied type is a binary type.
  `static boolean`
  `isCharacter(int type)`
  Returns true if supplied type is a character type.
  `static boolean`
  `isDateTime(int type)`
  `static boolean`
  `isDecimal(int type)`
  Returns true if supplied type is a decimal type.
  `static boolean`
  `isNumeric(int type)`
  Returns true if supplied type is a numeric type.
  `protected static String`
  `pickDataType(int jdbcType, org.apache.cayenne.dba.TypesMapping.TypeInfo[] alts)`
  Method implements an algorithm to pick a data type from a list of alternatives that most closely matches JDBC data type.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### NOT_DEFINED

    public static final int NOT_DEFINED
    See Also:
      - Constant Field Values

  - ### SQL_ARRAY

    public static final String SQL_ARRAY
    See Also:
      - Constant Field Values

  - ### SQL_BIGINT

    public static final String SQL_BIGINT
    See Also:
      - Constant Field Values

  - ### SQL_BINARY

    public static final String SQL_BINARY
    See Also:
      - Constant Field Values

  - ### SQL_BIT

    public static final String SQL_BIT
    See Also:
      - Constant Field Values

  - ### SQL_BLOB

    public static final String SQL_BLOB
    See Also:
      - Constant Field Values

  - ### SQL_BOOLEAN

    public static final String SQL_BOOLEAN
    Since:
      1.2
    See Also:
      - Constant Field Values

  - ### SQL_CLOB

    public static final String SQL_CLOB
    See Also:
      - Constant Field Values

  - ### SQL_NCLOB

    public static final String SQL_NCLOB
    See Also:
      - Constant Field Values

  - ### SQL_CHAR

    public static final String SQL_CHAR
    See Also:
      - Constant Field Values

  - ### SQL_NCHAR

    public static final String SQL_NCHAR
    See Also:
      - Constant Field Values

  - ### SQL_DATE

    public static final String SQL_DATE
    See Also:
      - Constant Field Values

  - ### SQL_DECIMAL

    public static final String SQL_DECIMAL
    See Also:
      - Constant Field Values

  - ### SQL_DOUBLE

    public static final String SQL_DOUBLE
    See Also:
      - Constant Field Values

  - ### SQL_FLOAT

    public static final String SQL_FLOAT
    See Also:
      - Constant Field Values

  - ### SQL_INTEGER

    public static final String SQL_INTEGER
    See Also:
      - Constant Field Values

  - ### SQL_LONGVARCHAR

    public static final String SQL_LONGVARCHAR
    See Also:
      - Constant Field Values

  - ### SQL_LONGNVARCHAR

    public static final String SQL_LONGNVARCHAR
    See Also:
      - Constant Field Values

  - ### SQL_LONGVARBINARY

    public static final String SQL_LONGVARBINARY
    See Also:
      - Constant Field Values

  - ### SQL_NUMERIC

    public static final String SQL_NUMERIC
    See Also:
      - Constant Field Values

  - ### SQL_REAL

    public static final String SQL_REAL
    See Also:
      - Constant Field Values

  - ### SQL_SMALLINT

    public static final String SQL_SMALLINT
    See Also:
      - Constant Field Values

  - ### SQL_TINYINT

    public static final String SQL_TINYINT
    See Also:
      - Constant Field Values

  - ### SQL_TIME

    public static final String SQL_TIME
    See Also:
      - Constant Field Values

  - ### SQL_TIMESTAMP

    public static final String SQL_TIMESTAMP
    See Also:
      - Constant Field Values

  - ### SQL_VARBINARY

    public static final String SQL_VARBINARY
    See Also:
      - Constant Field Values

  - ### SQL_VARCHAR

    public static final String SQL_VARCHAR
    See Also:
      - Constant Field Values

  - ### SQL_NVARCHAR

    public static final String SQL_NVARCHAR
    See Also:
      - Constant Field Values

  - ### SQL_SQLXML

    public static final String SQL_SQLXML
    See Also:
      - Constant Field Values

  - ### SQL_OTHER

    public static final String SQL_OTHER
    See Also:
      - Constant Field Values

  - ### SQL_NULL

    public static final String SQL_NULL
    See Also:
      - Constant Field Values

  - ### JAVA_LONG

    public static final String JAVA_LONG
    See Also:
      - Constant Field Values

  - ### JAVA_BYTES

    public static final String JAVA_BYTES
    See Also:
      - Constant Field Values

  - ### JAVA_BOOLEAN

    public static final String JAVA_BOOLEAN
    See Also:
      - Constant Field Values

  - ### JAVA_STRING

    public static final String JAVA_STRING
    See Also:
      - Constant Field Values

  - ### JAVA_SQLDATE

    public static final String JAVA_SQLDATE
    See Also:
      - Constant Field Values

  - ### JAVA_UTILDATE

    public static final String JAVA_UTILDATE
    See Also:
      - Constant Field Values

  - ### JAVA_BIGDECIMAL

    public static final String JAVA_BIGDECIMAL
    See Also:
      - Constant Field Values

  - ### JAVA_BIGINTEGER

    public static final String JAVA_BIGINTEGER
    See Also:
      - Constant Field Values

  - ### JAVA_DOUBLE

    public static final String JAVA_DOUBLE
    See Also:
      - Constant Field Values

  - ### JAVA_FLOAT

    public static final String JAVA_FLOAT
    See Also:
      - Constant Field Values

  - ### JAVA_INTEGER

    public static final String JAVA_INTEGER
    See Also:
      - Constant Field Values

  - ### JAVA_SHORT

    public static final String JAVA_SHORT
    See Also:
      - Constant Field Values

  - ### JAVA_BYTE

    public static final String JAVA_BYTE
    See Also:
      - Constant Field Values

  - ### JAVA_TIME

    public static final String JAVA_TIME
    See Also:
      - Constant Field Values

  - ### JAVA_TIMESTAMP

    public static final String JAVA_TIMESTAMP
    See Also:
      - Constant Field Values

  - ### JAVA_BLOB

    public static final String JAVA_BLOB
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### TypesMapping

    public TypesMapping(DatabaseMetaData metaData) throws SQLException
    Throws:
      `SQLException`

- ## Method Details

  - ### isCharacter

    public static boolean isCharacter(int type)
    Returns true if supplied type is a character type.
    Parameters:
      `type` - JDBC type
    Returns:
      true if supplied type is a character type.
    Since:
      4.0

  - ### isBinary

    public static boolean isBinary(int type)
    Returns true if supplied type is a binary type.
    Parameters:
      `type` - JDBC type
    Returns:
      true if supplied type is a binary type.
    Since:
      4.0

  - ### isNumeric

    public static boolean isNumeric(int type)
    Returns true if supplied type is a numeric type.

  - ### isDecimal

    public static boolean isDecimal(int type)
    Returns true if supplied type is a decimal type.

  - ### isDateTime

    public static boolean isDateTime(int type)
    Since:
      5.0

  - ### getDatabaseTypes

    public static String[] getDatabaseTypes()
    Returns an array of string names of the default JDBC data types.

  - ### pickDataType

    protected static String pickDataType(int jdbcType, org.apache.cayenne.dba.TypesMapping.TypeInfo[] alts)
    Method implements an algorithm to pick a data type from a list of alternatives that most closely matches JDBC data type.

  - ### getSqlTypeByName

    public static int getSqlTypeByName(String typeName)
    Returns a JDBC int type for SQL typem name.

  - ### getSqlNameByType

    public static String getSqlNameByType(int type)
    Returns a String representation of the SQL type from its JDBC code.

  - ### getSqlTypeByJava

    public static int getSqlTypeByJava(String className)
    Returns default java.sql.Types type by the Java type name.
    Parameters:
      `className` - Fully qualified Java Class name.
    Returns:
      The SQL type or NOT_DEFINED if no type found.

  - ### getSqlTypeByJava

    public static int getSqlTypeByJava(Class<?> javaClass)
    Guesses a default JDBC type for the Java class.
    Since:
      1.1

  - ### getJavaBySqlType

    public static String getJavaBySqlType(int type)
    Get the corresponding Java type by its `Types` counterpart. Note that this method should be used as a last resort, with explicit mapping provided by user used as a first choice, as it can only guess how to map certain types, such as NUMERIC, etc.
    Parameters:
      `type` - as defined in `Types`
    Returns:
      Fully qualified Java type name or null if not found.

  - ### getJavaBySqlType

    public static String getJavaBySqlType(DbAttribute attribute)
    Parameters:
      `attribute` - to get java type for
    Returns:
      Fully qualified Java type name or null if not found.
    Since:
      4.2
    See Also:
      - `getJavaBySqlType(int)`