Skip to content

Commit 9bf2e91

Browse files
committed
4.1.4版本
1 parent fdf51d2 commit 9bf2e91

8 files changed

Lines changed: 75 additions & 41 deletions

File tree

‎README.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636

3737
##分页插件支持MyBatis3.2.0~3.3.0(包含)
3838

39-
##分页插件最新版本为4.1.3
39+
##分页插件最新版本为4.1.4
4040

4141
###Maven坐标
4242

4343
```xml
4444
<dependency>
4545
<groupId>com.github.pagehelper</groupId>
4646
<artifactId>pagehelper</artifactId>
47-
<version>4.1.3</version>
47+
<version>4.1.4</version>
4848
</dependency>
4949
```
5050

@@ -66,6 +66,12 @@
6666

6767
- http://repo1.maven.org/maven2/com/github/jsqlparser/jsqlparser/0.9.1/
6868

69+
##4.1.4更新日志
70+
71+
- 解决`closeConn`未设置时,默认值被覆盖变成`false`的问题#97
72+
- `closeConn`不只对动态数据源有效,当没有设置`dialect`属性自动获取数据库类型的时候同样有效
73+
- 解决关闭tomcat的时候提示线程安全问题#98,这个问题不会导致内存溢出,已经增加处理
74+
6975
##4.1.3更新日志
7076

7177
- 解决反射类没有完全捕获异常的问题#94

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<groupId>com.github.pagehelper</groupId>
3030
<artifactId>pagehelper</artifactId>
31-
<version>4.1.3</version>
31+
<version>4.1.4</version>
3232
<packaging>jar</packaging>
3333

3434
<name>pagehelper</name>
@@ -63,7 +63,7 @@
6363
<dependency>
6464
<groupId>com.github.jsqlparser</groupId>
6565
<artifactId>jsqlparser</artifactId>
66-
<version>0.9.4</version>
66+
<version>0.9.5</version>
6767
</dependency>
6868
<dependency>
6969
<groupId>org.mybatis</groupId>

‎src/main/java/com/github/pagehelper/PageHelper.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,10 @@ public void setProperties(Properties p) {
368368
checkVersion();
369369
//多数据源时,获取jdbcurl后是否关闭数据源
370370
String closeConn = p.getProperty("closeConn");
371-
this.closeConn = Boolean.parseBoolean(closeConn);
371+
//解决#97
372+
if(StringUtil.isNotEmpty(closeConn)){
373+
this.closeConn = Boolean.parseBoolean(closeConn);
374+
}
372375
//数据库方言
373376
String dialect = p.getProperty("dialect");
374377
String runtimeDialect = p.getProperty("autoRuntimeDialect");

‎src/main/java/com/github/pagehelper/SqlUtil.java‎

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -461,44 +461,49 @@ private Page doProcessPage(Invocation invocation, Page page, Object[] args) thro
461461
}
462462
//设置当前的parser,后面每次使用前都会set,ThreadLocal的值不会产生不良影响
463463
((PageSqlSource)ms.getSqlSource()).setParser(parser);
464-
//忽略RowBounds-否则会进行Mybatis自带的内存分页
465-
args[2] = RowBounds.DEFAULT;
466-
//如果只进行排序 或 pageSizeZero的判断
467-
if (isQueryOnly(page)) {
468-
return doQueryOnly(page, invocation);
469-
}
464+
try {
465+
//忽略RowBounds-否则会进行Mybatis自带的内存分页
466+
args[2] = RowBounds.DEFAULT;
467+
//如果只进行排序 或 pageSizeZero的判断
468+
if (isQueryOnly(page)) {
469+
return doQueryOnly(page, invocation);
470+
}
470471

471-
//简单的通过total的值来判断是否进行count查询
472-
if (page.isCount()) {
473-
page.setCountSignal(Boolean.TRUE);
474-
//替换MS
475-
args[0] = msCountMap.get(ms.getId());
476-
//查询总数
477-
Object result = invocation.proceed();
478-
//还原ms
479-
args[0] = ms;
480-
//设置总数
481-
page.setTotal((Integer) ((List) result).get(0));
482-
if (page.getTotal() == 0) {
483-
return page;
472+
//简单的通过total的值来判断是否进行count查询
473+
if (page.isCount()) {
474+
page.setCountSignal(Boolean.TRUE);
475+
//替换MS
476+
args[0] = msCountMap.get(ms.getId());
477+
//查询总数
478+
Object result = invocation.proceed();
479+
//还原ms
480+
args[0] = ms;
481+
//设置总数
482+
page.setTotal((Integer) ((List) result).get(0));
483+
if (page.getTotal() == 0) {
484+
return page;
485+
}
486+
} else {
487+
page.setTotal(-1l);
484488
}
485-
} else {
486-
page.setTotal(-1l);
487-
}
488-
//pageSize>0的时候执行分页查询,pageSize<=0的时候不执行相当于可能只返回了一个count
489-
if (page.getPageSize() > 0 &&
490-
((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0)
491-
|| rowBounds != RowBounds.DEFAULT)) {
492-
//将参数中的MappedStatement替换为新的qs
493-
page.setCountSignal(null);
494-
BoundSql boundSql = ms.getBoundSql(args[1]);
495-
args[1] = parser.setPageParameter(ms, args[1], boundSql, page);
496-
page.setCountSignal(Boolean.FALSE);
497-
//执行分页查询
498-
Object result = invocation.proceed();
499-
//得到处理结果
500-
page.addAll((List) result);
489+
//pageSize>0的时候执行分页查询,pageSize<=0的时候不执行相当于可能只返回了一个count
490+
if (page.getPageSize() > 0 &&
491+
((rowBounds == RowBounds.DEFAULT && page.getPageNum() > 0)
492+
|| rowBounds != RowBounds.DEFAULT)) {
493+
//将参数中的MappedStatement替换为新的qs
494+
page.setCountSignal(null);
495+
BoundSql boundSql = ms.getBoundSql(args[1]);
496+
args[1] = parser.setPageParameter(ms, args[1], boundSql, page);
497+
page.setCountSignal(Boolean.FALSE);
498+
//执行分页查询
499+
Object result = invocation.proceed();
500+
//得到处理结果
501+
page.addAll((List) result);
502+
}
503+
} finally {
504+
((PageSqlSource)ms.getSqlSource()).removeParser();
501505
}
506+
502507
//返回结果
503508
return page;
504509
}

‎src/main/java/com/github/pagehelper/sqlsource/PageSqlSource.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public void setParser(Parser parser) {
1919
localParser.set(parser);
2020
}
2121

22+
public void removeParser(){
23+
localParser.remove();
24+
}
25+
2226
/**
2327
* 返回值null - 普通,true - count,false - page
2428
*

‎src/test/java/com/github/pagehelper/sql/SqlServerTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.github.pagehelper.parser.SqlServer;
2828
import net.sf.jsqlparser.JSQLParserException;
29+
import org.junit.Ignore;
2930
import org.junit.Test;
3031

3132
/**
@@ -34,6 +35,13 @@
3435
public class SqlServerTest {
3536
public static final SqlServer sqlServer = new SqlServer();
3637

38+
@Test
39+
@Ignore("暂时不支持")
40+
public void testSqlTestWithlock() throws JSQLParserException {
41+
String originalSql = "select * from Agency with (NOLOCK) where status=0 order by CreateTime";
42+
System.out.println(sqlServer.convertToPageSql(originalSql, 1, 10));
43+
}
44+
3745
@Test
3846
public void testSqlTest() throws JSQLParserException {
3947
String originalSql = "Select * from country o where id > 10 order by id desc , countryname asc";

‎wikis/Changelog.markdown‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
##更新日志
22

3-
##4.1.3 - 2016-03-31
3+
##4.1.4 - 2016-05-12
4+
5+
- 解决`closeConn`未设置时,默认值被覆盖变成`false`的问题#97
6+
- `closeConn`不只对动态数据源有效,当没有设置`dialect`属性自动获取数据库类型的时候同样有效
7+
- 解决关闭tomcat的时候提示线程安全问题#98,这个问题不会导致内存溢出,已经增加处理
8+
9+
###4.1.3 - 2016-03-31
410

511
- 解决反射类没有完全捕获异常的问题#94
612
- 把SqlServer类所有private都改成了protected,方便继承修改#93

‎wikis/HowToUse.markdown‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111

112112
8. `returnPageInfo`用来支持直接返回`PageInfo`类型,默认值`none`,可选参数always总是返回PageInfo类型,check检查返回类型是否为PageInfo,none返回Page(List)类型。用法和配置参考`com.github.pagehelper.test.basic`包下的`PageInfoTest`,特别要注意接口的返回值和xml中的`resultType`类型。
113113

114+
9. 增加`closeConn`属性,当使用动态数据源或没有设置`dialect`属性自动获取数据库类型时,会自动获取一个数据库连接,通过该属性来设置是否关闭获取的这个连接,默认`true`关闭。
115+
114116
<b>重要提示:</b>
115117

116118
当`offsetAsPageNum=false`的时候,由于PageNum问题,`RowBounds`查询的时候reasonable会强制为false。使用`PageHelper.startPage`方法不受影响。

0 commit comments

Comments
 (0)