IDEMPIERE-3586 Add pagination to Query / implement in generic way - info window now can paginate also in oracle
This commit is contained in:
parent
4aa248e82b
commit
e4c872275b
|
@ -89,9 +89,9 @@ public class Query
|
||||||
private int pageSize;
|
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
|
* @param pPageSize
|
||||||
* Limit current query rows return.
|
* Limit current query rows return.
|
||||||
*
|
*
|
||||||
* @param pSkip
|
* @param pPagesToSkip
|
||||||
* Number of pages will be skiped on query run. ZERO to first page
|
* Number of pages will be skipped on query run. ZERO for first page
|
||||||
*
|
*
|
||||||
* @return current Query
|
* @return current Query
|
||||||
*/
|
*/
|
||||||
public Query setPage(int pPageSize, int pSkip) {
|
public Query setPage(int pPageSize, int pPagesToSkip) {
|
||||||
this.pageSize = pPageSize;
|
this.pageSize = pPageSize;
|
||||||
this.skip = pSkip;
|
this.pagesToSkip = pPagesToSkip;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -820,25 +820,11 @@ public class Query
|
||||||
String query = pQuery;
|
String query = pQuery;
|
||||||
|
|
||||||
if (pageSize > 0) {
|
if (pageSize > 0) {
|
||||||
|
if (DB.getDatabase().isPagingSupported()) {
|
||||||
StringBuilder sql = new StringBuilder();
|
query = DB.getDatabase().addPagingSQL(query, (pageSize*pagesToSkip) + 1, pageSize * (pagesToSkip+1));
|
||||||
|
} else {
|
||||||
if (DB.isOracle()) {
|
throw new IllegalArgumentException("Pagination not supported by database");
|
||||||
|
}
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
|
|
|
@ -1287,12 +1287,20 @@ public class DB_Oracle implements AdempiereDatabase
|
||||||
}
|
}
|
||||||
|
|
||||||
public String addPagingSQL(String sql, int start, int end) {
|
public String addPagingSQL(String sql, int start, int end) {
|
||||||
//not supported, too many corner case that doesn't work using rownum. to investigate later
|
StringBuilder newSql = new StringBuilder("select * from (")
|
||||||
return sql;
|
.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() {
|
public boolean isPagingSupported() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getIntProperty(Properties properties, String key, int defaultValue)
|
private int getIntProperty(Properties properties, String key, int defaultValue)
|
||||||
|
|
Loading…
Reference in New Issue