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 | ↵
|
9 | StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );↵ | | 10 | StringBuffer pagingSelect = new StringBuffer( sql.length()+100 );↵
|
10 | if (hasOffset) {↵ | | 11 | if (hasOffset) {↵
|
11 | pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");↵ | | 12 | pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");↵
|
12 | }↵ | | 13 | }↵
|
13 | else {↵ | | 14 | else {↵
|
14 | pagingSelect.append("select * from ( ");↵ | | 15 | pagingSelect.append("select * from ( ");↵
|
15 | }↵ | | 16 | }↵
|
16 | pagingSelect.append(sql);↵ | | 17 | pagingSelect.append(sql);↵
|
17 | if (hasOffset) {↵ | | 18 | if (hasOffset) {↵
|
18 | pagingSelect.append(" ) row_ ) where rownum_ <= ? and rownum_ > ?");↵ | | 19 | pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");↵
|
19 | }↵ | | 20 | }↵
|
20 | else {↵ | | 21 | else {↵
|
21 | pagingSelect.append(" ) where rownum <= ?");↵ | | 22 | pagingSelect.append(" ) where rownum <= ?");↵
|
22 | }↵ | | 23 | }↵
|
|
23 | if ( isForUpdate ) {↵ | | 24 | if ( isForUpdate ) {↵
|
24 | pagingSelect.append( " for update" );↵ | | 25 | pagingSelect.append( " for update" );↵
|
25 | }↵ | | 26 | }↵
|
| | | 27 | ↵
|
26 | return pagingSelect.toString();↵ | | 28 | return pagingSelect.toString();↵
|
27 | | | 29 |
|