de.fuberlin.wiwiss.d2rq.sql.vendor
Interface Vendor

All Known Implementing Classes:
HSQLDB, MySQL, Oracle, PostgreSQL, SQL92, SQLServer

public interface Vendor

Encapsulates differences in SQL syntax between database engines. Methods only exists for SQL features where at least one engine requires custom syntax differing from SQL-92.

Author:
Richard Cyganiak (richard@cyganiak.de)

Field Summary
static Vendor HSQLDB
           
static Vendor InterbaseOrFirebird
           
static Vendor MSAccess
           
static Vendor MySQL
           
static Vendor Oracle
           
static Vendor PostgreSQL
           
static Vendor SQL92
           
static Vendor SQLServer
           
 
Method Summary
 Expression booleanExpressionToSimpleExpression(Expression expression)
          Turns a BOOLEAN expression into an expression that is guaranteed to be usable in any place where an expression is allowed.
 String getConcatenationExpression(String[] sqlFragments)
          Concatenation of a and b is "a || b" in standard SQL, but CONCAT(a, b) in MySQL.
 DataType getDataType(int jdbcType, String name, int size)
          Returns a DataType corresponding to a JDBC type.
 Properties getDefaultConnectionProperties()
          Returns a set of default connection properties to be used when connecting to this database engine type
 String getRelationNameAliasExpression(RelationName relationName, RelationName aliasName)
          A relation name with an alias name for use in FROM clauses.
 Expression getRowNumLimitAsExpression(int limit)
          Returns an expression for limiting the number of returned rows for engines that support this (ROWNUM <= n)
 String getRowNumLimitAsQueryAppendage(int limit)
          Returns a fragment to be appended to a SQL query in order to add a limit to the number of returned rows for engines that support this (LIMIT n)
 String getRowNumLimitAsSelectModifier(int limit)
          Returns a modifier for the SELECT keyword that adds a limit to the number of returned rows for engines that support this (TOP n)
 void initializeConnection(Connection connection)
          Vendor-specific initialization for a database connection.
 boolean isIgnoredTable(String schema, String table)
          TODO Use the Filter interface for this
 String quoteAttribute(Attribute attribute)
          Handles special characters in attribute names.
 String quoteBinaryLiteral(String hexString)
           
 String quoteDateLiteral(String date)
           
 String quoteIdentifier(String identifier)
          Handles special characters in identifiers.
 String quoteRelationName(RelationName relationName)
          Handles special characters in relation names.
 String quoteStringLiteral(String s)
          Handles special characters in strings.
 String quoteTimeLiteral(String time)
           
 String quoteTimestampLiteral(String timestamp)
           
 

Field Detail

SQL92

static final Vendor SQL92

MySQL

static final Vendor MySQL

PostgreSQL

static final Vendor PostgreSQL

InterbaseOrFirebird

static final Vendor InterbaseOrFirebird

Oracle

static final Vendor Oracle

SQLServer

static final Vendor SQLServer

MSAccess

static final Vendor MSAccess

HSQLDB

static final Vendor HSQLDB
Method Detail

getConcatenationExpression

String getConcatenationExpression(String[] sqlFragments)
Concatenation of a and b is "a || b" in standard SQL, but CONCAT(a, b) in MySQL.

Parameters:
sqlFragments - An array of SQL expressions to be concatenated
Returns:
A SQL expression that concatenates the arguments

getRelationNameAliasExpression

String getRelationNameAliasExpression(RelationName relationName,
                                      RelationName aliasName)
A relation name with an alias name for use in FROM clauses. Would return relation AS alias for SQL 92 (the AS is optional in SQL 92, but some engines require it, while others don't understand it).

Parameters:
relationName - The original table name
aliasName - The alias for the table name
Returns:
An expression that assigns the alias to the table name

quoteAttribute

String quoteAttribute(Attribute attribute)
Handles special characters in attribute names.

Parameters:
attribute - An attribute name (column name)
Returns:
Quoted form for use in SQL statements

quoteRelationName

String quoteRelationName(RelationName relationName)
Handles special characters in relation names.

Parameters:
relationName - A relation name (table name)
Returns:
Quoted form for use in SQL statements

quoteIdentifier

String quoteIdentifier(String identifier)
Handles special characters in identifiers. SQL 92 puts identifiers in double quotes, but MySQL uses backticks.

Parameters:
identifier - An identifier, such as a table or column name
Returns:
Quoted form of the identifier for use in SQL statements

quoteStringLiteral

String quoteStringLiteral(String s)
Handles special characters in strings. Most databases wrap the string in single quotes, and escape single quotes by doubling them. Some databases also require doubling of backslashes.

Parameters:
s - An arbitrary character string
Returns:
A quoted and escaped version safe for use in SQL statements

quoteBinaryLiteral

String quoteBinaryLiteral(String hexString)

quoteDateLiteral

String quoteDateLiteral(String date)

quoteTimeLiteral

String quoteTimeLiteral(String time)

quoteTimestampLiteral

String quoteTimestampLiteral(String timestamp)

getRowNumLimitAsExpression

Expression getRowNumLimitAsExpression(int limit)
Returns an expression for limiting the number of returned rows for engines that support this (ROWNUM <= n)

Parameters:
limit - A maximum number of rows, or Database.NO_LIMIT
Returns:
An expression that limits the number of rows, or Expression.TRUE if not supported by the engine

getRowNumLimitAsSelectModifier

String getRowNumLimitAsSelectModifier(int limit)
Returns a modifier for the SELECT keyword that adds a limit to the number of returned rows for engines that support this (TOP n)

Parameters:
limit - A maximum number of rows, or Database.NO_LIMIT
Returns:
A SELECT keyword modifier, or the empty string if unsupported/unnecessary

getRowNumLimitAsQueryAppendage

String getRowNumLimitAsQueryAppendage(int limit)
Returns a fragment to be appended to a SQL query in order to add a limit to the number of returned rows for engines that support this (LIMIT n)

Parameters:
limit - A maximum number of rows, or Database.NO_LIMIT
Returns:
A SQL fragment, or the empty string if unsupported/unnecessary

getDefaultConnectionProperties

Properties getDefaultConnectionProperties()
Returns a set of default connection properties to be used when connecting to this database engine type

Returns:
A collection of properties

getDataType

DataType getDataType(int jdbcType,
                     String name,
                     int size)
Returns a DataType corresponding to a JDBC type. This may be an unsupported datatype; in this case, its DataType.isUnsupported() method will return true. null will be returned if the vendor code doesn't handle this datatype at all; that should generally be considered a bug.

Parameters:
jdbcType - A java.sql.Types constant
name - The type name, as reported by java.sql metadata methods, normalized to uppercase
size - Character size of the type, or 0 if not applicable
Returns:
A compatible D2RQ DataType instance, or null if the vendor code is broken

booleanExpressionToSimpleExpression

Expression booleanExpressionToSimpleExpression(Expression expression)
Turns a BOOLEAN expression into an expression that is guaranteed to be usable in any place where an expression is allowed.

Parameters:
expression - A boolean expression
Returns:
A simple expression returning an equivalent value, e.g., INT 0 and 1

isIgnoredTable

boolean isIgnoredTable(String schema,
                       String table)
TODO Use the Filter interface for this

Parameters:
schema - A schema name, or null for the connection's default schema
table - A table name
Returns:
true if this is a system table that doesn't contain user/application data

initializeConnection

void initializeConnection(Connection connection)
                          throws SQLException
Vendor-specific initialization for a database connection.

Parameters:
connection -
Throws:
SQLException