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