1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.dao.orm.hibernate;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  
19  /**
20   * <a href="DB2Dialect.java.html"><b><i>View Source</i></b></a>
21   *
22   * @author Shepherd Ching
23   * @author Jian Cao
24   */
25  public class DB2Dialect extends org.hibernate.dialect.DB2Dialect {
26  
27      public String getLimitString(String sql, boolean hasOffset) {
28          if (!sql.startsWith("(")) {
29              return super.getLimitString(sql, hasOffset);
30          }
31  
32          StringBundler sb = new StringBundler(5);
33  
34          sb.append("select cursor1.* from (");
35          sb.append("select rownumber() over() as rownumber_, cursor2.* from (");
36          sb.append(sql);
37          sb.append(") as cursor2) as cursor1 where rownumber_");
38  
39          if (hasOffset) {
40              sb.append(" between ? + 1 and ?");
41          }
42          else {
43              sb.append(" <= ?");
44          }
45  
46          return sb.toString();
47      }
48  
49  }