public class DB2Dialect extends Dialect
An SQL dialect for DB2.
CLOSED_QUOTE, DEFAULT_BATCH_SIZE, LEGACY_LOB_MERGE_STRATEGY, NEW_LOCATOR_LOB_MERGE_STRATEGY, NO_BATCH, QUOTE, STANDARD_DEFAULT_BATCH_LOAD_SIZING_STRATEGY, STREAM_XFER_LOB_MERGE_STRATEGY| Constructor and Description |
|---|
DB2Dialect()
Constructs a DB2Dialect
|
| Modifier and Type | Method and Description |
|---|---|
SQLExceptionConversionDelegate |
buildSQLExceptionConversionDelegate()
Build an instance of a
SQLExceptionConversionDelegate for
interpreting dialect-specific error or SQLState codes. |
int |
convertToFirstRowValue(int zeroBasedFirstResult)
Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset.
|
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 |
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 |
getCrossJoinSeparator()
Returns the separator to use for defining cross joins when translating HQL queries.
|
String |
getCurrentTimestampSelectString()
Retrieve the command used to retrieve the current timestamp from the
database.
|
MultiTableBulkIdStrategy |
getDefaultMultiTableBulkIdStrategy() |
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.
|
IdentityColumnSupport |
getIdentityColumnSupport()
Get the appropriate
IdentityColumnSupport |
LimitHandler |
getLimitHandler()
Returns the delegate managing LIMIT clause.
|
String |
getLimitString(String sql,
int offset,
int limit)
Given a limit and an offset, apply the limit clause to the query.
|
String |
getLowercaseFunction()
The name of the SQL function that transforms a string to
lowercase
|
String |
getNotExpression(String expression)
Negate an expression
|
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 |
getSelectSequenceNextValString(String sequenceName)
Generate the select expression fragment that will retrieve the next
value of a sequence as part of another (typically DML) statement.
|
String |
getSequenceNextValString(String sequenceName)
Generate the appropriate select statement to to retrieve the next value
of a sequence.
|
protected SqlTypeDescriptor |
getSqlTypeDescriptorOverride(int sqlCode)
Returns the
SqlTypeDescriptor that should be used to handle the given JDBC type code. |
UniqueDelegate |
getUniqueDelegate()
Get the UniqueDelegate supported by this dialect
|
boolean |
isCurrentTimestampSelectStringCallable()
Should the value returned by
Dialect.getCurrentTimestampSelectString()
be treated as callable. |
int |
registerResultSetOutParameter(CallableStatement statement,
int col)
Registers a parameter (either OUT, or the new REF_CURSOR param type available in Java 8) capable of
returning
ResultSet by position. |
String |
renderOrderByElement(String expression,
String collation,
String order,
NullPrecedence nullPrecedence)
Handle DB2 "support" for null precedence…
|
boolean |
requiresCastingOfParametersInSelectClause()
Does this dialect require that parameters appearing in the <tt>SELECT</tt> clause be wrapped in <tt>cast()</tt>
calls to tell the db parser the expected type.
|
boolean |
supportsCommentOn()
Does this dialect/database support commenting on tables, columns, etc?
|
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?
<p/>
For example, is [where XYZ in ()] a supported construct?
|
boolean |
supportsExistsInSelect()
Does the dialect support an exists statement in the select clause?
|
boolean |
supportsLimit()
Does this dialect support some form of limiting query results
via a SQL clause?
|
boolean |
supportsLobValueChangePropogation()
Does the dialect support propagating 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…
<p/>
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). |
boolean |
supportsLockTimeouts()
Informational metadata about whether this dialect is known to support
specifying timeouts for requested lock acquisitions.
|
boolean |
supportsOuterJoinForUpdate()
Does this dialect support <tt>FOR UPDATE</tt> in conjunction with
outer joined rows?
|
boolean |
supportsParametersInInsertSelect()
Does this dialect support parameters within the <tt>SELECT</tt> clause of
<tt>INSERT … SELECT …</tt> statements?
|
boolean |
supportsPartitionBy()
Does the underlying database support partition by
|
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 |
supportsTupleDistinctCounts()
Does this dialect support
count(distinct a,b)? |
boolean |
supportsUnionAll()
Does this dialect support UNION ALL, which is generally a faster
variant of UNION?
|
boolean |
supportsVariableLimit()
Does this dialect support bind variables (i.e., prepared statement
parameters) for its limit/offset?
|
boolean |
useMaxForLimit()
Does the <tt>LIMIT</tt> clause take a "maximum" row number instead
of a total number of returned rows?
<p/>
This is easiest understood via an example.
|
addSqlHintOrComment, appendLockHint, appendLockHint, applyLocksToSql, areStringComparisonsCaseInsensitive, augmentRecognizedTableTypes, bindLimitParametersFirst, bindLimitParametersInReverseOrder, buildIdentifierHelper, buildSQLExceptionConverter, canCreateCatalog, canCreateSchema, cast, cast, cast, closeQuote, contributeTypes, createCaseFragment, createOuterJoinFragment, defaultScrollMode, doesRepeatableReadCauseReadersToBlockWriters, escapeLiteral, forceLimitUsage, forceLobAsLastValue, forUpdateOfColumns, getAddColumnSuffixString, getAddForeignKeyConstraintString, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getAddUniqueConstraintString, getAlterTableString, getAuxiliaryDatabaseObjectExporter, getCallableStatementSupport, getCascadeConstraintsString, getCaseInsensitiveLike, getCastTypeName, getColumnAliasExtractor, getColumnComment, getCreateCatalogCommand, getCreateMultisetTableString, getCreateSchemaCommand, getCreateSequenceString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCurrentSchemaCommand, getCurrentTimestampSQLFunctionName, getDefaultBatchLoadSizingStrategy, getDefaultProperties, getDialect, getDialect, getDropCatalogCommand, getDropForeignKeyString, getDropSchemaCommand, getDropSequenceStrings, getDropTableString, getForeignKeyExporter, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateSkipLockedString, getForUpdateSkipLockedString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIndexExporter, getInExpressionCountLimit, getKeywords, getLimitString, getLobMergeStrategy, getLockingStrategy, getMaxAliasLength, getNameQualifierSupport, getNativeIdentifierGeneratorClass, getNativeIdentifierGeneratorStrategy, getNoColumnsInsertString, getNullColumnString, getQueryHintString, getQueryHintString, getReadLockString, getReadLockString, getResultSet, getResultSet, getSchemaNameResolver, getSelectGUIDString, getSequenceExporter, getSequenceInformationExtractor, getTableComment, getTableExporter, getTableTypeString, getTypeName, getTypeName, getUniqueKeyExporter, getViolatedConstraintNameExtracter, getWriteLockString, getWriteLockString, hasAlterTable, hasSelfReferentialForeignKeyBug, inlineLiteral, isJdbcLogWarningsEnabledByDefault, isLegacyLimitHandlerBehaviorEnabled, isLockTimeoutParameterized, isTypeNameRegistered, openQuote, prependComment, qualifyIndexName, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, registerResultSetOutParameter, remapSqlTypeDescriptor, replaceResultVariableInOrderByClauseWithPosition, requiresParensForTupleDistinctCounts, supportsBindAsCallableArgument, supportsCascadeDelete, supportsCaseInsensitiveLike, supportsCircularCascadeDeleteConstraints, supportsColumnCheck, supportsExpectedLobUsagePattern, supportsIfExistsAfterAlterTable, supportsIfExistsAfterConstraintName, supportsIfExistsAfterTableName, supportsIfExistsBeforeConstraintName, supportsIfExistsBeforeTableName, supportsLimitOffset, supportsNamedParameters, supportsNationalizedTypes, supportsNonQueryWithCTE, supportsNotNullUnique, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsSkipLocked, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsTupleCounts, supportsTuplesInSubqueries, supportsUnboundedLobLocatorMaterialization, supportsUnique, supportsUniqueConstraintInCreateAlterTable, supportsValuesList, toBooleanValueString, toString, transformSelectString, useFollowOnLocking, useFollowOnLocking, useInputStreamToInsertBlobpublic String getLowercaseFunction()
DialectThe name of the SQL function that transforms a string to lowercase
getLowercaseFunction in class Dialectpublic String getAddColumnString()
DialectThe syntax used to add a column to a table (optional).
getAddColumnString in class Dialectpublic boolean dropConstraints()
DialectDo we need to drop constraints before dropping tables in this dialect?
dropConstraints in class Dialectpublic String getSequenceNextValString(String sequenceName)
DialectGenerate the appropriate select statement to to retrieve the next value of a sequence. <p/> This should be a "stand alone" select statement.
getSequenceNextValString in class DialectsequenceName - the name of the sequencepublic String getSelectSequenceNextValString(String sequenceName) throws MappingException
DialectGenerate the select expression fragment that will retrieve the next
value of a sequence as part of another (typically DML) statement.
<p/>
This differs from Dialect.getSequenceNextValString(String) in that this
should return an expression usable within another statement.
getSelectSequenceNextValString in class DialectsequenceName - the name of the sequenceMappingException - If sequences are not supported.public String getCreateSequenceString(String sequenceName)
DialectTypically 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.
<p/>
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).
getCreateSequenceString in class DialectsequenceName - The name of the sequencepublic String getDropSequenceString(String sequenceName)
DialectTypically 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.
<p/>
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).
getDropSequenceString in class DialectsequenceName - The name of the sequencepublic boolean supportsSequences()
DialectDoes this dialect support sequences?
supportsSequences in class Dialectpublic boolean supportsPooledSequences()
DialectDoes this dialect support "pooled" sequences. Not aware of a better name for this. Essentially can we specify the initial and increment values?
supportsPooledSequences in class DialectDialect.getCreateSequenceStrings(String, int, int),
Dialect.getCreateSequenceString(String, int, int)public String getQuerySequencesString()
DialectGet the select command used retrieve the names of all sequences.
getQuerySequencesString in class DialectSchemaUpdatepublic boolean supportsLimit()
DialectDoes this dialect support some form of limiting query results via a SQL clause?
supportsLimit in class Dialectpublic boolean supportsVariableLimit()
DialectDoes this dialect support bind variables (i.e., prepared statement parameters) for its limit/offset?
supportsVariableLimit in class Dialectpublic String getLimitString(String sql, int offset, int limit)
DialectGiven a limit and an offset, apply the limit clause to the query.
getLimitString in class Dialectsql - The query to which to apply the limit.offset - The offset of the limitlimit - The limit of the limit ;)public int convertToFirstRowValue(int zeroBasedFirstResult)
Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset. Here we allow the
Dialect a chance to convert that value based on what the underlying db or driver will expect.
<p/>
NOTE: what gets passed into Dialect.getLimitString(String,int,int) is the zero-based offset. Dialects which
do not Dialect.supportsVariableLimit() should take care to perform any needed first-row-conversion calls prior
to injecting the limit values into the SQL string.
DB2 does have a one-based offset, however this was actually already handled in the limit string building (the '?+1' bit). To not mess up inheritors, I’ll leave that part alone and not touch the offset here.
convertToFirstRowValue in class DialectzeroBasedFirstResult - The user-supplied, zero-based first row offset.Query.setFirstResult(int),
Criteria.setFirstResult(int)public String getForUpdateString()
DialectGet the string to append to SELECT statements to acquire locks for this dialect.
getForUpdateString in class Dialectpublic boolean useMaxForLimit()
DialectDoes the <tt>LIMIT</tt> clause take a "maximum" row number instead of a total number of returned rows? <p/> 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) <p/> So essentially, is limit relative from offset? Or is limit absolute?
useMaxForLimit in class Dialectpublic boolean supportsOuterJoinForUpdate()
DialectDoes this dialect support <tt>FOR UPDATE</tt> in conjunction with outer joined rows?
supportsOuterJoinForUpdate in class Dialectpublic boolean supportsExistsInSelect()
DialectDoes the dialect support an exists statement in the select clause?
supportsExistsInSelect in class Dialectpublic boolean supportsLockTimeouts()
DialectInformational metadata about whether this dialect is known to support specifying timeouts for requested lock acquisitions.
supportsLockTimeouts in class Dialectpublic String getSelectClauseNullString(int sqlType)
DialectGiven a Types type code, determine an appropriate
null value to use in a select clause.
<p/>
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.
getSelectClauseNullString in class DialectsqlType - The Types type code.public boolean supportsUnionAll()
DialectDoes this dialect support UNION ALL, which is generally a faster variant of UNION?
supportsUnionAll in class Dialectpublic int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException
DialectRegisters a parameter (either OUT, or the new REF_CURSOR param type available in Java 8) capable of
returning ResultSet by position. Pre-Java 8, registering such ResultSet-returning
parameters varied greatly across database and drivers; hence its inclusion as part of the Dialect contract.
registerResultSetOutParameter in class Dialectstatement - The callable statement.col - The bind position at which to register the output param.SQLException - Indicates problems registering the param.public ResultSet getResultSet(CallableStatement ps) throws SQLException
DialectGiven a callable statement previously processed by Dialect.registerResultSetOutParameter(java.sql.CallableStatement, int),
extract the ResultSet from the OUT parameter.
getResultSet in class Dialectps - The callable statement.SQLException - Indicates problems extracting the result set.public boolean supportsCommentOn()
DialectDoes this dialect/database support commenting on tables, columns, etc?
supportsCommentOn in class Dialecttrue if commenting is supportedpublic MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy()
getDefaultMultiTableBulkIdStrategy in class Dialectpublic boolean supportsCurrentTimestampSelection()
DialectDoes this dialect support a way to retrieve the database’s current timestamp value?
supportsCurrentTimestampSelection in class Dialectpublic String getCurrentTimestampSelectString()
DialectRetrieve the command used to retrieve the current timestamp from the database.
getCurrentTimestampSelectString in class Dialectpublic boolean isCurrentTimestampSelectStringCallable()
DialectShould the value returned by Dialect.getCurrentTimestampSelectString()
be treated as callable. Typically this indicates that JDBC escape
syntax is being used…
isCurrentTimestampSelectStringCallable in class DialectDialect.getCurrentTimestampSelectString() return
is callable; false otherwise.public boolean supportsParametersInInsertSelect()
Does this dialect support parameters within the <tt>SELECT</tt> clause of <tt>INSERT … SELECT …</tt> statements?
<p/> NOTE : DB2 is know to support parameters in the <tt>SELECT</tt> clause, but only in casted form (seerequiresCastingOfParametersInSelectClause()).supportsParametersInInsertSelect in class Dialectpublic boolean requiresCastingOfParametersInSelectClause()
Does this dialect require that parameters appearing in the <tt>SELECT</tt> clause be wrapped in <tt>cast()</tt> calls to tell the db parser the expected type.
<p/> 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.requiresCastingOfParametersInSelectClause in class Dialectpublic boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor()
DialectDoes 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.
<p/>
NOTE : this is highly driver dependent!
supportsResultSetPositionQueryMethodsOnForwardOnlyCursor in class DialectResultSet.isAfterLast() and
ResultSet.isBeforeFirst() are supported for forward
only cursors; false otherwise.public String getCrossJoinSeparator()
DialectReturns the separator to use for defining cross joins when translating HQL queries. <p/> Typically this will be either [<tt> cross join </tt>] or [<tt>, </tt>] <p/> Note that the spaces are important!
getCrossJoinSeparator in class Dialectpublic boolean supportsEmptyInList()
DialectDoes this dialect support empty IN lists? <p/> For example, is [where XYZ in ()] a supported construct?
supportsEmptyInList in class Dialectpublic boolean supportsLobValueChangePropogation()
DialectDoes the dialect support propagating 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…
<p/>
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).
<p/>
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).
<p/>
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().
supportsLobValueChangePropogation in class Dialectpublic boolean doesReadCommittedCauseWritersToBlockReaders()
DialectFor the underlying database, is READ_COMMITTED isolation implemented by forcing readers to wait for write locks to be released?
doesReadCommittedCauseWritersToBlockReaders in class Dialectpublic boolean supportsTupleDistinctCounts()
DialectDoes this dialect support count(distinct a,b)?
supportsTupleDistinctCounts in class Dialectprotected SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode)
DialectReturns the SqlTypeDescriptor that should be used to handle the given JDBC type code. Returns
null if there is no override.
getSqlTypeDescriptorOverride in class DialectsqlCode - A Types constant indicating the SQL column typeSqlTypeDescriptor to use as an override, or null if there is no override.public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate()
DialectBuild an instance of a SQLExceptionConversionDelegate for
interpreting dialect-specific error or SQLState codes.
<p/>
When Dialect.buildSQLExceptionConverter() returns null, the default
SQLExceptionConverter is used to interpret SQLState and
error codes. If this method is overridden to return a non-null value,
the default SQLExceptionConverter will use the returned
SQLExceptionConversionDelegate in addition to the following
standard delegates:
<ol>
<li>a "static" delegate based on the JDBC 4 defined SQLException hierarchy;</li>
<li>a delegate that interprets SQLState codes for either X/Open or SQL-2003 codes,
depending on java.sql.DatabaseMetaData#getSQLStateType</li>
</ol>
<p/>
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 a vendor-specific ErrorCode rather than the SQLState.
<p/>
Specific Dialects may override to return whatever is most appropriate for that vendor.
buildSQLExceptionConversionDelegate in class Dialectpublic UniqueDelegate getUniqueDelegate()
DialectGet the UniqueDelegate supported by this dialect
getUniqueDelegate in class Dialectpublic String getNotExpression(String expression)
DialectNegate an expression
getNotExpression in class Dialectexpression - The expression to negatepublic LimitHandler getLimitHandler()
DialectReturns the delegate managing LIMIT clause.
getLimitHandler in class Dialectpublic String renderOrderByElement(String expression, String collation, String order, NullPrecedence nullPrecedence)
Handle DB2 "support" for null precedence…
renderOrderByElement in class Dialectexpression - The SQL order expression. In case of @OrderBy annotation user receives property placeholder
(e.g. attribute name enclosed in '{' and '}' signs).collation - Collation string in format collate IDENTIFIER, or null
if expression has not been explicitly specified.order - Order direction. Possible values: asc, desc, or null
if expression has not been explicitly specified.nullPrecedence - Nulls precedence. Default value: NullPrecedence.NONE.public IdentityColumnSupport getIdentityColumnSupport()
DialectGet the appropriate IdentityColumnSupport
getIdentityColumnSupport in class Dialectpublic boolean supportsPartitionBy()
DialectDoes the underlying database support partition by
supportsPartitionBy in class DialectCopyright © 2001-2018 Red Hat, Inc. All Rights Reserved.