Package com.exasol.adapter.jdbc
Class BaseColumnMetadataReader
- java.lang.Object
-
- com.exasol.adapter.jdbc.AbstractMetadataReader
-
- com.exasol.adapter.jdbc.BaseColumnMetadataReader
-
- All Implemented Interfaces:
ColumnMetadataReader,MetadataReader
public class BaseColumnMetadataReader extends AbstractMetadataReader implements ColumnMetadataReader
This class implements a mapper that reads column metadata from the remote database and converts it into JDBC information.
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTOINCREMENT_COLUMNKey for autoincrementstatic StringCHAR_OCTET_LENGTH_COLUMNKey for char octet lengthstatic StringDATA_TYPE_COLUMNKey for data typestatic StringDEFAULT_VALUE_COLUMNKey for the default valuestatic StringNAME_COLUMNKey for column namestatic StringNULLABLE_COLUMNKey for is nullablestatic StringREMARKS_COLUMNKey for the commentstatic StringSCALE_COLUMNKey for decimal digitsstatic StringSIZE_COLUMNKey for column sizestatic StringTYPE_NAME_COLUMNKey for type name-
Fields inherited from class com.exasol.adapter.jdbc.AbstractMetadataReader
connection, exaMetadata, properties
-
-
Constructor Summary
Constructors Constructor Description BaseColumnMetadataReader(Connection connection, com.exasol.adapter.AdapterProperties properties, com.exasol.ExaMetadata exaMetadata, IdentifierConverter identifierConverter)Create a new instance of aColumnMetadataReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.exasol.adapter.metadata.DataTypeconvertDecimal(int jdbcPrecision, int scale)Build a data type for a decimal value.protected ResultSetgetColumnMetadata(String catalogName, String schemaName, String tableName)Read column metadata from JDBC driver escaping potential SQL wild cards in the names of schema and table.protected ResultSetgetColumnMetadataAllowingPatterns(String catalogName, String schemaNamePattern, String tableNamePattern)Read column metadata from JDBC driver without escaping potential SQL wild cards in the names of schema and table.protected List<com.exasol.adapter.metadata.ColumnMetadata>getColumnsFromResultSet(ResultSet remoteColumns)Read the columns result set.protected com.exasol.adapter.metadata.DataTypegetNumberTypeFromProperty(String property)Parse a number type property.protected booleanisRemoteColumnNullable(ResultSet remoteColumn, String columnName)Check if a column a nullable.protected StringmapColumnName(String columnName)Convert the column name.List<com.exasol.adapter.metadata.ColumnMetadata>mapColumns(String tableName)Map a metadata for a list of columns to Exasol metadata.protected List<com.exasol.adapter.metadata.ColumnMetadata>mapColumns(String catalogName, String schemaName, String tableName)Read the columns metadata from a result set.com.exasol.adapter.metadata.DataTypemapJdbcType(JDBCTypeDescription jdbcTypeDescription)Map type information from JDBC to the Exasol type information.protected com.exasol.adapter.metadata.DataTypemapJdbcTypeNumericToDecimalWithFallbackToDouble(JDBCTypeDescription jdbcTypeDescription)Map aNUMERICcolumn to an ExasolDECIMALvoidmapOrSkipColumn(ResultSet remoteColumns, List<com.exasol.adapter.metadata.ColumnMetadata> columns)Read the column metadata from result set if supported.protected StringreadColumnName(ResultSet columns)Read the column name form result set.JDBCTypeDescriptionreadJdbcTypeDescription(ResultSet remoteColumn)Read the JDBC type description of a column.protected booleansupportsTimestampsWithNanoPrecision()Whether the Exasol database supports timestamp with precision up to nanoseconds.-
Methods inherited from class com.exasol.adapter.jdbc.AbstractMetadataReader
getCatalogNameFilter, getSchemaNameFilter
-
-
-
-
Field Detail
-
NAME_COLUMN
public static final String NAME_COLUMN
Key for column name- See Also:
- Constant Field Values
-
DATA_TYPE_COLUMN
public static final String DATA_TYPE_COLUMN
Key for data type- See Also:
- Constant Field Values
-
SIZE_COLUMN
public static final String SIZE_COLUMN
Key for column size- See Also:
- Constant Field Values
-
SCALE_COLUMN
public static final String SCALE_COLUMN
Key for decimal digits- See Also:
- Constant Field Values
-
CHAR_OCTET_LENGTH_COLUMN
public static final String CHAR_OCTET_LENGTH_COLUMN
Key for char octet length- See Also:
- Constant Field Values
-
TYPE_NAME_COLUMN
public static final String TYPE_NAME_COLUMN
Key for type name- See Also:
- Constant Field Values
-
REMARKS_COLUMN
public static final String REMARKS_COLUMN
Key for the comment- See Also:
- Constant Field Values
-
DEFAULT_VALUE_COLUMN
public static final String DEFAULT_VALUE_COLUMN
Key for the default value- See Also:
- Constant Field Values
-
AUTOINCREMENT_COLUMN
public static final String AUTOINCREMENT_COLUMN
Key for autoincrement- See Also:
- Constant Field Values
-
NULLABLE_COLUMN
public static final String NULLABLE_COLUMN
Key for is nullable- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseColumnMetadataReader
public BaseColumnMetadataReader(Connection connection, com.exasol.adapter.AdapterProperties properties, com.exasol.ExaMetadata exaMetadata, IdentifierConverter identifierConverter)
Create a new instance of aColumnMetadataReader.- Parameters:
connection- JDBC connection through which the column metadata is read from the remote databaseproperties- user-defined adapter propertiesexaMetadata- metadata of the Exasol databaseidentifierConverter- converter between source and Exasol identifiers
-
-
Method Detail
-
supportsTimestampsWithNanoPrecision
protected boolean supportsTimestampsWithNanoPrecision()
Whether the Exasol database supports timestamp with precision up to nanoseconds.- Returns:
- true if Exasol database supports timestamps with nanoseconds precision false otherwise.
-
mapColumns
public List<com.exasol.adapter.metadata.ColumnMetadata> mapColumns(String tableName)
Map a metadata for a list of columns to Exasol metadata.- Specified by:
mapColumnsin interfaceColumnMetadataReader- Parameters:
tableName- the table for which the columns are mapped- Returns:
- list of Exasol column metadata objects
-
mapColumns
protected List<com.exasol.adapter.metadata.ColumnMetadata> mapColumns(String catalogName, String schemaName, String tableName)
Read the columns metadata from a result set.- Parameters:
catalogName- catalog nameschemaName- schema nametableName- table name- Returns:
- list with column metadata
-
getColumnMetadata
protected ResultSet getColumnMetadata(String catalogName, String schemaName, String tableName) throws SQLException
Read column metadata from JDBC driver escaping potential SQL wild cards in the names of schema and table.- Parameters:
catalogName- catalog nameschemaName- schema name, potential SQL wildcards will be escapedtableName- table name, potential SQL wildcards will be escaped- Returns:
- list with metadata for all columns of the respective catalog, schema, and table
- Throws:
SQLException- in case of failures
-
getColumnMetadataAllowingPatterns
protected ResultSet getColumnMetadataAllowingPatterns(String catalogName, String schemaNamePattern, String tableNamePattern) throws SQLException
Read column metadata from JDBC driver without escaping potential SQL wild cards in the names of schema and table.- Parameters:
catalogName- catalog nameschemaNamePattern- schema name pattern, may contain SQL wildcardstableNamePattern- table name pattern, may contain SQL wildcards- Returns:
- list with metadata for all columns of the respective catalog, matching schema name pattern, and table name pattern
- Throws:
SQLException- in case of failures
-
getColumnsFromResultSet
protected List<com.exasol.adapter.metadata.ColumnMetadata> getColumnsFromResultSet(ResultSet remoteColumns) throws SQLException
Read the columns result set.- Parameters:
remoteColumns- column result set.- Returns:
- list of column metadata
- Throws:
SQLException- if read fails
-
mapOrSkipColumn
public void mapOrSkipColumn(ResultSet remoteColumns, List<com.exasol.adapter.metadata.ColumnMetadata> columns) throws SQLException
Read the column metadata from result set if supported. Otherwise, skip.- Parameters:
remoteColumns- column result setcolumns- list to append column to- Throws:
SQLException- if read fails
-
readJdbcTypeDescription
public JDBCTypeDescription readJdbcTypeDescription(ResultSet remoteColumn) throws SQLException
Read the JDBC type description of a column.- Parameters:
remoteColumn- result set column- Returns:
- JDBC type description
- Throws:
SQLException- if read fails
-
isRemoteColumnNullable
protected boolean isRemoteColumnNullable(ResultSet remoteColumn, String columnName)
Check if a column a nullable.- Parameters:
remoteColumn- column result setcolumnName- column name- Returns:
trueif remote column is nullable
-
readColumnName
protected String readColumnName(ResultSet columns) throws SQLException
Read the column name form result set.- Parameters:
columns- column result set- Returns:
- column name
- Throws:
SQLException- if read fails
-
mapJdbcType
public com.exasol.adapter.metadata.DataType mapJdbcType(JDBCTypeDescription jdbcTypeDescription)
Description copied from interface:ColumnMetadataReaderMap type information from JDBC to the Exasol type information.Override this method in a dedicated mapper if you need dialect specific behavior.
- Specified by:
mapJdbcTypein interfaceColumnMetadataReader- Parameters:
jdbcTypeDescription- parameter object describing the type from the JDBC perspective- Returns:
- Exasol data type information
-
convertDecimal
protected com.exasol.adapter.metadata.DataType convertDecimal(int jdbcPrecision, int scale)Build a data type for a decimal value.- Parameters:
jdbcPrecision- precisionscale- scale- Returns:
- built data type
-
mapColumnName
protected String mapColumnName(String columnName)
Convert the column name.- Parameters:
columnName- column name- Returns:
- column name
-
mapJdbcTypeNumericToDecimalWithFallbackToDouble
protected com.exasol.adapter.metadata.DataType mapJdbcTypeNumericToDecimalWithFallbackToDouble(JDBCTypeDescription jdbcTypeDescription)
Map aNUMERICcolumn to an ExasolDECIMALIf the precision of the remote column exceeds the maximum precision of an Exasol
DECIMAL, the column is mapped to an ExasolDOUBLEinstead.- Parameters:
jdbcTypeDescription- parameter object describing the type from the JDBC perspective- Returns:
- Exasol
DECIMALif precision is less than or equal maximum precision,DOUBLEotherwise.
-
getNumberTypeFromProperty
protected com.exasol.adapter.metadata.DataType getNumberTypeFromProperty(String property)
Parse a number type property.- Parameters:
property- formatted string:<precision>,<scale>- Returns:
- data type
-
-