de.fuberlin.wiwiss.d2rq.sql.types
Class DataType

java.lang.Object
  extended by de.fuberlin.wiwiss.d2rq.sql.types.DataType
Direct Known Subclasses:
SQLApproximateNumeric, SQLBinary, SQLBit, SQLBoolean, SQLCharacterString, SQLDate, SQLExactNumeric, SQLInterval, SQLTime, SQLTimestamp, UnsupportedDataType

public abstract class DataType
extends Object

Represents a SQL data type. TODO: Data types should know whether they can be used in DISTINCT queries

Author:
Richard Cyganiak (richard@cyganiak.de), Christian Becker

Nested Class Summary
static class DataType.GenericType
           
 
Field Summary
static org.apache.commons.logging.Log log
           
 
Constructor Summary
DataType(Vendor sqlSyntax, String name)
           
 
Method Summary
 boolean isIRISafe()
           
 boolean isUnsupported()
           
 String name()
          Returns the datatype's name as reported by JDBC metadata (or closest equivalent), for debugging
 String rdfType()
          Return the appropriate RDF datatype for a SQL data type.
 boolean supportsDistinct()
           
protected  Vendor syntax()
           
 String toSQLLiteral(String value)
          Creates a SQL literal for the given value, suitable for comparison to a column of this indicated type.
 String toString()
           
 String value(ResultSet resultSet, int column)
          Retrieves a string value in preferred format (canonical form of the closest XSD type) from a SQL ResultSet.
 String valueRegex()
          A regular expression that covers the lexical form of all values of this datatype (in their RDF representation).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

public static final org.apache.commons.logging.Log log
Constructor Detail

DataType

public DataType(Vendor sqlSyntax,
                String name)
Parameters:
name - Name as reported by JDBC metadata, for debugging
Method Detail

rdfType

public String rdfType()
Return the appropriate RDF datatype for a SQL data type. null indicates a known SQL type that cannot be mapped to RDF.

Returns:
RDF datatype as prefixed name: xsd:string etc.

isIRISafe

public boolean isIRISafe()

supportsDistinct

public boolean supportsDistinct()
Returns:
true if this column can be used in SELECT DISTINCT queries

isUnsupported

public boolean isUnsupported()

toSQLLiteral

public String toSQLLiteral(String value)
Creates a SQL literal for the given value, suitable for comparison to a column of this indicated type. If the value is not suitable for the column type (e.g., not a number for a SQLExactNumeric), NULL is returned.

Parameters:
value - A value
Returns:
A quoted and escaped SQL literal, suitable for comparison to a column

value

public String value(ResultSet resultSet,
                    int column)
             throws SQLException
Retrieves a string value in preferred format (canonical form of the closest XSD type) from a SQL ResultSet.

Parameters:
resultSet - Result of a SELECT query
column - The column index to retrieve; leftmost columns is 1
Returns:
String representation, or null if SQL result was null or is not representable in the XSD type
Throws:
SQLException

valueRegex

public String valueRegex()
A regular expression that covers the lexical form of all values of this datatype (in their RDF representation). This is especially important for types that are not mapped to a typed literal but to plain/xsd:string literals.

Returns:
A regular expression covering the lexical forms of all values of this datatype

toString

public String toString()
Overrides:
toString in class Object

syntax

protected Vendor syntax()

name

public String name()
Returns the datatype's name as reported by JDBC metadata (or closest equivalent), for debugging