org.hibernate.dialect
Class SQLServerDialect

java.lang.Object
  extended by org.hibernate.dialect.Dialect
      extended by org.hibernate.dialect.SQLServerDialect
Direct Known Subclasses:
SQLServer2005Dialect

public class SQLServerDialect
extends Dialect

A dialect for Microsoft SQL Server 2000

Author:
Gavin King

Field Summary
 
Fields inherited from class org.hibernate.dialect.Dialect
CLOSED_QUOTE, DEFAULT_BATCH_SIZE, NO_BATCH, QUOTE
 
Constructor Summary
SQLServerDialect()
           
 
Method Summary
 String appendIdentitySelectToInsert(String insertSQL)
          Use insert table(...) values(...) select SCOPE_IDENTITY()
 String appendLockHint(LockMode mode, String tableName)
          Some dialects support an alternative means to SELECT FOR UPDATE, whereby a "lock hint" is appends to the table name in the from clause.
 String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map keyColumnNames)
          Modifies the given SQL by applying the appropriate updates for the specified lock modes and key columns.
 boolean areStringComparisonsCaseInsensitive()
          Are string comparisons implicitly case insensitive.
 char closeQuote()
          The character specific to this dialect used to close a quoted identifier.
 boolean doesReadCommittedCauseWritersToBlockReaders()
          For the underlying database, is READ_COMMITTED isolation implemented by forcing readers to wait for write locks to be released?
 boolean doesRepeatableReadCauseReadersToBlockWriters()
          For the underlying database, is REPEATABLE_READ isolation implemented by forcing writers to wait for read locks to be released?
 boolean dropTemporaryTableAfterUse()
          Do we need to drop the temporary table after use?
 String generateTemporaryTableName(String baseTableName)
          Generate a temporary table name given the base table.
 String getAddColumnString()
          The syntax used to add a column to a table (optional).
 String getCurrentTimestampSelectString()
          Retrieve the command used to retrieve the current timestamp from the database.
 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 getIdentitySelectString()
          Get the select command to use to retrieve the last generated IDENTITY value.
 String getLimitString(String querySelect, int offset, int limit)
          Given a limit and an offset, apply the limit clause to the query.
 String getNoColumnsInsertString()
          The fragment used to insert a row without specifying any column values.
 String getNullColumnString()
          The keyword used to specify a nullable column.
 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 getSelectGUIDString()
          Get the command used to select a GUID from the underlying database.
 boolean isCurrentTimestampSelectStringCallable()
          Should the value returned by Dialect.getCurrentTimestampSelectString() be treated as callable.
 char openQuote()
          The character specific to this dialect used to begin a quoted identifier.
 boolean qualifyIndexName()
          Do we need to qualify index names with the schema name?
 int registerResultSetOutParameter(CallableStatement statement, int col)
          Registers an OUT parameter which will be returning a ResultSet.
 boolean supportsCircularCascadeDeleteConstraints()
          Does this dialect support definition of cascade delete constraints which can cause circular chains?
 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 supportsExistsInSelect()
          Does the dialect support an exists statement in the select clause?
 boolean supportsIdentityColumns()
          Does this dialect support identity column key generation?
 boolean supportsInsertSelectIdentity()
          Does the dialect support some form of inserting and selecting the generated IDENTITY value all in the same statement.
 boolean supportsLimit()
          Does this dialect support some form of limiting query results via a SQL clause?
 boolean supportsLimitOffset()
          Does this dialect's LIMIT support (if any) additionally support specifying an offset?
 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...
 boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor()
          Does this dialect support asking the result set its positioning information on forward only cursors.
 boolean supportsTemporaryTables()
          Does this dialect support temporary tables?
 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 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
addTypeOverride, bindLimitParametersFirst, bindLimitParametersInReverseOrder, buildSQLExceptionConverter, convertToFirstRowValue, createCaseFragment, createOuterJoinFragment, dropConstraints, forceLimitUsage, forUpdateOfColumns, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getCascadeConstraintsString, getCastTypeName, getColumnAliasExtractor, getColumnComment, getCreateMultisetTableString, getCreateSequenceString, getCreateSequenceString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCreateTemporaryTablePostfix, getCreateTemporaryTableString, getCrossJoinSeparator, getCurrentTimestampSQLFunctionName, getDefaultProperties, getDialect, getDialect, getDropForeignKeyString, getDropSequenceString, getDropSequenceStrings, getDropTemporaryTableString, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIdentityColumnString, getIdentityInsertString, getIdentitySelectString, getKeywords, getLimitString, getLockingStrategy, getLowercaseFunction, getMaxAliasLength, getNativeIdentifierGeneratorClass, getQuerySequencesString, getReadLockString, getSelectClauseNullString, getSelectSequenceNextValString, getSequenceNextValString, getTableComment, getTableTypeString, getTypeName, getTypeName, getTypeOverrides, getViolatedConstraintNameExtracter, getWriteLockString, hasAlterTable, hasDataTypeInIdentityColumn, hasSelfReferentialForeignKeyBug, isLockTimeoutParameterized, performTemporaryTableDDLInIsolation, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, replaceResultVariableInOrderByClauseWithPosition, requiresCastingOfParametersInSelectClause, supportsBindAsCallableArgument, supportsCascadeDelete, supportsColumnCheck, supportsCommentOn, supportsExpectedLobUsagePattern, supportsIfExistsAfterTableName, supportsIfExistsBeforeTableName, supportsLockTimeouts, supportsNotNullUnique, supportsOuterJoinForUpdate, supportsParametersInInsertSelect, supportsPooledSequences, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsSequences, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsTupleCounts, supportsUnboundedLobLocatorMaterialization, supportsUnique, supportsUniqueConstraintInCreateAlterTable, toBooleanValueString, toString, transformSelectString, useInputStreamToInsertBlob
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SQLServerDialect

public SQLServerDialect()
Method Detail

getNoColumnsInsertString

public String getNoColumnsInsertString()
Description copied from class: Dialect
The fragment used to insert a row without specifying any column values. This is not possible on some databases.

Overrides:
getNoColumnsInsertString in class Dialect
Returns:
The appropriate empty values clause.

getLimitString

public String getLimitString(String querySelect,
                             int offset,
                             int limit)
Description copied from class: Dialect
Given a limit and an offset, apply the limit clause to the query.

Overrides:
getLimitString in class Dialect
Parameters:
querySelect - The query to which to apply the limit.
offset - The offset of the limit
limit - The limit of the limit ;)
Returns:
The modified query statement with the limit applied.

appendIdentitySelectToInsert

public String appendIdentitySelectToInsert(String insertSQL)
Use insert table(...) values(...) select SCOPE_IDENTITY()

Parameters:
insertSQL - The insert command
Returns:
The insert command with any necessary identity select clause attached.

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.

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.

supportsLimitOffset

public boolean supportsLimitOffset()
Description copied from class: Dialect
Does this dialect's LIMIT support (if any) additionally support specifying an offset?

Overrides:
supportsLimitOffset in class Dialect
Returns:
True if the dialect supports an offset within the limit support.

supportsVariableLimit

public boolean supportsVariableLimit()
Description copied from class: Dialect
Does this dialect support bind variables (i.e., prepared statement parameters) for its limit/offset?

Overrides:
supportsVariableLimit in class Dialect
Returns:
True if bind variables can be used; false otherwise.

closeQuote

public char closeQuote()
Description copied from class: Dialect
The character specific to this dialect used to close a quoted identifier.

Overrides:
closeQuote in class Dialect
Returns:
The dialect's specific close quote character.

openQuote

public char openQuote()
Description copied from class: Dialect
The character specific to this dialect used to begin a quoted identifier.

Overrides:
openQuote in class Dialect
Returns:
The dialect's specific open quote character.

appendLockHint

public String appendLockHint(LockMode mode,
                             String tableName)
Description copied from class: Dialect
Some dialects support an alternative means to SELECT FOR UPDATE, whereby a "lock hint" is appends to the table name in the from clause.

contributed by Helge Schulz

Parameters:
mode - The lock mode to apply
tableName - The name of the table to which to apply the lock hint.
Returns:
The table with any required lock hints.

getCurrentTimestampSelectString

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

Returns:
The command.

areStringComparisonsCaseInsensitive

public boolean areStringComparisonsCaseInsensitive()
Description copied from class: Dialect
Are string comparisons implicitly case insensitive.

In other words, does [where 'XYZ' = 'xyz'] resolve to true?

Overrides:
areStringComparisonsCaseInsensitive in class Dialect
Returns:
True if comparisons are case insensitive.

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.

supportsCircularCascadeDeleteConstraints

public boolean supportsCircularCascadeDeleteConstraints()
Description copied from class: Dialect
Does this dialect support definition of cascade delete constraints which can cause circular chains?

Overrides:
supportsCircularCascadeDeleteConstraints in class Dialect
Returns:
True if circular cascade delete constraints are supported; false otherwise.

supportsLobValueChangePropogation

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

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 propagated 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?

Returns:
True if writers block readers to achieve READ_COMMITTED; false otherwise.

doesRepeatableReadCauseReadersToBlockWriters

public boolean doesRepeatableReadCauseReadersToBlockWriters()
Description copied from class: Dialect
For the underlying database, is REPEATABLE_READ isolation implemented by forcing writers to wait for read locks to be released?

Returns:
True if readers block writers to achieve REPEATABLE_READ; false otherwise.

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.

getNullColumnString

public String getNullColumnString()
Description copied from class: Dialect
The keyword used to specify a nullable column.

Overrides:
getNullColumnString in class Dialect
Returns:
String

qualifyIndexName

public boolean qualifyIndexName()
Description copied from class: Dialect
Do we need to qualify index names with the schema name?

Overrides:
qualifyIndexName in class Dialect
Returns:
boolean

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.

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.

supportsInsertSelectIdentity

public boolean supportsInsertSelectIdentity()
Description copied from class: Dialect
Does the dialect support some form of inserting and selecting the generated IDENTITY value all in the same statement.

Overrides:
supportsInsertSelectIdentity in class Dialect
Returns:
True if the dialect supports selecting the just generated IDENTITY in the insert statement.

applyLocksToSql

public String applyLocksToSql(String sql,
                              LockOptions aliasedLockOptions,
                              Map keyColumnNames)
Description copied from class: Dialect
Modifies the given SQL by applying the appropriate updates for the specified lock modes and key columns.

The behavior here is that of an ANSI SQL SELECT FOR UPDATE. This method is really intended to allow dialects which do not support SELECT FOR UPDATE to achieve this in their own fashion.

Overrides:
applyLocksToSql in class Dialect
Parameters:
sql - the SQL string to modify
aliasedLockOptions - lock options indexed by aliased table names.
keyColumnNames - a map of key columns indexed by aliased table names.
Returns:
the modified SQL string.

registerResultSetOutParameter

public int registerResultSetOutParameter(CallableStatement statement,
                                         int col)
                                  throws SQLException
Description copied from class: Dialect
Registers an OUT parameter which will be returning 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.

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.

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 syntax is being used...

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

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.

generateTemporaryTableName

public String generateTemporaryTableName(String baseTableName)
Description copied from class: Dialect
Generate a temporary table name given the base 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.

dropTemporaryTableAfterUse

public boolean dropTemporaryTableAfterUse()
Description copied from class: Dialect
Do we need to drop the temporary table after use?

Overrides:
dropTemporaryTableAfterUse in class Dialect
Returns:
True if the table should be dropped.

getSelectGUIDString

public String getSelectGUIDString()
Description copied from class: Dialect
Get the command used to select a GUID from the underlying database.

Optional operation.

Overrides:
getSelectGUIDString in class Dialect
Returns:
The appropriate command.

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.

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.

supportsExistsInSelect

public boolean supportsExistsInSelect()
Description copied from class: Dialect
Does the dialect support an exists statement in the select clause?

Overrides:
supportsExistsInSelect in class Dialect
Returns:
True if exists checks are allowed in the select clause; false otherwise.

supportsTupleDistinctCounts

public boolean supportsTupleDistinctCounts()
Description copied from class: Dialect
Does this dialect support `count(distinct a,b)`?

Overrides:
supportsTupleDistinctCounts in class Dialect
Returns:
True if the database supports counting disintct tuples; false otherwise.


Copyright © 2001-2010 Red Hat, Inc. All Rights Reserved.