Skip to content

6.1.0 - 2023-12-16

Latest
Compare
Choose a tag to compare
@pagehelper pagehelper released this 17 Dec 05:24
· 17 commits to master since this release
  • 发布6.1.0,PageHelper 提供 jsqlparser直接依赖都是中间接口,可以通过SPI替换默认实现
  • 升级jsqlparser版本4.7,重新实现order by,分页,count查询
  • 简化pom.xml配置,去掉shade内嵌jsqlparser方式,改为通过外部依赖选择不同的jsqlparser版本,允许自己SPI扩展
  • jsqlparser解析不使用线程池,支持SPI扩展覆盖SqlParser实现
  • SqlServer分页改为SqlServerSqlParser接口,添加参数 sqlServerSqlParser 覆盖默认值
  • OrderByParser提取OrderBySqlParser接口,增加 orderBySqlParser 参数,可以覆盖默认实现
  • OrderByParser静态方法改为普通方法,为后续改接口做准备
  • jdk8+后不再需要JSqlParser接口,移除该接口,文档标记该参数(该参数早期用于支持sqlserver特殊配置
    兼容jsqlparser4.7版本 Rui 2023/12/3 15:15
  • maven-compiler-plugin固定版本以去除警告,并增加构建稳定性 qxo
  • gitignore .vscode for vscode ide qxo
  • 修改bug #779 chenyuehui

为了兼容 jsqlparser 4.5 和 4.7,以及后续可能存在的其他版本,新建了一个 pagehelper-sqlparser 项目,目前提供了 4.5 和 4.7 两个实现,
使用时从 pagehelper 排除 jsqlparser,然后选择一个 jsqlparser 实现即可,当前版本默认使用的 4.7 版本的代码,
因此如果想换 4.5 的实现,可以按照下面方式进行配置:

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>6.1.0</version>
    <exclusions>
        <exclusion>
            <groupId>com.github.jsqlparser</groupId>
            <artifactId>jsqlparser</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>sqlparser4.5</artifactId>
    <version>6.1.0</version>
</dependency>

SPI 替换默认值的优先级低于 sqlServerSqlParser,orderBySqlParser,countSqlParser 参数指定的实现,不指定时如果存在SPI实现,即可生效,
SPI 可以参考 pagehelper-sqlsource 模块代码。

JSqlParser 默认解析 SQL 会使用临时创建的 Executors.newSingleThreadExecutor(),这里通过 API 跳过了线程池:

CCJSqlParser parser = CCJSqlParserUtil.newParser(statementReader);
parser.withSquareBracketQuotation(true);
return parser.Statement();

JSqlParser 使用线程池的目的是为了防止解析超时,因此如果你遇到过超时的情况,可以引入下面的依赖(通过SPI覆盖了默认实现,超时时间10秒):

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>sqlparser-timeout</artifactId>
    <version>6.1.0</version>
</dependency>

  • Released version 6.1.0, PageHelper provides direct dependency on jsqlparser as intermediate interfaces, allowing default implementation replacement through SPI.
  • Upgraded jsqlparser version to 4.7, re-implemented order by, pagination, and count queries.
  • Simplified pom.xml configuration, removed shade-embedded jsqlparser approach, and switched to selecting different jsqlparser versions through external dependencies, allowing self-SPI extension.
  • jsqlparser parsing no longer uses a thread pool, supporting SPI extension to override SqlParser implementation.
  • Changed SqlServer pagination to SqlServerSqlParser interface, added parameter sqlServerSqlParser to override the default value.
  • Extracted OrderByParser to OrderBySqlParser interface, added orderBySqlParser parameter to override the default implementation.
  • Changed static methods of OrderByParser to regular methods, preparing for future interface changes.
  • JSqlParser interface is no longer needed after JDK 8+, removed the interface, and marked the parameter in the documentation (This parameter was used in the early stages to support special configuration for SQL Server).
    Compatible with jsqlparser 4.7 version. Rui 2023/12/3 15:15.
  • Fixed maven-compiler-plugin version to remove warnings and improve build stability. qxo
  • Added .vscode to .gitignore for vscode IDE. qxo
  • Fixed bug #779. chenyuehui

To ensure compatibility with jsqlparser 4.5, 4.7, and possible future versions,
a new project called pagehelper-sqlparser has been created.
Currently, it provides two implementations: 4.5 and 4.7.
To use it, exclude jsqlparser from pagehelper and select one jsqlparser implementation.
The current version defaults to using the code from version 4.7.
If you want to switch to the 4.5 implementation, follow the configuration steps below:

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>6.1.0</version>
    <exclusions>
        <exclusion>
            <groupId>com.github.jsqlparser</groupId>
            <artifactId>jsqlparser</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>sqlparser4.5</artifactId>
    <version>6.1.0</version>
</dependency>

The priority of replacing default values with SPI is lower than the implementations specified by the sqlServerSqlParser, orderBySqlParser, and countSqlParser parameters.
If no specific implementation is specified, the SPI implementation will take effect if available.
You can refer to the code in the pagehelper-sqlsource module for SPI implementation examples.

By default, JSqlParser uses a temporarily created Executors.newSingleThreadExecutor() for parsing SQL.
Here, the thread pool is bypassed through the API:

CCJSqlParser parser = CCJSqlParserUtil.newParser(statementReader);
parser.withSquareBracketQuotation(true);
return parser.Statement();

The purpose of using a thread pool in JSqlParser is to prevent parsing timeouts. Therefore, if you have encountered timeout situations,
you can introduce the following dependency (which overrides the default implementation through SPI with a timeout of 10 seconds):

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>sqlparser-timeout</artifactId>
    <version>6.1.0</version>
</dependency>