001package io.ebean.config.dbplatform.db2;
002
003import io.ebean.config.dbplatform.SqlLimitRequest;
004import io.ebean.config.dbplatform.SqlLimitResponse;
005import io.ebean.config.dbplatform.SqlLimiter;
006
007public class Db2SqlLimiter implements SqlLimiter {
008
009  @Override
010  public SqlLimitResponse limit(SqlLimitRequest request) {
011
012    StringBuilder sb = new StringBuilder(512);
013    sb.append("select ");
014    if (request.isDistinct()) {
015      sb.append("distinct ");
016    }
017    sb.append(request.getDbSql());
018
019    int maxRows = request.getMaxRows();
020    if (maxRows > 0) {
021      sb.append(" ").append(NEW_LINE).append("FETCH FIRST ").append(maxRows).append(" ROWS ONLY");
022    }
023
024    String sql = request.getDbPlatform().completeSql(sb.toString(), request.getOrmQuery());
025    return new SqlLimitResponse(sql);
026  }
027}