org.hibernate.dialect
Class Dialect

java.lang.Object
  extended byorg.hibernate.dialect.Dialect
Direct Known Subclasses:
DB2Dialect, FrontBaseDialect, HSQLDialect, InformixDialect, IngresDialect, InterbaseDialect, JDataStoreDialect, MckoiDialect, MimerSQLDialect, MySQLDialect, Oracle9Dialect, PointbaseDialect, PostgreSQLDialect, ProgressDialect, RDMSOS2200Dialect, SAPDBDialect, SybaseDialect, TimesTenDialect

public abstract class Dialect
extends Object

Represents a dialect of SQL implemented by a particular RDBMS. Subclasses implement Hibernate compatibility with different systems.

Subclasses should provide a public default constructor that register() a set of type mappings and default Hibernate properties.

Subclasses should be immutable.

Author:
Gavin King, David Channon

Field Summary
static String CLOSED_QUOTE
           
static String QUOTE
          Characters used for quoting SQL identifiers
 
Constructor Summary
protected Dialect()
           
 
Method Summary
 String appendIdentitySelectToInsert(String insertString)
          Append a clause to retrieve the generated identity value for the given INSERT statement.
 String appendLockHint(LockMode mode, String tableName)
          Method appendLockHint appends according to the given lock mode a lock hint behind the given table name, if this dialect needs this.
 boolean bindLimitParametersFirst()
          Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?
 boolean bindLimitParametersInReverseOrder()
          Does the LIMIT clause specify arguments in the "reverse" order limit, offset instead of offset, limit?
 SQLExceptionConverter buildSQLExceptionConverter()
          Build an instance of the SQLExceptionConverter preferred by this dialect for converting SQLExceptions into Hibernate's JDBCException hierarchy.
 char closeQuote()
          The closing quote for a quoted identifier
 CaseFragment createCaseFragment()
          Create a CaseFragment for this dialect.
 JoinFragment createOuterJoinFragment()
          Create an OuterJoinGenerator for this dialect.
 boolean dropConstraints()
          Do we need to drop constraints before dropping tables in this dialect?
 boolean dropTemporaryTableAfterUse()
           
 boolean forUpdateOfColumns()
          Does the FOR UPDATE OF syntax specify particular columns?
 String generateTemporaryTableName(String baseTableName)
           
 String getAddColumnString()
          The syntax used to add a column to a table (optional).
 String getAddForeignKeyConstraintString(String constraintName, String[] foreignKey, String referencedTable, String[] primaryKey, boolean referencesPrimaryKey)
          The syntax used to add a foreign key constraint to a table.
 String getAddPrimaryKeyConstraintString(String constraintName)
          The syntax used to add a primary key constraint to a table.
 String getCascadeConstraintsString()
          Completely optional cascading drop clause
 String getCastTypeName(int code)
           
 String getColumnComment(String comment)
           
protected  String getCreateSequenceString(String sequenceName)
          The syntax used to create a sequence, if sequences are supported.
 String[] getCreateSequenceStrings(String sequenceName)
          The multiline script used to create a sequence, if sequences are supported.
 String getCreateTemporaryTablePostfix()
           
 String getCreateTemporaryTableString()
           
 String getCurrentTimestampSelectString()
           
 String getCurrentTimestampSQLFunctionName()
          The name of the database-specific SQL function for retrieving the current timestamp.
 Properties getDefaultProperties()
          Retrieve a set of default Hibernate properties for this database.
static Dialect getDialect()
          Get the Dialect specified by the current System properties.
static Dialect getDialect(Properties props)
          Get the Dialect specified by the given properties or system properties.
 String getDropForeignKeyString()
           
protected  String getDropSequenceString(String sequenceName)
          The syntax used to drop a sequence, if sequences are supported.
 String[] getDropSequenceStrings(String sequenceName)
          The multiline script used to drop a sequence, if sequences are supported.
 String getForUpdateNowaitString()
          Does this dialect support the Oracle-style FOR UPDATE NOWAIT syntax?
 String getForUpdateNowaitString(String aliases)
          Does this dialect support the Oracle-style FOR UPDATE OF ...
 String getForUpdateString()
          Does this dialect support the FOR UPDATE syntax?
 String getForUpdateString(LockMode lockMode)
           
 String getForUpdateString(String aliases)
          Does this dialect support the FOR UPDATE OF syntax?
 Map getFunctions()
          SQL functions as defined in general.
 String getHibernateTypeName(int code)
           
 String getHibernateTypeName(int code, int length, int precision, int scale)
           
protected  String getIdentityColumnString()
           
 String getIdentityColumnString(int type)
          The keyword used to specify an identity column, if identity column key generation is supported.
 String getIdentityInsertString()
          The keyword used to insert a generated value into an identity column (or null).
protected  String getIdentitySelectString()
           
 String getIdentitySelectString(String table, String column, int type)
          The syntax that returns the identity value of the last insert, if identity column key generation is supported.
 Set getKeywords()
           
 String getLimitString(String querySelect, boolean hasOffset)
          Add a LIMIT clause to the given SQL SELECT
 String getLimitString(String querySelect, int offset, int limit)
           
 String getLowercaseFunction()
          The name of the SQL function that transforms a string to lowercase
 int getMaxAliasLength()
           
 Class getNativeIdentifierGeneratorClass()
           
 String getNoColumnsInsertString()
          The keyword used to insert a row without specifying any column values.
 String getNullColumnString()
          The keyword used to specify a nullable column.
 String getQuerySequencesString()
          A query used to find all sequences
 ResultSet getResultSet(CallableStatement ps)
           
 String getSelectClauseNullString(int sqlType)
           
 String getSelectGUIDString()
           
 String getSelectSequenceNextValString(String sequenceName)
          Generate the select expression fragment that will retreive the next value of a sequence, if sequences are supported.
 String getSequenceNextValString(String sequenceName)
          Generate the appropriate select statement to to retreive the next value of a sequence, if sequences are supported.
 String getTableComment(String comment)
           
 String getTableTypeString()
           
 String getTypeName(int code)
          Get the name of the database type associated with the given java.sql.Types typecode.
 String getTypeName(int code, int length, int precision, int scale)
          Get the name of the database type associated with the given java.sql.Types typecode.
 ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter()
           
 boolean hasAlterTable()
          Does this dialect support the ALTER TABLE syntax?
 boolean hasDataTypeInIdentityColumn()
          Whether this dialect have an Identity clause added to the data type or a completely seperate identity data type
 boolean hasSelfReferentialForeignKeyBug()
           
 boolean isCurrentTimestampSelectStringCallable()
           
 char openQuote()
          The opening quote for a quoted identifier
 boolean performTemporaryTableDDLInIsolation()
           
 boolean qualifyIndexName()
          Do we need to qualify index names with the schema name?
 String quote(String column)
           
protected  void registerColumnType(int code, int capacity, String name)
          Subclasses register a typename for the given type code and maximum column length.
protected  void registerColumnType(int code, String name)
          Subclasses register a typename for the given type code.
protected  void registerFunction(String name, SQLFunction function)
           
protected  void registerHibernateType(int sqlcode, int capacity, String name)
           
protected  void registerHibernateType(int sqlcode, String name)
           
protected  void registerKeyword(String word)
           
 int registerResultSetOutParameter(CallableStatement statement, int col)
           
 boolean supportsCascadeDelete()
           
 boolean supportsColumnCheck()
          Does this dialect support column-level check constraints?
 boolean supportsCommentOn()
           
 boolean supportsCurrentTimestampSelection()
           
 boolean supportsIdentityColumns()
          Does this dialect support identity column key generation?
 boolean supportsIfExistsAfterTableName()
           
 boolean supportsIfExistsBeforeTableName()
           
 boolean supportsInsertSelectIdentity()
           
 boolean supportsLimit()
          Does this Dialect have some kind of LIMIT syntax?
 boolean supportsLimitOffset()
          Does this dialect support an offset?
 boolean supportsNotNullUnique()
           
 boolean supportsOuterJoinForUpdate()
           
 boolean supportsParametersInInsertSelect()
          Does this dialect support parameters within the select clause of INSERT ...
 boolean supportsSequences()
          Does this dialect support sequences?
 boolean supportsTableCheck()
          Does this dialect support table-level check constraints?
 boolean supportsTemporaryTables()
           
 boolean supportsUnionAll()
           
 boolean supportsUnique()
          Does this dialect support the UNIQUE column syntax?
 boolean supportsUniqueConstraintInCreateAlterTable()
          Does this dialect support adding Unique constraints via create and alter table ?
 boolean supportsVariableLimit()
           
 String toBooleanValueString(boolean bool)
          The SQL value that the JDBC driver maps boolean values to
 String toString()
           
 String transformSelectString(String select)
           
 boolean useInputStreamToInsertBlob()
           
 boolean useMaxForLimit()
          Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

QUOTE

public static final String QUOTE
Characters used for quoting SQL identifiers

See Also:
Constant Field Values

CLOSED_QUOTE

public static final String CLOSED_QUOTE
See Also:
Constant Field Values
Constructor Detail

Dialect

protected Dialect()
Method Detail

toString

public String toString()

getTypeName

public String getTypeName(int code)
                   throws HibernateException
Get the name of the database type associated with the given java.sql.Types typecode.

Parameters:
code - java.sql.Types typecode
Returns:
the database type name
Throws:
HibernateException

getHibernateTypeName

public String getHibernateTypeName(int code)
                            throws HibernateException
Throws:
HibernateException

getHibernateTypeName

public String getHibernateTypeName(int code,
                                   int length,
                                   int precision,
                                   int scale)
                            throws HibernateException
Throws:
HibernateException

getTypeName

public String getTypeName(int code,
                          int length,
                          int precision,
                          int scale)
                   throws HibernateException
Get the name of the database type associated with the given java.sql.Types typecode.

Parameters:
code - java.sql.Types typecode
length - the length or precision of the column
precision - the precision of the column
scale - the scale of the column
Returns:
the database type name
Throws:
HibernateException

getCastTypeName

public String getCastTypeName(int code)

registerFunction

protected void registerFunction(String name,
                                SQLFunction function)

registerKeyword

protected void registerKeyword(String word)

getKeywords

public Set getKeywords()

registerColumnType

protected void registerColumnType(int code,
                                  int capacity,
                                  String name)
Subclasses register a typename for the given type code and maximum column length. $l in the type name with be replaced by the column length (if appropriate).

Parameters:
code - java.sql.Types typecode
capacity - maximum length of database type
name - the database type name

registerColumnType

protected void registerColumnType(int code,
                                  String name)
Subclasses register a typename for the given type code. $l in the type name with be replaced by the column length (if appropriate).

Parameters:
code - java.sql.Types typecode
name - the database type name

registerHibernateType

protected void registerHibernateType(int sqlcode,
                                     String name)

registerHibernateType

protected void registerHibernateType(int sqlcode,
                                     int capacity,
                                     String name)

hasAlterTable

public boolean hasAlterTable()
Does this dialect support the ALTER TABLE syntax?

Returns:
boolean

dropConstraints

public boolean dropConstraints()
Do we need to drop constraints before dropping tables in this dialect?

Returns:
boolean

qualifyIndexName

public boolean qualifyIndexName()
Do we need to qualify index names with the schema name?

Returns:
boolean

forUpdateOfColumns

public boolean forUpdateOfColumns()
Does the FOR UPDATE OF syntax specify particular columns?


getForUpdateString

public String getForUpdateString(String aliases)
Does this dialect support the FOR UPDATE OF syntax?

Returns:
boolean

getForUpdateNowaitString

public String getForUpdateNowaitString(String aliases)
Does this dialect support the Oracle-style FOR UPDATE OF ... NOWAIT syntax?

Returns:
boolean

getForUpdateString

public String getForUpdateString()
Does this dialect support the FOR UPDATE syntax?

Returns:
boolean

getForUpdateNowaitString

public String getForUpdateNowaitString()
Does this dialect support the Oracle-style FOR UPDATE NOWAIT syntax?

Returns:
boolean

supportsUnique

public boolean supportsUnique()
Does this dialect support the UNIQUE column syntax?

Returns:
boolean

supportsUniqueConstraintInCreateAlterTable

public boolean supportsUniqueConstraintInCreateAlterTable()
Does this dialect support adding Unique constraints via create and alter table ?

Returns:
boolean

getAddColumnString

public String getAddColumnString()
The syntax used to add a column to a table (optional).


getDropForeignKeyString

public String getDropForeignKeyString()

getTableTypeString

public String getTableTypeString()

getAddForeignKeyConstraintString

public String getAddForeignKeyConstraintString(String constraintName,
                                               String[] foreignKey,
                                               String referencedTable,
                                               String[] primaryKey,
                                               boolean referencesPrimaryKey)
The syntax used to add a foreign key constraint to a table.

Parameters:
referencesPrimaryKey - if false, constraint should be explicit about which column names the constraint refers to
Returns:
String

getAddPrimaryKeyConstraintString

public String getAddPrimaryKeyConstraintString(String constraintName)
The syntax used to add a primary key constraint to a table.

Returns:
String

getNullColumnString

public String getNullColumnString()
The keyword used to specify a nullable column.

Returns:
String

supportsIdentityColumns

public boolean supportsIdentityColumns()
Does this dialect support identity column key generation?

Returns:
boolean

supportsSequences

public boolean supportsSequences()
Does this dialect support sequences?

Returns:
boolean

supportsInsertSelectIdentity

public boolean supportsInsertSelectIdentity()

appendIdentitySelectToInsert

public String appendIdentitySelectToInsert(String insertString)
Append a clause to retrieve the generated identity value for the given INSERT statement.


getIdentitySelectString

protected String getIdentitySelectString()
                                  throws MappingException
Throws:
MappingException

getIdentitySelectString

public String getIdentitySelectString(String table,
                                      String column,
                                      int type)
                               throws MappingException
The syntax that returns the identity value of the last insert, if identity column key generation is supported.

Parameters:
type - TODO
Throws:
MappingException - if no native key generation

getIdentityColumnString

protected String getIdentityColumnString()
                                  throws MappingException
Throws:
MappingException

getIdentityColumnString

public String getIdentityColumnString(int type)
                               throws MappingException
The keyword used to specify an identity column, if identity column key generation is supported.

Parameters:
type - the SQL column type, as defined by java.sql.Types
Throws:
MappingException - if no native key generation

getIdentityInsertString

public String getIdentityInsertString()
The keyword used to insert a generated value into an identity column (or null). Need if the dialect does not support inserts that specify no column values.

Returns:
String

getNoColumnsInsertString

public String getNoColumnsInsertString()
The keyword used to insert a row without specifying any column values. This is not possible on some databases.


getSequenceNextValString

public String getSequenceNextValString(String sequenceName)
                                throws MappingException
Generate the appropriate select statement to to retreive the next value of a sequence, if sequences are supported.

This should be a "stand alone" select statement.

Parameters:
sequenceName - the name of the sequence
Returns:
String The "nextval" select string.
Throws:
MappingException - if no sequences

getSelectSequenceNextValString

public String getSelectSequenceNextValString(String sequenceName)
                                      throws MappingException
Generate the select expression fragment that will retreive the next value of a sequence, if sequences are supported.

This differs from getSequenceNextValString(String) in that this should return an expression usable within another select statement.

Parameters:
sequenceName - the name of the sequence
Returns:
String
Throws:
MappingException - if no sequences

getCreateSequenceString

protected String getCreateSequenceString(String sequenceName)
                                  throws MappingException
The syntax used to create a sequence, if sequences are supported.

Parameters:
sequenceName - the name of the sequence
Returns:
String
Throws:
MappingException - if no sequences

getCreateSequenceStrings

public String[] getCreateSequenceStrings(String sequenceName)
                                  throws MappingException
The multiline script used to create a sequence, if sequences are supported.

Parameters:
sequenceName - the name of the sequence
Returns:
String[]
Throws:
MappingException - if no sequences

getDropSequenceString

protected String getDropSequenceString(String sequenceName)
                                throws MappingException
The syntax used to drop a sequence, if sequences are supported.

Parameters:
sequenceName - the name of the sequence
Returns:
String
Throws:
MappingException - if no sequences

getDropSequenceStrings

public String[] getDropSequenceStrings(String sequenceName)
                                throws MappingException
The multiline script used to drop a sequence, if sequences are supported.

Parameters:
sequenceName - the name of the sequence
Returns:
String[]
Throws:
MappingException - if no sequences

getQuerySequencesString

public String getQuerySequencesString()
A query used to find all sequences

See Also:
SchemaUpdate

getDialect

public static Dialect getDialect()
                          throws HibernateException
Get the Dialect specified by the current System properties.

Returns:
Dialect
Throws:
HibernateException

getDialect

public static Dialect getDialect(Properties props)
                          throws HibernateException
Get the Dialect specified by the given properties or system properties.

Parameters:
props -
Returns:
Dialect
Throws:
HibernateException

getDefaultProperties

public final Properties getDefaultProperties()
Retrieve a set of default Hibernate properties for this database.

Returns:
a set of Hibernate properties

getCascadeConstraintsString

public String getCascadeConstraintsString()
Completely optional cascading drop clause

Returns:
String

createOuterJoinFragment

public JoinFragment createOuterJoinFragment()
Create an OuterJoinGenerator for this dialect.

Returns:
OuterJoinGenerator

createCaseFragment

public CaseFragment createCaseFragment()
Create a CaseFragment for this dialect.

Returns:
OuterJoinGenerator

getLowercaseFunction

public String getLowercaseFunction()
The name of the SQL function that transforms a string to lowercase

Returns:
String

supportsLimit

public boolean supportsLimit()
Does this Dialect have some kind of LIMIT syntax?


supportsLimitOffset

public boolean supportsLimitOffset()
Does this dialect support an offset?


getLimitString

public String getLimitString(String querySelect,
                             boolean hasOffset)
Add a LIMIT clause to the given SQL SELECT

Returns:
the modified SQL

getLimitString

public String getLimitString(String querySelect,
                             int offset,
                             int limit)

supportsVariableLimit

public boolean supportsVariableLimit()

bindLimitParametersInReverseOrder

public boolean bindLimitParametersInReverseOrder()
Does the LIMIT clause specify arguments in the "reverse" order limit, offset instead of offset, limit?

Returns:
true if the correct order is limit, offset

bindLimitParametersFirst

public boolean bindLimitParametersFirst()
Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?

Returns:
true if limit parameters should come before other parameters

useMaxForLimit

public boolean useMaxForLimit()
Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?


openQuote

public char openQuote()
The opening quote for a quoted identifier


closeQuote

public char closeQuote()
The closing quote for a quoted identifier


getFunctions

public final Map getFunctions()
SQL functions as defined in general. The results of this method should be integrated with the specialisation's data.


supportsIfExistsBeforeTableName

public boolean supportsIfExistsBeforeTableName()

supportsIfExistsAfterTableName

public boolean supportsIfExistsAfterTableName()

supportsColumnCheck

public boolean supportsColumnCheck()
Does this dialect support column-level check constraints?


supportsTableCheck

public boolean supportsTableCheck()
Does this dialect support table-level check constraints?


hasDataTypeInIdentityColumn

public boolean hasDataTypeInIdentityColumn()
Whether this dialect have an Identity clause added to the data type or a completely seperate identity data type

Returns:
boolean

supportsCascadeDelete

public boolean supportsCascadeDelete()

appendLockHint

public String appendLockHint(LockMode mode,
                             String tableName)
Method appendLockHint appends according to the given lock mode a lock hint behind the given table name, if this dialect needs this. MS SQL Server for example doesn't support the standard "select ... for update" syntax and use a special "select ... from TABLE as ALIAS with (updlock, rowlock) where ..." syntax instead.

Parameters:
tableName - name of table to append lock hint
Returns:
String

author Helge Schulz


getNativeIdentifierGeneratorClass

public Class getNativeIdentifierGeneratorClass()

getSelectGUIDString

public String getSelectGUIDString()

supportsOuterJoinForUpdate

public boolean supportsOuterJoinForUpdate()

getSelectClauseNullString

public String getSelectClauseNullString(int sqlType)

supportsNotNullUnique

public boolean supportsNotNullUnique()

buildSQLExceptionConverter

public SQLExceptionConverter buildSQLExceptionConverter()
Build an instance of the SQLExceptionConverter preferred by this dialect for converting SQLExceptions into Hibernate's JDBCException hierarchy. The default Dialect implementation simply returns a converter based on X/Open SQLState codes.

It is strongly recommended that specific Dialect implementations override this method, since interpretation of a SQL error is much more accurate when based on the ErrorCode rather than the SQLState. Unfortunately, the ErrorCode is a vendor- specific approach.

Returns:
The Dialect's preferred SQLExceptionConverter.

getViolatedConstraintNameExtracter

public ViolatedConstraintNameExtracter getViolatedConstraintNameExtracter()

quote

public final String quote(String column)

hasSelfReferentialForeignKeyBug

public boolean hasSelfReferentialForeignKeyBug()

useInputStreamToInsertBlob

public boolean useInputStreamToInsertBlob()

registerResultSetOutParameter

public int registerResultSetOutParameter(CallableStatement statement,
                                         int col)
                                  throws SQLException
Throws:
SQLException

getResultSet

public ResultSet getResultSet(CallableStatement ps)
                       throws SQLException
Throws:
SQLException

supportsUnionAll

public boolean supportsUnionAll()

supportsCommentOn

public boolean supportsCommentOn()

getTableComment

public String getTableComment(String comment)

getColumnComment

public String getColumnComment(String comment)

transformSelectString

public String transformSelectString(String select)

supportsTemporaryTables

public boolean supportsTemporaryTables()

generateTemporaryTableName

public String generateTemporaryTableName(String baseTableName)

getCreateTemporaryTableString

public String getCreateTemporaryTableString()

performTemporaryTableDDLInIsolation

public boolean performTemporaryTableDDLInIsolation()

getCreateTemporaryTablePostfix

public String getCreateTemporaryTablePostfix()

dropTemporaryTableAfterUse

public boolean dropTemporaryTableAfterUse()

getForUpdateString

public String getForUpdateString(LockMode lockMode)

getMaxAliasLength

public int getMaxAliasLength()

supportsCurrentTimestampSelection

public boolean supportsCurrentTimestampSelection()

getCurrentTimestampSelectString

public String getCurrentTimestampSelectString()

isCurrentTimestampSelectStringCallable

public boolean isCurrentTimestampSelectStringCallable()

toBooleanValueString

public String toBooleanValueString(boolean bool)
The SQL value that the JDBC driver maps boolean values to


supportsParametersInInsertSelect

public boolean supportsParametersInInsertSelect()
Does this dialect support parameters within the select clause of INSERT ... SELECT ... statements?

Returns:
True if this is supported; false otherwise.

getCurrentTimestampSQLFunctionName

public String getCurrentTimestampSQLFunctionName()
The name of the database-specific SQL function for retrieving the current timestamp.

Returns:
The function name.