package com.ejie.m62fb.util;

import com.ejie.x38.dto.Pagination;

public class UdaUtils {
	public static String getQueryLimits(Pagination pagination, String query)
	{
	  String queryAux = "";
	  if ((pagination.getPage() != null) && (pagination.getRows() != null)) {
	     Long paginationRows = pagination.getRows();
	     queryAux = "SELECT * FROM (SELECT rownum rnum, a.*  FROM (" + query + ")a) where rnum > " + (paginationRows.longValue() * (pagination.getPage().longValue() - 1L)) + " and rnum < " + (paginationRows.longValue() * pagination.getPage().longValue() + 1L);
	     return queryAux; }
	   if (pagination.getRows() != null) {
	     Long paginationRows = pagination.getRows();
	     queryAux = "SELECT * FROM (SELECT rownum rnum, a.*  FROM (" + query + ")a) where rnum > 0 and rnum < " + (paginationRows.longValue() + 1L);
	     return queryAux;
	   }
	   return query;
	 }
}
