Class BaseDialect

java.lang.Object
org.huiche.dialect.BaseDialect
All Implemented Interfaces:
Dialect
Direct Known Subclasses:
DB2Dialect, DMDialect, H2Dialect, HSQLDialect, MySQLDialect, OracleDialect, PostgreSQLDialect, SQLiteDialect, SQLServerDialect

public abstract class BaseDialect extends Object implements Dialect
默认方言实现
Author:
Maning
  • Field Details

    • keywords

      protected final Set<String> keywords
      完整关键字(内置关键字与数据库关键字的并集)
    • quoteString

      protected final String quoteString
      标识符转义字符串
  • Constructor Details

    • BaseDialect

      public BaseDialect()
      默认构造
    • BaseDialect

      public BaseDialect(String quoteString)
      自定义转义标识符构造
      Parameters:
      quoteString - 标识符转义字符串
    • BaseDialect

      public BaseDialect(String quoteString, Set<String> keywords)
      默认构造
      Parameters:
      quoteString - 标识符转义字符串
      keywords - 数据库关键字(会与内置关键字合并)
  • Method Details

    • quote

      public String quote(String identifier)
      标识符转义
      Specified by:
      quote in interface Dialect
      Parameters:
      identifier - 标识符,不能为null或空串
      Returns:
      转义后标识符
      Throws:
      HcDialectException - 标识符为null或空串时
    • quoteIdentifier

      protected String quoteIdentifier(String identifier)
      转义标识符,缓存未命中时调用

      标识符固定按 . 解析层级(schema.table、database.schema.table 等), 逐段判断是否需要引用,而不是把整串当成一个标识符。

      不做特殊形态判断:已自带引号的标识符会被再次引用;空段(如 a..b)原样保留、不加引号。

      Parameters:
      identifier - 标识符
      Returns:
      转义后标识符
    • quotePart

      protected String quotePart(String part)
      转义单段标识符,不同数据库转义方式不同时可覆写此方法
      Parameters:
      part - 标识符片段
      Returns:
      转义后标识符片段
    • translate

      public Translation translate(Statement statement)
      Description copied from interface: Dialect
      将语句翻译为sql
      Specified by:
      translate in interface Dialect
      Parameters:
      statement - 语句,不能为null
      Returns:
      翻译结果,不允许返回null
    • translate

      public Translation translate(Segment segment)
      Description copied from interface: Dialect
      将SQL片段翻译为sql
      Specified by:
      translate in interface Dialect
      Parameters:
      segment - SQL片段,不能为null
      Returns:
      翻译结果,不允许返回null
    • translateCustom

      public Translation translateCustom(Segment segment)
      Description copied from interface: Dialect
      转译自定义SQL,会在转译最后执行
      Specified by:
      translateCustom in interface Dialect
      Parameters:
      segment - SQL片段,不能为null
      Returns:
      翻译结果,不允许返回null
    • translatePaging

      public Translation translatePaging(Integer limit, Integer offset)
      Description copied from interface: Dialect
      转译分页
      Specified by:
      translatePaging in interface Dialect
      Parameters:
      limit - 限制条数
      offset - 跳过条数
      Returns:
      分页语法