IDEMPIERE-3586 Add pagination to Query / implement in generic way - info window now can paginate also in oracle

This commit is contained in:
Carlos Ruiz 2018-01-19 12:06:46 +01:00
parent 4aa248e82b
commit e4c872275b
2 changed files with 22 additions and 28 deletions

View File

@ -89,9 +89,9 @@ public class Query
private int pageSize;
/**
* Number of pages will be skiped on query run.
* Number of pages will be skipped on query run.
*/
private int skip;
private int pagesToSkip;
/**
*
@ -794,14 +794,14 @@ public class Query
* @param pPageSize
* Limit current query rows return.
*
* @param pSkip
* Number of pages will be skiped on query run. ZERO to first page
* @param pPagesToSkip
* Number of pages will be skipped on query run. ZERO for first page
*
* @return current Query
*/
public Query setPage(int pPageSize, int pSkip) {
public Query setPage(int pPageSize, int pPagesToSkip) {
this.pageSize = pPageSize;
this.skip = pSkip;
this.pagesToSkip = pPagesToSkip;
return this;
}
@ -820,25 +820,11 @@ public class Query
String query = pQuery;
if (pageSize > 0) {
StringBuilder sql = new StringBuilder();
if (DB.isOracle()) {
sql.append("select * from (");
sql.append(" select ROWNUM pRow, tb.* from (");
sql.append(query);
sql.append(") tb) where pRow > ");
sql.append(pageSize * skip);
sql.append(" AND pRow <= ");
sql.append(((pageSize * skip) + pageSize));
return sql.toString();
}
else {
query = query.concat(" FETCH FIRST " + pageSize + " ROWS ONLY OFFSET " + (pageSize * skip));
}
if (DB.getDatabase().isPagingSupported()) {
query = DB.getDatabase().addPagingSQL(query, (pageSize*pagesToSkip) + 1, pageSize * (pagesToSkip+1));
} else {
throw new IllegalArgumentException("Pagination not supported by database");
}
}
return query;

View File

@ -1287,12 +1287,20 @@ public class DB_Oracle implements AdempiereDatabase
}
public String addPagingSQL(String sql, int start, int end) {
//not supported, too many corner case that doesn't work using rownum. to investigate later
return sql;
StringBuilder newSql = new StringBuilder("select * from (")
.append(" select tb.*, ROWNUM oracle_native_rownum_ from (")
.append(sql)
.append(") tb) where oracle_native_rownum_ >= ")
.append(start)
.append(" AND oracle_native_rownum_ <= ")
.append(end)
.append(" order by oracle_native_rownum_");
return newSql.toString();
}
public boolean isPagingSupported() {
return false;
return true;
}
private int getIntProperty(Properties properties, String key, int defaultValue)