Top Description Fields Constructors Methods
org.hibernate.dialect

public Class SQLServer2005Dialect

extends SQLServerDialect
Class Inheritance
Known Direct Subclasses
org.hibernate.dialect.SQLServer2008Dialect
Imports
java.sql.Types, org.hibernate.dialect.function.NoArgSQLFunction, org.hibernate.type.StandardBasicTypes

A dialect for Microsoft SQL 2005. (HHH-3936 fix)
Author
Yoryos Valotasios

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final int
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
bindLimitParametersFirst()

Overrides org.hibernate.dialect.Dialect.bindLimitParametersFirst.

Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?
public int
convertToFirstRowValue(int
The user-supplied, zero-based first row offset.
zeroBasedFirstResult
)

Overrides org.hibernate.dialect.Dialect.convertToFirstRowValue.

Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset.
public String
getLimitString(String
The query to which to apply the limit.
query
,
int
The offset of the limit
offset
,
int
The limit of the limit ;)
limit
)

Overrides org.hibernate.dialect.SQLServerDialect.getLimitString.

Given a limit and an offset, apply the limit clause to the query.
public String

Returns:

A new SQL statement with the LIMIT clause applied.
getLimitString
(String
The SQL statement to base the limit query off of.
querySqlString
,
boolean
Offset of the first row to be returned by the query (zero-based)
hasOffset
)

Overrides org.hibernate.dialect.Dialect.getLimitString.

Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging) The LIMIT SQL will look like:
WITH query AS (
  SELECT ROW_NUMBER() OVER (ORDER BY orderby) as __hibernate_row_nr__, 
  original_query_without_orderby
)
SELECT * FROM query WHERE __hibernate_row_nr__ BEETWIN offset AND offset + last
protected static CharSequence

Returns:

the fields of the select statement without their alias
getSelectFieldsWithoutAliases
(StringBuilder
sql query
sql
)

This utility method searches the given sql query for the fields of the select statement and returns them without the aliases.

protected static void
insertRowNumberFunction(StringBuilder
the initial sql query without the order by clause
sql
,
CharSequence
the order by clause of the query
orderby
)

Right after the select statement of a given query we must place the row_number function

protected static void
replaceDistinctWithGroupBy(StringBuilder
an sql query
sql
)

Utility method that checks if the given sql query is a select distinct one and if so replaces the distinct select with an equivalent simple select with a group by clause.

protected static String

Returns:

a string without the as statements
stripAliases
(String
string to replace the as statements
str
)

Utility method that strips the aliases.

public boolean
supportsLimitOffset()

Overrides org.hibernate.dialect.SQLServerDialect.supportsLimitOffset.

Does this dialect's LIMIT support (if any) additionally support specifying an offset?
public boolean
supportsVariableLimit()

Overrides org.hibernate.dialect.SQLServerDialect.supportsVariableLimit.

Does this dialect support bind variables (i.e., prepared statement parameters) for its limit/offset?
Inherited from org.hibernate.dialect.SQLServerDialect:
appendIdentitySelectToInsertappendLockHintareStringComparisonsCaseInsensitivecloseQuotedoesReadCommittedCauseWritersToBlockReadersdoesRepeatableReadCauseReadersToBlockWritersgetAfterSelectInsertPointgetCurrentTimestampSelectStringgetNoColumnsInsertStringopenQuotesupportsCircularCascadeDeleteConstraintssupportsLimitsupportsLobValueChangePropogationsupportsResultSetPositionQueryMethodsOnForwardOnlyCursoruseMaxForLimit

Field Detail

DISTINCTback to summary
private static final String DISTINCT
FROMback to summary
private static final String FROM
MAX_LENGTHback to summary
private static final int MAX_LENGTH
SELECTback to summary
private static final String SELECT

Constructor Detail

SQLServer2005Dialectback to summary
public SQLServer2005Dialect()

Method Detail

bindLimitParametersFirstback to summary
public boolean bindLimitParametersFirst()

Overrides org.hibernate.dialect.Dialect.bindLimitParametersFirst.

Doc from org.hibernate.dialect.Dialect.bindLimitParametersFirst.

Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?

Returns:boolean

true if limit parameters should come before other parameters

Annotations
@Override
convertToFirstRowValueback to summary
public int convertToFirstRowValue(int zeroBasedFirstResult)

Overrides org.hibernate.dialect.Dialect.convertToFirstRowValue.

Doc from org.hibernate.dialect.Dialect.convertToFirstRowValue.

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.

Note

what gets passed into getLimitString(String, int, int) is the zero-based offset. Dialects which do not supportsVariableLimit should take care to perform any needed convertToFirstRowValue calls prior to injecting the limit values into the SQL string.

Parameters
zeroBasedFirstResult:int

The user-supplied, zero-based first row offset.

Returns:int

The corresponding db/dialect specific offset.

Annotations
@Override
getLimitStringback to summary
public String getLimitString(String query, int offset, int limit)

Overrides org.hibernate.dialect.SQLServerDialect.getLimitString.

Doc from org.hibernate.dialect.Dialect.getLimitString.

Given a limit and an offset, apply the limit clause to the query.

Parameters
query:String

The query to which to apply the limit.

offset:int

The offset of the limit

limit:int

The limit of the limit ;)

Returns:String

The modified query statement with the limit applied.

Annotations
@Override
getLimitStringback to summary
public String getLimitString(String querySqlString, boolean hasOffset)

Overrides org.hibernate.dialect.Dialect.getLimitString.

Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging) The LIMIT SQL will look like:

WITH query AS (
  SELECT ROW_NUMBER() OVER (ORDER BY orderby) as __hibernate_row_nr__, 
  original_query_without_orderby
)
SELECT * FROM query WHERE __hibernate_row_nr__ BEETWIN offset AND offset + last
Parameters
querySqlString:String

The SQL statement to base the limit query off of.

hasOffset:boolean

Offset of the first row to be returned by the query (zero-based)

Returns:String

A new SQL statement with the LIMIT clause applied.

Annotations
@Override
getSelectFieldsWithoutAliasesback to summary
protected static CharSequence getSelectFieldsWithoutAliases(StringBuilder sql)

This utility method searches the given sql query for the fields of the select statement and returns them without the aliases. See SQLServer2005DialectTestCase#testGetSelectFieldsWithoutAliases()

Parameters
sql:StringBuilder

sql query

Returns:CharSequence

the fields of the select statement without their alias

insertRowNumberFunctionback to summary
protected static void insertRowNumberFunction(StringBuilder sql, CharSequence orderby)

Right after the select statement of a given query we must place the row_number function

Parameters
sql:StringBuilder

the initial sql query without the order by clause

orderby:CharSequence

the order by clause of the query

replaceDistinctWithGroupByback to summary
protected static void replaceDistinctWithGroupBy(StringBuilder sql)

Utility method that checks if the given sql query is a select distinct one and if so replaces the distinct select with an equivalent simple select with a group by clause. See SQLServer2005DialectTestCase#testReplaceDistinctWithGroupBy()

Parameters
sql:StringBuilder

an sql query

stripAliasesback to summary
protected static String stripAliases(String str)

Utility method that strips the aliases. See SQLServer2005DialectTestCase#testStripAliases()

Parameters
str:String

string to replace the as statements

Returns:String

a string without the as statements

supportsLimitOffsetback to summary
public boolean supportsLimitOffset()

Overrides org.hibernate.dialect.SQLServerDialect.supportsLimitOffset.

Doc from org.hibernate.dialect.Dialect.supportsLimitOffset.

Does this dialect's LIMIT support (if any) additionally support specifying an offset?

Returns:boolean

True if the dialect supports an offset within the limit support.

Annotations
@Override
supportsVariableLimitback to summary
public boolean supportsVariableLimit()

Overrides org.hibernate.dialect.SQLServerDialect.supportsVariableLimit.

Doc from org.hibernate.dialect.Dialect.supportsVariableLimit.

Does this dialect support bind variables (i.e., prepared statement parameters) for its limit/offset?

Returns:boolean

True if bind variables can be used; false otherwise.

Annotations
@Override