de.fuberlin.wiwiss.d2rq.sql.vendor
Class SQL92

java.lang.Object
  extended by de.fuberlin.wiwiss.d2rq.sql.vendor.SQL92
All Implemented Interfaces:
Vendor
Direct Known Subclasses:
HSQLDB, 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)

Field Summary
 
Fields inherited from interface de.fuberlin.wiwiss.d2rq.sql.vendor.Vendor
HSQLDB, InterbaseOrFirebird, 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 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)
          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)
 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)
           
 
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

getRelationNameAliasExpression

public String getRelationNameAliasExpression(RelationName relationName,
                                             RelationName aliasName)
Description copied from interface: Vendor
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).

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

public String quoteAttribute(Attribute attribute)
Description copied from interface: Vendor
Handles special characters in attribute names.

Specified by:
quoteAttribute in interface Vendor
Parameters:
attribute - An attribute name (column name)
Returns:
Quoted form for use in SQL statements

quoteRelationName

public String quoteRelationName(RelationName relationName)
Description copied from interface: Vendor
Handles special characters in relation names.

Specified by:
quoteRelationName in interface Vendor
Parameters:
relationName - A relation name (table name)
Returns:
Quoted form for use in SQL statements

quoteIdentifier

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

Specified by:
quoteIdentifier in interface Vendor
Parameters:
identifier - An identifier, such as a table or column name
Returns:
Quoted form of the identifier 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 schema,
                              String table)
Description copied from interface: Vendor
TODO Use the Filter interface for this

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

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