DB2Dialect.java |
1 /** 2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or modify it under 5 * the terms of the GNU Lesser General Public License as published by the Free 6 * Software Foundation; either version 2.1 of the License, or (at your option) 7 * any later version. 8 * 9 * This library is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 12 * details. 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 }