public class

SQLServer2005Dialect

extends SQLServerDialect
java.lang.Object
   ↳ org.hibernate.dialect.Dialect
     ↳ org.hibernate.dialect.SQLServerDialect
       ↳ org.hibernate.dialect.SQLServer2005Dialect

Class Overview

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

Summary

[Expand]
Inherited Constants
From class org.hibernate.dialect.Dialect
Public Constructors
SQLServer2005Dialect()
Public Methods
boolean bindLimitParametersFirst()
Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?
int convertToFirstRowValue(int zeroBasedFirstResult)
Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset.
String getLimitString(String query, int offset, int limit)
Given a limit and an offset, apply the limit clause to the query.
String getLimitString(String querySqlString, boolean hasOffset)
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
 
boolean supportsLimitOffset()
Does this dialect's LIMIT support (if any) additionally support specifying an offset?
boolean supportsVariableLimit()
Does this dialect support bind variables (i.e., prepared statement parameters) for its limit/offset?
Protected Methods
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.
static void insertRowNumberFunction(StringBuilder sql, CharSequence orderby)
Right after the select statement of a given query we must place the row_number function
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.
static String stripAliases(String str)
Utility method that strips the aliases.
[Expand]
Inherited Methods
From class org.hibernate.dialect.SQLServerDialect
From class org.hibernate.dialect.Dialect
From class java.lang.Object

Public Constructors

public SQLServer2005Dialect ()

Public Methods

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

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.

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(int) calls prior to injecting the limit values into the SQL string.

Parameters
zeroBasedFirstResult The user-supplied, zero-based first row offset.
Returns
  • The corresponding db/dialect specific offset.

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

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

Parameters
query 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.

public String getLimitString (String querySqlString, boolean hasOffset)

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 The SQL statement to base the limit query off of.
hasOffset Is the query requesting an offset?
Returns
  • A new SQL statement with the LIMIT clause applied.

public boolean supportsLimitOffset ()

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

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

public boolean supportsVariableLimit ()

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

Returns
  • True if bind variables can be used; false otherwise.

Protected Methods

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()

Returns
  • the fields of the select statement without their alias

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 the initial sql query without the order by clause
orderby the order by clause of the query

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 an sql query

protected static String stripAliases (String str)

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

Returns
  • a string without the as statements