org.d2rq.db.vendor
Class SQL92

java.lang.Object
  extended by org.d2rq.db.vendor.SQL92
All Implemented Interfaces:
Vendor
Direct Known Subclasses:
HSQLDB, InterbaseOrFirebird, MySQL, Oracle, PostgreSQL, SQLServer

public class SQL92
extends Object
implements Vendor

This base class implements SQL-92 compatible syntax. Subclasses can override individual methods to implement different syntax.

Author:
Richard Cyganiak (richard@cyganiak.de)

Nested Class Summary
static class SQL92.PatternDoublingQuoter
           
static interface SQL92.Quoter
           
 
Field Summary
 
Fields inherited from interface org.d2rq.db.vendor.Vendor
HSQLDB, InterbaseOrFirebird, log, MSAccess, MySQL, Oracle, PostgreSQL, SQL92, SQLServer
 
Constructor Summary
SQL92(boolean useAS)
          Initializes a new instance.
 
Method Summary
 Expression booleanExpressionToSimpleExpression(Expression expression)
          In most databases, we don't have to do anything because boolean expressions are allowed anywhere.
 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)
          Technically speaking, SQL 92 supports NO way of limiting result sets (ROW_NUMBER appeared in SQL 2003).
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQL92

public SQL92(boolean useAS)
Initializes a new instance.

Parameters:
useAS - Use "Table AS Alias" or "Table Alias" in FROM clauses? In standard SQL, either is fine.
Method Detail

getConcatenationExpression

public String getConcatenationExpression(String[] sqlFragments)
Description copied from interface: Vendor
Concatenation of a and b is "a || b" in standard SQL, but CONCAT(a, b) in MySQL.

Specified by:
getConcatenationExpression in interface Vendor
Parameters:
sqlFragments - An array of SQL expressions to be concatenated
Returns:
A SQL expression that concatenates the arguments

getAliasOperator

public String getAliasOperator()
Description copied from interface: Vendor
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).

Specified by:
getAliasOperator in interface Vendor
Returns:
An operator for assigning an alias to a table specification

getTrueTable

public String getTrueTable()
Description copied from interface: Vendor
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.

Specified by:
getTrueTable in interface Vendor

toString

public String toString(Identifier identifier)
Description copied from interface: Vendor
Handles special characters in identifiers. For example, SQL 92 puts delimited identifiers in double quotes, but MySQL uses backticks.

Specified by:
toString in interface Vendor
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

public String toString(ColumnName column)
Description copied from interface: Vendor
Handles special characters in qualified column names.

Specified by:
toString in interface Vendor
Parameters:
column - A qualified column name
Returns:
A string representation of the column name for use in SQL statements

toString

public String toString(TableName table)
Description copied from interface: Vendor
Handles special characters in qualified table names.

Specified by:
toString in interface Vendor
Parameters:
table - A qualified table name
Returns:
A string representation of the table name for use in SQL statements

quoteStringLiteral

public String quoteStringLiteral(String s)
Description copied from interface: Vendor
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.

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

quoteBinaryLiteral

public String quoteBinaryLiteral(String hexString)
Specified by:
quoteBinaryLiteral in interface Vendor

quoteDateLiteral

public String quoteDateLiteral(String date)
Specified by:
quoteDateLiteral in interface Vendor

quoteTimeLiteral

public String quoteTimeLiteral(String time)
Specified by:
quoteTimeLiteral in interface Vendor

quoteTimestampLiteral

public String quoteTimestampLiteral(String timestamp)
Specified by:
quoteTimestampLiteral in interface Vendor

getRowNumLimitAsExpression

public Expression getRowNumLimitAsExpression(int limit)
Description copied from interface: Vendor
Returns an expression for limiting the number of returned rows for engines that support this (ROWNUM <= n)

Specified by:
getRowNumLimitAsExpression in interface Vendor
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

getRowNumLimitAsQueryAppendage

public String getRowNumLimitAsQueryAppendage(int limit)
Technically speaking, SQL 92 supports NO way of limiting result sets (ROW_NUMBER appeared in SQL 2003). We will just use MySQL's LIMIT as it appears to be widely implemented.

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

getRowNumLimitAsSelectModifier

public String getRowNumLimitAsSelectModifier(int limit)
Description copied from interface: Vendor
Returns a modifier for the SELECT keyword that adds a limit to the number of returned rows for engines that support this (TOP n)

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

getDefaultConnectionProperties

public Properties getDefaultConnectionProperties()
Description copied from interface: Vendor
Returns a set of default connection properties to be used when connecting to this database engine type

Specified by:
getDefaultConnectionProperties in interface Vendor
Returns:
A collection of properties

getDataType

public DataType getDataType(int jdbcType,
                            String name,
                            int size)
Description copied from interface: Vendor
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.

Specified by:
getDataType in interface Vendor
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

public Expression booleanExpressionToSimpleExpression(Expression expression)
In most databases, we don't have to do anything because boolean expressions are allowed anywhere.

Specified by:
booleanExpressionToSimpleExpression in interface Vendor
Parameters:
expression - A boolean expression
Returns:
A simple expression returning an equivalent value, e.g., INT 0 and 1

isIgnoredTable

public boolean isIgnoredTable(String catalog,
                              String schema,
                              String table)
Description copied from interface: Vendor
TODO Use the Filter interface for this

Specified by:
isIgnoredTable in interface Vendor
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

public TableName toQualifiedTableName(String catalog,
                                      String schema,
                                      String table)
Description copied from interface: Vendor
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.

Specified by:
toQualifiedTableName in interface Vendor
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

public void initializeConnection(Connection connection)
                          throws SQLException
Description copied from interface: Vendor
Vendor-specific initialization for a database connection.

Specified by:
initializeConnection in interface Vendor
Throws:
SQLException