org.d2rq.db.types
Class DataType

java.lang.Object
  extended by org.d2rq.db.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.

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

Nested Class Summary
static class DataType.GenericType
           
 
Field Summary
protected static org.apache.commons.logging.Log log
           
 
Constructor Summary
DataType(String name)
           
 
Method Summary
 boolean equals(Object o)
           
 int hashCode()
           
 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 URI of an appropriate RDF datatype for a SQL data type.
 boolean supportsDistinct()
           
 String toSQLLiteral(String value, Vendor vendor)
          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, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

log

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

DataType

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

rdfType

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

Returns:
RDF datatype URI: http://www.w3.org/2001/XMLSchema#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,
                           Vendor vendor)
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
vendor - A vendor instance responsible for quoting/escaping
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

name

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


equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object