Module bus.pager

Class SqlServer

All Implemented Interfaces:
Dialect
Direct Known Subclasses:
SqlServer2012

public class SqlServer extends AbstractPaging
Database dialect for SQL Server. This class provides SQL Server-specific implementations for pagination SQL generation and parameter processing. It also handles SQL caching and replacement for specific SQL Server syntax like `with(nolock)`.
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

    • sqlServerSqlParser

      protected SqlServerSqlParser sqlServerSqlParser
      SQL Server specific SQL parser for pagination.
    • CACHE_COUNTSQL

      protected org.miaixz.bus.cache.CacheX<String,String> CACHE_COUNTSQL
      Cache for count SQL queries.
    • CACHE_PAGESQL

      protected org.miaixz.bus.cache.CacheX<String,String> CACHE_PAGESQL
      Cache for paginated SQL queries.
    • replaceSql

      protected ReplaceSql replaceSql
      Utility for replacing and restoring SQL parts, especially for `with(nolock)`.
  • Constructor Details

    • SqlServer

      public SqlServer()
  • Method Details

    • getCountSql

      public String getCountSql(org.apache.ibatis.mapping.MappedStatement ms, org.apache.ibatis.mapping.BoundSql boundSql, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey countKey)
      Generates the SQL for the count query for SQL Server. It uses a cache to store and retrieve count SQL, and applies SQL replacement rules.
      Specified by:
      getCountSql in interface Dialect
      Overrides:
      getCountSql in class AbstractPaging
      Parameters:
      ms - the MappedStatement object
      boundSql - the BoundSql object containing the original SQL and parameters
      parameterObject - the parameter object for the query
      rowBounds - the RowBounds object containing pagination parameters
      countKey - the CacheKey for the count query
      Returns:
      the generated count SQL string
    • processPageParameter

      public Object processPageParameter(org.apache.ibatis.mapping.MappedStatement ms, Map<String,Object> paramMap, Page page, org.apache.ibatis.mapping.BoundSql boundSql, org.apache.ibatis.cache.CacheKey pageKey)
      Processes the pagination parameters for SQL Server. This implementation simply returns the parameter map as is.
      Specified by:
      processPageParameter in class AbstractPaging
      Parameters:
      ms - the MappedStatement object
      paramMap - a map containing the query parameters
      page - the Page object containing pagination details
      boundSql - the BoundSql object for the query
      pageKey - the CacheKey for the paginated query
      Returns:
      the processed parameter map
    • getPageSql

      public String getPageSql(String sql, Page page, org.apache.ibatis.cache.CacheKey pageKey)
      Generates the SQL Server-specific pagination SQL. It uses a cache to store and retrieve paginated SQL, applies SQL replacement rules, and substitutes pagination parameters.
      Specified by:
      getPageSql in class AbstractPaging
      Parameters:
      sql - the original SQL string
      page - the Page object containing pagination details
      pageKey - the CacheKey for the paginated query
      Returns:
      the SQL Server-specific paginated SQL string
    • getPageSql

      public String getPageSql(org.apache.ibatis.mapping.MappedStatement ms, org.apache.ibatis.mapping.BoundSql boundSql, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.cache.CacheKey pageKey)
      Overrides the parent method to handle SQL Server specific pagination, especially for `with(nolock)` clauses. It first replaces specific SQL parts, then applies order by, and finally restores the SQL.
      Specified by:
      getPageSql in interface Dialect
      Overrides:
      getPageSql in class AbstractPaging
      Parameters:
      ms - the MappedStatement object
      boundSql - the BoundSql object containing the original SQL and parameters
      parameterObject - the parameter object for the query
      rowBounds - the RowBounds object containing pagination parameters
      pageKey - the CacheKey for the paginated query
      Returns:
      the generated paginated SQL string
    • setProperties

      public void setProperties(Properties properties)
      Sets the properties for this SQL Server dialect. It initializes the SqlServerSqlParser, ReplaceSql implementation, and SQL caches.
      Specified by:
      setProperties in interface Dialect
      Overrides:
      setProperties in class AbstractPaging
      Parameters:
      properties - the properties to set