org.d2rq.db.vendor
Interface Vendor

All Known Implementing Classes:
HSQLDB, InterbaseOrFirebird, 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 org.apache.commons.logging.Log log
           
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 getAliasOperator()
          An alias declaration for use in FROM clauses.
 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
 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)
 String getTrueTable()
          For databases that support SQL queries without a FROM clause, (SELECT 1+1), this should return null.
 void initializeConnection(Connection connection)
          Vendor-specific initialization for a database connection.
 boolean isIgnoredTable(String catalog, String schema, String table)
          TODO Use the Filter interface for this
 String quoteBinaryLiteral(String hexString)
           
 String quoteDateLiteral(String date)
           
 String quoteStringLiteral(String s)
          Handles special characters in strings.
 String quoteTimeLiteral(String time)
           
 String quoteTimestampLiteral(String timestamp)
           
 TableName toQualifiedTableName(String catalog, String schema, String table)
          Returns a qualified table name from catalog/schema/table strings as reported from JDBC metadata.
 String toString(ColumnName column)
          Handles special characters in qualified column names.
 String toString(Identifier identifier)
          Handles special characters in identifiers.
 String toString(TableName table)
          Handles special characters in qualified table names.
 

Field Detail

log

static final org.apache.commons.logging.Log log

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

getAliasOperator

String getAliasOperator()
An alias declaration for use in FROM clauses. Would return AS for SQL 92, and a single space for Oracle (the AS is optional in SQL 92, but some engines require it, while others don't understand it).

Returns:
An operator for assigning an alias to a table specification

getTrueTable

String getTrueTable()
For databases that support SQL queries without a FROM clause, (SELECT 1+1), this should return null. For databases that require some sort of dummy table (e.g., Oracle: SELECT 1+1 FROM DUAL), this should return the name of that table.


toString

String toString(Identifier identifier)
Handles special characters in identifiers. For example, SQL 92 puts delimited identifiers in double quotes, but MySQL uses backticks.

Parameters:
identifier - An identifier, such as an unqualified table or column name
Returns:
A string representation of the identifier for use in SQL statements

toString

String toString(TableName table)
Handles special characters in qualified table names.

Parameters:
table - A qualified table name
Returns:
A string representation of the table name for use in SQL statements

toString

String toString(ColumnName column)
Handles special characters in qualified column names.

Parameters:
column - A qualified column name
Returns:
A string representation of the column name 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 catalog,
                       String schema,
                       String table)
TODO Use the Filter interface for this

Parameters:
catalog - A catalog name, or null for the connection's default schema
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

toQualifiedTableName

TableName toQualifiedTableName(String catalog,
                               String schema,
                               String table)
Returns a qualified table name from catalog/schema/table strings as reported from JDBC metadata. Vendor implementations can override this to rename schemas, mess around with case sensitivity, etc.

Parameters:
catalog - A catalog name, or null for the connection's default schema
schema - A schema name, or null for the connection's default schema
table - A table name
Returns:
A QualfiedTableName instance that names the table

initializeConnection

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

Parameters:
connection -
Throws:
SQLException