1 | public String getLimitString(String sql, boolean hasOffset) {↵ | | 1 | public String getLimitString(String sql, boolean hasOffset) {↵
|
2 | ↵ | | 2 | ↵
|
3 | sql = sql.trim();↵ | | 3 | sql = sql.trim();↵
|
4 | boolean isForUpdate = false;↵ | | 4 | boolean isForUpdate = false;↵
|
5 | if ( sql.toLowerCase().endsWith(" for update") ) {↵ | | 5 | if ( sql.toLowerCase().endsWith(" for update") ) {↵
|
6 | sql = sql.substring( 0, sql.length()-11 );↵ | | 6 | sql = sql.substring( 0, sql.length()-11 );↵
|
7 | isForUpdate = true;↵ | | 7 | isForUpdate = true;↵
|
8 | }↵ | | 8 | }↵
|
9 | ↵ | | |
|
10 | StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );↵ | | 9 | StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );↵
|
11 | if (hasOffset) {↵ | | 10 | if (hasOffset) {↵
|
12 | pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");↵ | | 11 | pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");↵
|
13 | }↵ | | 12 | }↵
|
14 | else {↵ | | 13 | else {↵
|
15 | pagingSelect.append("select * from ( ");↵ | | 14 | pagingSelect.append("select * from ( ");↵
|
16 | }↵ | | 15 | }↵
|
17 | pagingSelect.append(sql);↵ | | 16 | pagingSelect.append(sql);↵
|
18 | if (hasOffset) {↵ | | 17 | if (hasOffset) {↵
|
19 | pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");↵ | | 18 | pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");↵
|
20 | }↵ | | 19 | }↵
|
21 | else {↵ | | 20 | else {↵
|
22 | pagingSelect.append(" ) where rownum <= ?");↵ | | 21 | pagingSelect.append(" ) where rownum <= ?");↵
|
23 | }↵ | | 22 | }↵
|
|
24 | if ( isForUpdate ) {↵ | | 23 | if ( isForUpdate ) {↵
|
25 | pagingSelect.append( " for update" );↵ | | 24 | pagingSelect.append( " for update" );↵
|
26 | }↵ | | 25 | }↵
|
27 | ↵ | | |
|
28 | return pagingSelect.toString();↵ | | 26 | return pagingSelect.toString();↵
|
29 | | | 27 |
|