001package io.ebean.config.dbplatform.hana;
002
003import io.ebean.config.dbplatform.SqlLimitRequest;
004import io.ebean.config.dbplatform.SqlLimitResponse;
005import io.ebean.config.dbplatform.SqlLimiter;
006
007public class HanaSqlLimiter implements SqlLimiter {
008  @Override
009  public SqlLimitResponse limit(SqlLimitRequest request) {
010    String dbSql = request.getDbSql();
011
012    StringBuilder sb = new StringBuilder(50 + dbSql.length());
013    sb.append("select ");
014    if (request.isDistinct()) {
015      sb.append("distinct ");
016    }
017
018    sb.append(dbSql);
019
020    int firstRow = request.getFirstRow();
021    int maxRows = request.getMaxRows();
022
023    if (maxRows > 0) {
024      sb.append(" ").append("limit ").append(maxRows);
025      if (firstRow > 0) {
026        sb.append(" ").append("offset ");
027        sb.append(firstRow);
028      }
029    }
030
031    String sql = request.getDbPlatform().completeSql(sb.toString(), request.getOrmQuery());
032    return new SqlLimitResponse(sql);
033  }
034}