001package io.ebean.config.dbplatform; 002 003/** 004 * Adds LIMIT OFFSET clauses to a SQL query. 005 */ 006public class BasicSqlLimitOffset implements BasicSqlLimiter { 007 008 /** 009 * LIMIT keyword. 010 */ 011 private static final String LIMIT = "limit"; 012 013 /** 014 * OFFSET keyword. 015 */ 016 private static final String OFFSET = "offset"; 017 018 @Override 019 public String limit(String dbSql, int firstRow, int maxRows) { 020 021 StringBuilder sb = new StringBuilder(50 + dbSql.length()); 022 023 sb.append(dbSql); 024 025 if (maxRows > 0) { 026 sb.append(" ").append(LIMIT); 027 sb.append(" ").append(maxRows); 028 } 029 if (firstRow > 0) { 030 sb.append(" ").append(OFFSET).append(" "); 031 sb.append(firstRow); 032 } 033 return sb.toString(); 034 } 035 036}