org.hibernate.dialect
Class DB2Dialect

java.lang.Object
  extended by org.hibernate.dialect.Dialect
      extended by org.hibernate.dialect.DB2Dialect
Direct Known Subclasses:
DB2390Dialect, DB2400Dialect, DerbyDialect

public class DB2Dialect
extends Dialect

An SQL dialect for DB2.

Author:
Gavin King

Field Summary
 
Fields inherited from class org.hibernate.dialect.Dialect
CLOSED_QUOTE, DEFAULT_BATCH_SIZE, NO_BATCH, QUOTE
 
Constructor Summary
DB2Dialect()
           
 
Method Summary
 int convertToFirstRowValue(int zeroBasedFirstResult)
          DB2 does have a one-based offset, however this was actually already handled in the limiot string building (the '?+1' bit).
 boolean doesReadCommittedCauseWritersToBlockReaders()
          For the underlying database, is READ_COMMITTED isolation implemented by forcing readers to wait for write locks to be released?
 boolean dropConstraints()
          Do we need to drop constraints before dropping tables in this dialect?
 String generateTemporaryTableName(String baseTableName)
          Generate a temporary table name given the bas table.
 String getAddColumnString()
          The syntax used to add a column to a table (optional).
 String getCreateSequenceString(String sequenceName)
          Typically dialects which support sequences can create a sequence with a single command.
 String getCreateTemporaryTablePostfix()
          Get any fragments needing to be postfixed to the command for temporary table creation.
 String getCreateTemporaryTableString()
          Command used to create a temporary table.
 String getCurrentTimestampSelectString()
          Retrieve the command used to retrieve the current timestammp from the database.
 String getDropSequenceString(String sequenceName)
          Typically dialects which support sequences can drop a sequence with a single command.
 String getForUpdateString()
          Get the string to append to SELECT statements to acquire locks for this dialect.
 String getIdentityColumnString()
          The syntax used during DDL to define a column as being an IDENTITY.
 String getIdentityInsertString()
          The keyword used to insert a generated value into an identity column (or null).
 String getIdentitySelectString()
          Get the select command to use to retrieve the last generated IDENTITY value.
 String getLimitString(String sql, boolean hasOffset)
          Apply s limit clause to the query.
 String getLowercaseFunction()
          The name of the SQL function that transforms a string to lowercase
 String getQuerySequencesString()
          Get the select command used retrieve the names of all sequences.
 ResultSet getResultSet(CallableStatement ps)
          Given a callable statement previously processed by Dialect.registerResultSetOutParameter(java.sql.CallableStatement, int), extract the ResultSet from the OUT parameter.
 String getSelectClauseNullString(int sqlType)
          Given a Types type code, determine an appropriate null value to use in a select clause.
 String getSequenceNextValString(String sequenceName)
          Generate the appropriate select statement to to retreive the next value of a sequence.
 boolean isCurrentTimestampSelectStringCallable()
          Should the value returned by Dialect.getCurrentTimestampSelectString() be treated as callable.
static void main(String[] args)
           
 int registerResultSetOutParameter(CallableStatement statement, int col)
          Registers an OUT parameter which will be returing a ResultSet.
 boolean requiresCastingOfParametersInSelectClause()
          DB2 in fact does require that parameters appearing in the select clause be wrapped in cast() calls to tell the DB parser the type of the select value.
 boolean supportsCommentOn()
           
 boolean supportsCurrentTimestampSelection()
          Does this dialect support a way to retrieve the database's current timestamp value?
 boolean supportsEmptyInList()
          Does this dialect support empty IN lists?

For example, is [where XYZ in ()] a supported construct?

 boolean supportsIdentityColumns()
          Does this dialect support identity column key generation?
 boolean supportsLimit()
          Does this dialect support some form of limiting query results via a SQL clause?
 boolean supportsLobValueChangePropogation()
          Does the dialect support propogating changes to LOB values back to the database? Talking about mutating the internal value of the locator as opposed to supplying a new locator instance...
 boolean supportsNotNullUnique()
           
 boolean supportsOuterJoinForUpdate()
          Does this dialect support FOR UPDATE in conjunction with outer joined rows?
 boolean supportsParametersInInsertSelect()
          Does this dialect support parameters within the SELECT clause of INSERT ...

DB2 is know to support parameters in the SELECT clause, but only in casted form (see requiresCastingOfParametersInSelectClause()).

 boolean supportsPooledSequences()
          Does this dialect support "pooled" sequences.
 boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor()
          Does this dialect support asking the result set its positioning information on forward only cursors.
 boolean supportsSequences()
          Does this dialect support sequences?
 boolean supportsTemporaryTables()
          Does this dialect support temporary tables?
 boolean supportsUnionAll()
          Does this dialect support UNION ALL, which is generally a faster variant of UNION?
 boolean useMaxForLimit()
          Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?

This is easiest understood via an example.

 
Methods inherited from class org.hibernate.dialect.Dialect
appendIdentitySelectToInsert, appendLockHint, applyLocksToSql, areStringComparisonsCaseInsensitive, bindLimitParametersFirst, bindLimitParametersInReverseOrder, buildSQLExceptionConverter, closeQuote, createCaseFragment, createOuterJoinFragment, doesRepeatableReadCauseReadersToBlockWriters, dropTemporaryTableAfterUse, forceLimitUsage, forUpdateOfColumns, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getCascadeConstraintsString, getCastTypeName, getColumnComment, getCreateMultisetTableString, getCreateSequenceString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCurrentTimestampSQLFunctionName, getDefaultProperties, getDialect, getDialect, getDropForeignKeyString, getDropSequenceStrings, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIdentityColumnString, getIdentitySelectString, getKeywords, getLimitString, getLockingStrategy, getMaxAliasLength, getNativeIdentifierGeneratorClass, getNoColumnsInsertString, getNullColumnString, getSelectGUIDString, getSelectSequenceNextValString, getTableComment, getTableTypeString, getTypeName, getTypeName, getViolatedConstraintNameExtracter, hasAlterTable, hasDataTypeInIdentityColumn, hasSelfReferentialForeignKeyBug, openQuote, performTemporaryTableDDLInIsolation, qualifyIndexName, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, supportsBindAsCallableArgument, supportsCascadeDelete, supportsCircularCascadeDeleteConstraints, supportsColumnCheck, supportsExistsInSelect, supportsExpectedLobUsagePattern, supportsIfExistsAfterTableName, supportsIfExistsBeforeTableName, supportsInsertSelectIdentity, supportsLimitOffset, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsUnboundedLobLocatorMaterialization, supportsUnique, supportsUniqueConstraintInCreateAlterTable, supportsVariableLimit, toBooleanValueString, toString, transformSelectString, useInputStreamToInsertBlob
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DB2Dialect

public DB2Dialect()
Method Detail

getLowercaseFunction

public String getLowercaseFunction()
Description copied from class: Dialect
The name of the SQL function that transforms a string to lowercase

Overrides:
getLowercaseFunction in class Dialect
Returns:
The dialect-specific lowercase function.

getAddColumnString

public String getAddColumnString()
Description copied from class: Dialect
The syntax used to add a column to a table (optional).

Overrides:
getAddColumnString in class Dialect
Returns:
The "add column" fragment.

dropConstraints

public boolean dropConstraints()
Description copied from class: Dialect
Do we need to drop constraints before dropping tables in this dialect?

Overrides:
dropConstraints in class Dialect
Returns:
True if constraints must be dropped prior to dropping the table; false otherwise.

supportsIdentityColumns

public boolean supportsIdentityColumns()
Description copied from class: Dialect
Does this dialect support identity column key generation?

Overrides:
supportsIdentityColumns in class Dialect
Returns:
True if IDENTITY columns are supported; false otherwise.

getIdentitySelectString

public String getIdentitySelectString()
Description copied from class: Dialect
Get the select command to use to retrieve the last generated IDENTITY value.

Overrides:
getIdentitySelectString in class Dialect
Returns:
The appropriate select command

getIdentityColumnString

public String getIdentityColumnString()
Description copied from class: Dialect
The syntax used during DDL to define a column as being an IDENTITY.

Overrides:
getIdentityColumnString in class Dialect
Returns:
The appropriate DDL fragment.

getIdentityInsertString

public String getIdentityInsertString()
Description copied from class: Dialect
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.

Overrides:
getIdentityInsertString in class Dialect
Returns:
The appropriate keyword.

getSequenceNextValString

public String getSequenceNextValString(String sequenceName)
Description copied from class: Dialect
Generate the appropriate select statement to to retreive the next value of a sequence.

This should be a "stand alone" select statement.

Overrides:
getSequenceNextValString in class Dialect
Parameters:
sequenceName - the name of the sequence
Returns:
String The "nextval" select string.

getCreateSequenceString

public String getCreateSequenceString(String sequenceName)
Description copied from class: Dialect
Typically dialects which support sequences can create a sequence with a single command. This is convenience form of Dialect.getCreateSequenceStrings(java.lang.String) to help facilitate that.

Dialects which support sequences and can create a sequence in a single command need *only* override this method. Dialects which support sequences but require multiple commands to create a sequence should instead override Dialect.getCreateSequenceStrings(java.lang.String).

Overrides:
getCreateSequenceString in class Dialect
Parameters:
sequenceName - The name of the sequence
Returns:
The sequence creation command

getDropSequenceString

public String getDropSequenceString(String sequenceName)
Description copied from class: Dialect
Typically dialects which support sequences can drop a sequence with a single command. This is convenience form of Dialect.getDropSequenceStrings(java.lang.String) to help facilitate that.

Dialects which support sequences and can drop a sequence in a single command need *only* override this method. Dialects which support sequences but require multiple commands to drop a sequence should instead override Dialect.getDropSequenceStrings(java.lang.String).

Overrides:
getDropSequenceString in class Dialect
Parameters:
sequenceName - The name of the sequence
Returns:
The sequence drop commands

supportsSequences

public boolean supportsSequences()
Description copied from class: Dialect
Does this dialect support sequences?

Overrides:
supportsSequences in class Dialect
Returns:
True if sequences supported; false otherwise.

supportsPooledSequences

public boolean supportsPooledSequences()
Description copied from class: Dialect
Does this dialect support "pooled" sequences. Not aware of a better name for this. Essentially can we specify the initial and increment values?

Overrides:
supportsPooledSequences in class Dialect
Returns:
True if such "pooled" sequences are supported; false otherwise.
See Also:
Dialect.getCreateSequenceStrings(String, int, int), Dialect.getCreateSequenceString(String, int, int)

getQuerySequencesString

public String getQuerySequencesString()
Description copied from class: Dialect
Get the select command used retrieve the names of all sequences.

Overrides:
getQuerySequencesString in class Dialect
Returns:
The select command; or null if sequences are not supported.
See Also:
SchemaUpdate

supportsLimit

public boolean supportsLimit()
Description copied from class: Dialect
Does this dialect support some form of limiting query results via a SQL clause?

Overrides:
supportsLimit in class Dialect
Returns:
True if this dialect supports some form of LIMIT.

getLimitString

public String getLimitString(String sql,
                             boolean hasOffset)
Description copied from class: Dialect
Apply s limit clause to the query.

Typically dialects utilize variable limit caluses when they support limits. Thus, when building the select command we do not actually need to know the limit or the offest since we will just be using placeholders.

Here we do still pass along whether or not an offset was specified so that dialects not supporting offsets can generate proper exceptions. In general, dialects will override one or the other of this method and Dialect.getLimitString(String, int, int).

Overrides:
getLimitString in class Dialect
Parameters:
sql - The query to which to apply the limit.
hasOffset - Is the query requesting an offset?
Returns:
the modified SQL

convertToFirstRowValue

public int convertToFirstRowValue(int zeroBasedFirstResult)
DB2 does have a one-based offset, however this was actually already handled in the limiot string building (the '?+1' bit). To not mess up inheritors, I'll leave that part alone and not touch the offset here.

Overrides:
convertToFirstRowValue in class Dialect
Parameters:
zeroBasedFirstResult - The user-supplied, zero-based offset
Returns:
zeroBasedFirstResult
See Also:
Query.setFirstResult(int), Criteria.setFirstResult(int)

getForUpdateString

public String getForUpdateString()
Description copied from class: Dialect
Get the string to append to SELECT statements to acquire locks for this dialect.

Overrides:
getForUpdateString in class Dialect
Returns:
The appropriate FOR UPDATE clause string.

useMaxForLimit

public boolean useMaxForLimit()
Description copied from class: Dialect
Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?

This is easiest understood via an example. Consider you have a table with 20 rows, but you only want to retrieve rows number 11 through 20. Generally, a limit with offset would say that the offset = 11 and the limit = 10 (we only want 10 rows at a time); this is specifying the total number of returned rows. Some dialects require that we instead specify offset = 11 and limit = 20, where 20 is the "last" row we want relative to offset (i.e. total number of rows = 20 - 11 = 9)

So essentially, is limit relative from offset? Or is limit absolute?

Overrides:
useMaxForLimit in class Dialect
Returns:
True if limit is relative from offset; false otherwise.

supportsOuterJoinForUpdate

public boolean supportsOuterJoinForUpdate()
Description copied from class: Dialect
Does this dialect support FOR UPDATE in conjunction with outer joined rows?

Overrides:
supportsOuterJoinForUpdate in class Dialect
Returns:
True if outer joined rows can be locked via FOR UPDATE.

supportsNotNullUnique

public boolean supportsNotNullUnique()
Overrides:
supportsNotNullUnique in class Dialect

getSelectClauseNullString

public String getSelectClauseNullString(int sqlType)
Description copied from class: Dialect
Given a Types type code, determine an appropriate null value to use in a select clause.

One thing to consider here is that certain databases might require proper casting for the nulls here since the select here will be part of a UNION/UNION ALL.

Overrides:
getSelectClauseNullString in class Dialect
Parameters:
sqlType - The Types type code.
Returns:
The appropriate select clause value fragment.

main

public static void main(String[] args)

supportsUnionAll

public boolean supportsUnionAll()
Description copied from class: Dialect
Does this dialect support UNION ALL, which is generally a faster variant of UNION?

Overrides:
supportsUnionAll in class Dialect
Returns:
True if UNION ALL is supported; false otherwise.

registerResultSetOutParameter

public int registerResultSetOutParameter(CallableStatement statement,
                                         int col)
                                  throws SQLException
Description copied from class: Dialect
Registers an OUT parameter which will be returing a ResultSet. How this is accomplished varies greatly from DB to DB, hence its inclusion (along with Dialect.getResultSet(java.sql.CallableStatement)) here.

Overrides:
registerResultSetOutParameter in class Dialect
Parameters:
statement - The callable statement.
col - The bind position at which to register the OUT param.
Returns:
The number of (contiguous) bind positions used.
Throws:
SQLException - Indicates problems registering the OUT param.

getResultSet

public ResultSet getResultSet(CallableStatement ps)
                       throws SQLException
Description copied from class: Dialect
Given a callable statement previously processed by Dialect.registerResultSetOutParameter(java.sql.CallableStatement, int), extract the ResultSet from the OUT parameter.

Overrides:
getResultSet in class Dialect
Parameters:
ps - The callable statement.
Returns:
The extracted result set.
Throws:
SQLException - Indicates problems extracting the result set.

supportsCommentOn

public boolean supportsCommentOn()
Overrides:
supportsCommentOn in class Dialect

supportsTemporaryTables

public boolean supportsTemporaryTables()
Description copied from class: Dialect
Does this dialect support temporary tables?

Overrides:
supportsTemporaryTables in class Dialect
Returns:
True if temp tables are supported; false otherwise.

getCreateTemporaryTableString

public String getCreateTemporaryTableString()
Description copied from class: Dialect
Command used to create a temporary table.

Overrides:
getCreateTemporaryTableString in class Dialect
Returns:
The command used to create a temporary table.

getCreateTemporaryTablePostfix

public String getCreateTemporaryTablePostfix()
Description copied from class: Dialect
Get any fragments needing to be postfixed to the command for temporary table creation.

Overrides:
getCreateTemporaryTablePostfix in class Dialect
Returns:
Any required postfix.

generateTemporaryTableName

public String generateTemporaryTableName(String baseTableName)
Description copied from class: Dialect
Generate a temporary table name given the bas table.

Overrides:
generateTemporaryTableName in class Dialect
Parameters:
baseTableName - The table name from which to base the temp table name.
Returns:
The generated temp table name.

supportsCurrentTimestampSelection

public boolean supportsCurrentTimestampSelection()
Description copied from class: Dialect
Does this dialect support a way to retrieve the database's current timestamp value?

Overrides:
supportsCurrentTimestampSelection in class Dialect
Returns:
True if the current timestamp can be retrieved; false otherwise.

getCurrentTimestampSelectString

public String getCurrentTimestampSelectString()
Description copied from class: Dialect
Retrieve the command used to retrieve the current timestammp from the database.

Overrides:
getCurrentTimestampSelectString in class Dialect
Returns:
The command.

isCurrentTimestampSelectStringCallable

public boolean isCurrentTimestampSelectStringCallable()
Description copied from class: Dialect
Should the value returned by Dialect.getCurrentTimestampSelectString() be treated as callable. Typically this indicates that JDBC escape sytnax is being used...

Overrides:
isCurrentTimestampSelectStringCallable in class Dialect
Returns:
True if the Dialect.getCurrentTimestampSelectString() return is callable; false otherwise.

supportsParametersInInsertSelect

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

DB2 is know to support parameters in the SELECT clause, but only in casted form (see requiresCastingOfParametersInSelectClause()).

Overrides:
supportsParametersInInsertSelect in class Dialect
Returns:
True.

requiresCastingOfParametersInSelectClause

public boolean requiresCastingOfParametersInSelectClause()
DB2 in fact does require that parameters appearing in the select clause be wrapped in cast() calls to tell the DB parser the type of the select value.

Overrides:
requiresCastingOfParametersInSelectClause in class Dialect
Returns:
True.

supportsResultSetPositionQueryMethodsOnForwardOnlyCursor

public boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor()
Description copied from class: Dialect
Does this dialect support asking the result set its positioning information on forward only cursors. Specifically, in the case of scrolling fetches, Hibernate needs to use ResultSet.isAfterLast() and ResultSet.isBeforeFirst(). Certain drivers do not allow access to these methods for forward only cursors.

NOTE : this is highly driver dependent!

Overrides:
supportsResultSetPositionQueryMethodsOnForwardOnlyCursor in class Dialect
Returns:
True if methods like ResultSet.isAfterLast() and ResultSet.isBeforeFirst() are supported for forward only cursors; false otherwise.

supportsEmptyInList

public boolean supportsEmptyInList()
Description copied from class: Dialect
Does this dialect support empty IN lists?

For example, is [where XYZ in ()] a supported construct?

Overrides:
supportsEmptyInList in class Dialect
Returns:
True if empty in lists are supported; false otherwise.

supportsLobValueChangePropogation

public boolean supportsLobValueChangePropogation()
Description copied from class: Dialect
Does the dialect support propogating changes to LOB values back to the database? Talking about mutating the internal value of the locator as opposed to supplying a new locator instance...

For BLOBs, the internal value might be changed by: Blob.setBinaryStream(long), Blob.setBytes(long, byte[]), Blob.setBytes(long, byte[], int, int), or Blob.truncate(long).

For CLOBs, the internal value might be changed by: Clob.setAsciiStream(long), Clob.setCharacterStream(long), Clob.setString(long, String), Clob.setString(long, String, int, int), or Clob.truncate(long).

NOTE : I do not know the correct answer currently for databases which (1) are not part of the cruise control process or (2) do not Dialect.supportsExpectedLobUsagePattern().

Overrides:
supportsLobValueChangePropogation in class Dialect
Returns:
True if the changes are propogated back to the database; false otherwise.

doesReadCommittedCauseWritersToBlockReaders

public boolean doesReadCommittedCauseWritersToBlockReaders()
Description copied from class: Dialect
For the underlying database, is READ_COMMITTED isolation implemented by forcing readers to wait for write locks to be released?

Overrides:
doesReadCommittedCauseWritersToBlockReaders in class Dialect
Returns:
True if writers block readers to achieve READ_COMMITTED; false otherwise.


Copyright © 2009 Hibernate.org. All Rights Reserved.