0e36a56e75ea2b12c74d7877370c338c91a454b3.svn-base
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.common.persistence.dialect.db;
import com.thinkgem.jeesite.common.persistence.dialect.Dialect;
/**
* A dialect compatible with the H2 database.
*
* @author poplar.yfyang
* @version 1.0 2010-10-10 下午12:31
* @since JDK 1.5
*/
public class H2Dialect implements Dialect {
public boolean supportsLimit() {
return true;
}
/**
* 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换.
* <pre>
* 如mysql
* dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
* select * from user limit :offset,:limit
* </pre>
*
* @param sql 实际SQL语句
* @param offset 分页开始纪录条数
* @param offsetPlaceholder 分页开始纪录条数-占位符号
* @param limit 分页每页显示纪录条数
* @param limitPlaceholder 分页纪录条数占位符号
* @return 包含占位符的分页sql
*/
private String getLimitString(String sql, int offset, String offsetPlaceholder, int limit, String limitPlaceholder) {
return sql + ((offset > 0) ? " limit " + limitPlaceholder + " offset "
+ offsetPlaceholder : " limit " + limitPlaceholder);
}
@Override
public String getLimitString(String sql, int offset, int limit) {
return getLimitString(sql, offset, Integer.toString(offset), limit, Integer.toString(limit));
}
}