protected static String applyLimitClause(final String query,int limit,final int queryResultSetLimit){
  Matcher matcher=SELECT_EXPR_PATTERN.matcher(query);
  if (matcher.matches()) {
    Matcher limit_matcher=SELECT_WITH_LIMIT_EXPR_PATTERN.matcher(query);
    boolean queryAlreadyHasLimitClause=limit_matcher.matches();
    if (!queryAlreadyHasLimitClause) {
      if (limit == 0) {
        limit=queryResultSetLimit;
      }
      String result=query;
      result+=" LIMIT " + limit;
      return result;
    }
  }
  return query;
}

protected static String applyLimitClause ( final String query , int limit , final int queryResultSetLimit ) { Matcher matcher = SELECT_EXPR_PATTERN . matcher ( query ) ; if ( matcher . matches ( ) ) { Matcher limit_matcher = SELECT_WITH_LIMIT_EXPR_PATTERN . matcher ( query ) ; boolean queryAlreadyHasLimitClause = limit_matcher . matches ( ) ; if ( ! queryAlreadyHasLimitClause ) { if ( limit == 0 ) { limit = queryResultSetLimit ; } String result = query ; result += " LIMIT " + limit ; return result ; } } return query ; }
matches the input query with query with limit pattern . if limit is found in input query this function ignores . else it will append a default limit . . 1000 if input limit is 0 then also it will append default limit of 1000
