mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
125783 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127809 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,130 +1,130 @@
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
|
||||
/**
|
||||
* Cursor - Allows for scrolling through a row set.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public interface Cursor
|
||||
{
|
||||
/**
|
||||
* Gets the page type
|
||||
*
|
||||
* @return page type
|
||||
*/
|
||||
public String getPageType();
|
||||
|
||||
/**
|
||||
* Gets the page size
|
||||
*
|
||||
* @return page size
|
||||
*/
|
||||
int getPageSize();
|
||||
|
||||
/**
|
||||
* Gets total number of pages
|
||||
*
|
||||
* @return total number of pages
|
||||
*/
|
||||
int getTotalPages();
|
||||
|
||||
/**
|
||||
* Gets total rows
|
||||
*
|
||||
* @return total rows
|
||||
*/
|
||||
int getTotalRows();
|
||||
|
||||
/**
|
||||
* Gets the current page number
|
||||
*
|
||||
* @return current page number
|
||||
*/
|
||||
int getCurrentPage();
|
||||
|
||||
/**
|
||||
* Gets the first page number
|
||||
*
|
||||
* @return first page number
|
||||
*/
|
||||
int getFirstPage();
|
||||
|
||||
/**
|
||||
* Gets the last page number
|
||||
*
|
||||
* @return last page number
|
||||
*/
|
||||
int getLastPage();
|
||||
|
||||
/**
|
||||
* Gets the next page number
|
||||
*
|
||||
* @return next page number (-1 if no more pages)
|
||||
*/
|
||||
int getNextPage();
|
||||
|
||||
/**
|
||||
* Gets the previous page number
|
||||
*
|
||||
* @return previous page number (-1 if no previous pages)
|
||||
*/
|
||||
int getPrevPage();
|
||||
|
||||
/**
|
||||
* Is the page within range of the result set
|
||||
*
|
||||
* @return true => page is within range
|
||||
*/
|
||||
boolean isInRange();
|
||||
|
||||
/**
|
||||
* Is there a known first page?
|
||||
*
|
||||
* @return true => getFirstPage() will succeed
|
||||
*/
|
||||
boolean getHasFirstPage();
|
||||
|
||||
/**
|
||||
* Is there a known last page?
|
||||
*
|
||||
* @return true => getLastPage() will succeed
|
||||
*/
|
||||
boolean getHasLastPage();
|
||||
|
||||
/**
|
||||
* Is there a known next page?
|
||||
*
|
||||
* @return true => getNextPage() will succeed
|
||||
*/
|
||||
boolean getHasNextPage();
|
||||
|
||||
/**
|
||||
* Is there a known prev page?
|
||||
*
|
||||
* @return true => getPrevPage() will succeed
|
||||
*/
|
||||
boolean getHasPrevPage();
|
||||
|
||||
/**
|
||||
* Gets the start row within result set for this page
|
||||
*
|
||||
* @return start row index
|
||||
*/
|
||||
int getStartRow();
|
||||
|
||||
/**
|
||||
* Gets the end row within result set for this page
|
||||
*
|
||||
* @return end row index
|
||||
*/
|
||||
int getEndRow();
|
||||
|
||||
/**
|
||||
* Gets the count of rows within result set for this page
|
||||
*
|
||||
* @return row count
|
||||
*/
|
||||
int getRowCount();
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
|
||||
/**
|
||||
* Cursor - Allows for scrolling through a row set.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public interface Cursor
|
||||
{
|
||||
/**
|
||||
* Gets the page type
|
||||
*
|
||||
* @return page type
|
||||
*/
|
||||
public String getPageType();
|
||||
|
||||
/**
|
||||
* Gets the page size
|
||||
*
|
||||
* @return page size
|
||||
*/
|
||||
int getPageSize();
|
||||
|
||||
/**
|
||||
* Gets total number of pages
|
||||
*
|
||||
* @return total number of pages
|
||||
*/
|
||||
int getTotalPages();
|
||||
|
||||
/**
|
||||
* Gets total rows
|
||||
*
|
||||
* @return total rows
|
||||
*/
|
||||
int getTotalRows();
|
||||
|
||||
/**
|
||||
* Gets the current page number
|
||||
*
|
||||
* @return current page number
|
||||
*/
|
||||
int getCurrentPage();
|
||||
|
||||
/**
|
||||
* Gets the first page number
|
||||
*
|
||||
* @return first page number
|
||||
*/
|
||||
int getFirstPage();
|
||||
|
||||
/**
|
||||
* Gets the last page number
|
||||
*
|
||||
* @return last page number
|
||||
*/
|
||||
int getLastPage();
|
||||
|
||||
/**
|
||||
* Gets the next page number
|
||||
*
|
||||
* @return next page number (-1 if no more pages)
|
||||
*/
|
||||
int getNextPage();
|
||||
|
||||
/**
|
||||
* Gets the previous page number
|
||||
*
|
||||
* @return previous page number (-1 if no previous pages)
|
||||
*/
|
||||
int getPrevPage();
|
||||
|
||||
/**
|
||||
* Is the page within range of the result set
|
||||
*
|
||||
* @return true => page is within range
|
||||
*/
|
||||
boolean isInRange();
|
||||
|
||||
/**
|
||||
* Is there a known first page?
|
||||
*
|
||||
* @return true => getFirstPage() will succeed
|
||||
*/
|
||||
boolean getHasFirstPage();
|
||||
|
||||
/**
|
||||
* Is there a known last page?
|
||||
*
|
||||
* @return true => getLastPage() will succeed
|
||||
*/
|
||||
boolean getHasLastPage();
|
||||
|
||||
/**
|
||||
* Is there a known next page?
|
||||
*
|
||||
* @return true => getNextPage() will succeed
|
||||
*/
|
||||
boolean getHasNextPage();
|
||||
|
||||
/**
|
||||
* Is there a known prev page?
|
||||
*
|
||||
* @return true => getPrevPage() will succeed
|
||||
*/
|
||||
boolean getHasPrevPage();
|
||||
|
||||
/**
|
||||
* Gets the start row within result set for this page
|
||||
*
|
||||
* @return start row index
|
||||
*/
|
||||
int getStartRow();
|
||||
|
||||
/**
|
||||
* Gets the end row within result set for this page
|
||||
*
|
||||
* @return end row index
|
||||
*/
|
||||
int getEndRow();
|
||||
|
||||
/**
|
||||
* Gets the count of rows within result set for this page
|
||||
*
|
||||
* @return row count
|
||||
*/
|
||||
int getRowCount();
|
||||
|
||||
}
|
||||
|
@@ -1,72 +1,72 @@
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
|
||||
/**
|
||||
* A Page within a Cursor.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class Page
|
||||
{
|
||||
Paging.PageType pageType;
|
||||
boolean zeroBasedIdx;
|
||||
int startIdx;
|
||||
int pageSize;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param pageType Page or Window
|
||||
* @param zeroBasedIdx true => start index from 0
|
||||
* @param startIdx start index
|
||||
* @param pageSize page size
|
||||
*/
|
||||
/*package*/ Page(Paging.PageType pageType, boolean zeroBasedIdx, int startIdx, int pageSize)
|
||||
{
|
||||
this.pageType = pageType;
|
||||
this.zeroBasedIdx = zeroBasedIdx;
|
||||
this.startIdx = startIdx;
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Page Type
|
||||
*
|
||||
* @return page type
|
||||
*/
|
||||
/*package*/ Paging.PageType getType()
|
||||
{
|
||||
return pageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page number
|
||||
*
|
||||
* @return page number
|
||||
*/
|
||||
public int getNumber()
|
||||
{
|
||||
return startIdx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page size
|
||||
*
|
||||
* @return page size
|
||||
*/
|
||||
public int getSize()
|
||||
{
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is zero based page index
|
||||
*
|
||||
* @return true => page number starts from zero
|
||||
*/
|
||||
public boolean isZeroBasedIdx()
|
||||
{
|
||||
return zeroBasedIdx;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
|
||||
/**
|
||||
* A Page within a Cursor.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class Page
|
||||
{
|
||||
Paging.PageType pageType;
|
||||
boolean zeroBasedIdx;
|
||||
int startIdx;
|
||||
int pageSize;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param pageType Page or Window
|
||||
* @param zeroBasedIdx true => start index from 0
|
||||
* @param startIdx start index
|
||||
* @param pageSize page size
|
||||
*/
|
||||
/*package*/ Page(Paging.PageType pageType, boolean zeroBasedIdx, int startIdx, int pageSize)
|
||||
{
|
||||
this.pageType = pageType;
|
||||
this.zeroBasedIdx = zeroBasedIdx;
|
||||
this.startIdx = startIdx;
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Page Type
|
||||
*
|
||||
* @return page type
|
||||
*/
|
||||
/*package*/ Paging.PageType getType()
|
||||
{
|
||||
return pageType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page number
|
||||
*
|
||||
* @return page number
|
||||
*/
|
||||
public int getNumber()
|
||||
{
|
||||
return startIdx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the page size
|
||||
*
|
||||
* @return page size
|
||||
*/
|
||||
public int getSize()
|
||||
{
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is zero based page index
|
||||
*
|
||||
* @return true => page number starts from zero
|
||||
*/
|
||||
public boolean isZeroBasedIdx()
|
||||
{
|
||||
return zeroBasedIdx;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,200 +1,200 @@
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.repo.web.util.paging.Paging.PageType;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of cursor based on notion of a Page.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class PagedCursor implements Cursor, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -1041155610387669590L;
|
||||
|
||||
private boolean zeroBasedPage;
|
||||
private boolean zeroBasedRow;
|
||||
private int totalRows;
|
||||
private int pageSize;
|
||||
private int rowsPerPage;
|
||||
private int page;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param zeroBasedRow true => row index starts at zero
|
||||
* @param totalRows total number of rows (-1 for don't know)
|
||||
* @param zeroBasedPage true => page number starts at zero
|
||||
* @param page page number
|
||||
* @param pageSize page size
|
||||
*/
|
||||
/*package*/ PagedCursor(boolean zeroBasedRow, int totalRows, boolean zeroBasedPage, int page, int pageSize)
|
||||
{
|
||||
this.zeroBasedRow = zeroBasedRow;
|
||||
this.totalRows = totalRows;
|
||||
this.zeroBasedPage = zeroBasedPage;
|
||||
this.page = (zeroBasedPage) ? page : page - 1;
|
||||
this.pageSize = pageSize;
|
||||
this.rowsPerPage = (pageSize <=0) ? totalRows : pageSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageType()
|
||||
*/
|
||||
public String getPageType()
|
||||
{
|
||||
return PageType.PAGE.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageSize()
|
||||
*/
|
||||
public int getPageSize()
|
||||
{
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalPages()
|
||||
*/
|
||||
public int getTotalPages()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
int totalPages = (int)(totalRows / rowsPerPage);
|
||||
totalPages += (totalRows % rowsPerPage != 0) ? 1 : 0;
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalRows()
|
||||
*/
|
||||
public int getTotalRows()
|
||||
{
|
||||
return totalRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getCurrentPage()
|
||||
*/
|
||||
public int getCurrentPage()
|
||||
{
|
||||
return page + (zeroBasedPage ? 0 : 1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getFirstPage()
|
||||
*/
|
||||
public int getFirstPage()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return zeroBasedPage ? 0 : 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getLastPage()
|
||||
*/
|
||||
public int getLastPage()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return getTotalPages() - (zeroBasedPage ? 1 : 0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getNextPage()
|
||||
*/
|
||||
public int getNextPage()
|
||||
{
|
||||
return getCurrentPage() < getLastPage() ? getCurrentPage() + 1 : - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPrevPage()
|
||||
*/
|
||||
public int getPrevPage()
|
||||
{
|
||||
return page > 0 ? getCurrentPage() - 1 : - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#isInRange()
|
||||
*/
|
||||
public boolean isInRange()
|
||||
{
|
||||
return page >= 0 && getCurrentPage() <= getLastPage();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasFirstPage()
|
||||
*/
|
||||
public boolean getHasFirstPage()
|
||||
{
|
||||
return getFirstPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasLastPage()
|
||||
*/
|
||||
public boolean getHasLastPage()
|
||||
{
|
||||
return getLastPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasNextPage()
|
||||
*/
|
||||
public boolean getHasNextPage()
|
||||
{
|
||||
return getNextPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasPrevPage()
|
||||
*/
|
||||
public boolean getHasPrevPage()
|
||||
{
|
||||
return getPrevPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getStartRow()
|
||||
*/
|
||||
public int getStartRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return (page * rowsPerPage) + (zeroBasedRow ? 0 : 1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getEndRow()
|
||||
*/
|
||||
public int getEndRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return getStartRow() + Math.min(rowsPerPage, totalRows - (page * rowsPerPage)) - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getRowCount()
|
||||
*/
|
||||
public int getRowCount()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return getEndRow() - getStartRow() + 1;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.repo.web.util.paging.Paging.PageType;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of cursor based on notion of a Page.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class PagedCursor implements Cursor, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -1041155610387669590L;
|
||||
|
||||
private boolean zeroBasedPage;
|
||||
private boolean zeroBasedRow;
|
||||
private int totalRows;
|
||||
private int pageSize;
|
||||
private int rowsPerPage;
|
||||
private int page;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param zeroBasedRow true => row index starts at zero
|
||||
* @param totalRows total number of rows (-1 for don't know)
|
||||
* @param zeroBasedPage true => page number starts at zero
|
||||
* @param page page number
|
||||
* @param pageSize page size
|
||||
*/
|
||||
/*package*/ PagedCursor(boolean zeroBasedRow, int totalRows, boolean zeroBasedPage, int page, int pageSize)
|
||||
{
|
||||
this.zeroBasedRow = zeroBasedRow;
|
||||
this.totalRows = totalRows;
|
||||
this.zeroBasedPage = zeroBasedPage;
|
||||
this.page = (zeroBasedPage) ? page : page - 1;
|
||||
this.pageSize = pageSize;
|
||||
this.rowsPerPage = (pageSize <=0) ? totalRows : pageSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageType()
|
||||
*/
|
||||
public String getPageType()
|
||||
{
|
||||
return PageType.PAGE.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageSize()
|
||||
*/
|
||||
public int getPageSize()
|
||||
{
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalPages()
|
||||
*/
|
||||
public int getTotalPages()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
int totalPages = (int)(totalRows / rowsPerPage);
|
||||
totalPages += (totalRows % rowsPerPage != 0) ? 1 : 0;
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalRows()
|
||||
*/
|
||||
public int getTotalRows()
|
||||
{
|
||||
return totalRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getCurrentPage()
|
||||
*/
|
||||
public int getCurrentPage()
|
||||
{
|
||||
return page + (zeroBasedPage ? 0 : 1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getFirstPage()
|
||||
*/
|
||||
public int getFirstPage()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return zeroBasedPage ? 0 : 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getLastPage()
|
||||
*/
|
||||
public int getLastPage()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return getTotalPages() - (zeroBasedPage ? 1 : 0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getNextPage()
|
||||
*/
|
||||
public int getNextPage()
|
||||
{
|
||||
return getCurrentPage() < getLastPage() ? getCurrentPage() + 1 : - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPrevPage()
|
||||
*/
|
||||
public int getPrevPage()
|
||||
{
|
||||
return page > 0 ? getCurrentPage() - 1 : - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#isInRange()
|
||||
*/
|
||||
public boolean isInRange()
|
||||
{
|
||||
return page >= 0 && getCurrentPage() <= getLastPage();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasFirstPage()
|
||||
*/
|
||||
public boolean getHasFirstPage()
|
||||
{
|
||||
return getFirstPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasLastPage()
|
||||
*/
|
||||
public boolean getHasLastPage()
|
||||
{
|
||||
return getLastPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasNextPage()
|
||||
*/
|
||||
public boolean getHasNextPage()
|
||||
{
|
||||
return getNextPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasPrevPage()
|
||||
*/
|
||||
public boolean getHasPrevPage()
|
||||
{
|
||||
return getPrevPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getStartRow()
|
||||
*/
|
||||
public int getStartRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return (page * rowsPerPage) + (zeroBasedRow ? 0 : 1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getEndRow()
|
||||
*/
|
||||
public int getEndRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return getStartRow() + Math.min(rowsPerPage, totalRows - (page * rowsPerPage)) - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getRowCount()
|
||||
*/
|
||||
public int getRowCount()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return getEndRow() - getStartRow() + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,83 +1,83 @@
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* A Paged Result Set
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class PagedResults implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 5905699888354619269L;
|
||||
|
||||
private Object result;
|
||||
private Object[] results;
|
||||
private Cursor cursor;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param results results for the page within cursor
|
||||
* @param cursor the cursor
|
||||
*/
|
||||
/*Package*/ PagedResults(Object[] results, Cursor cursor)
|
||||
{
|
||||
this.result = results;
|
||||
this.results = results;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param result results for the page within cursor
|
||||
* @param cursor the cursor
|
||||
*/
|
||||
/*Package*/ PagedResults(Object result, Cursor cursor)
|
||||
{
|
||||
this.result = result;
|
||||
this.results = null;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Results
|
||||
*
|
||||
* @return results
|
||||
*/
|
||||
public Object[] getResults()
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
results = new Object[] {result};
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Result
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
public Object getResult()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Cursor
|
||||
*
|
||||
* @return cursor
|
||||
*/
|
||||
public Cursor getCursor()
|
||||
{
|
||||
return cursor;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* A Paged Result Set
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class PagedResults implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 5905699888354619269L;
|
||||
|
||||
private Object result;
|
||||
private Object[] results;
|
||||
private Cursor cursor;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param results results for the page within cursor
|
||||
* @param cursor the cursor
|
||||
*/
|
||||
/*Package*/ PagedResults(Object[] results, Cursor cursor)
|
||||
{
|
||||
this.result = results;
|
||||
this.results = results;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param result results for the page within cursor
|
||||
* @param cursor the cursor
|
||||
*/
|
||||
/*Package*/ PagedResults(Object result, Cursor cursor)
|
||||
{
|
||||
this.result = result;
|
||||
this.results = null;
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Results
|
||||
*
|
||||
* @return results
|
||||
*/
|
||||
public Object[] getResults()
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
results = new Object[] {result};
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Result
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
public Object getResult()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Cursor
|
||||
*
|
||||
* @return cursor
|
||||
*/
|
||||
public Cursor getCursor()
|
||||
{
|
||||
return cursor;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,286 +1,286 @@
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Paging. A utility for maintaining paged indexes for a collection of N items.
|
||||
*
|
||||
* There are two types of cursor:
|
||||
*
|
||||
* a) Paged
|
||||
*
|
||||
* This type of cursor is driven from a page number and page size. Random access within
|
||||
* the collection is possible by jumping straight to a page. A simple scroll through
|
||||
* the collection is supported by iterating through each next page.
|
||||
*
|
||||
* b) Windowed
|
||||
*
|
||||
* This type of cursor is driven from a skip row count and maximum number of rows. Random
|
||||
* access is not supported. The collection of items is simply scrolled through from
|
||||
* start to end by iterating through each next set of rows.
|
||||
*
|
||||
* In either case, a paging cursor provides a start row and end row which may be used
|
||||
* to extract the items for the page from the collection of N items.
|
||||
*
|
||||
* A zero (or less) page size or row maximum means "unlimited".
|
||||
*
|
||||
* Zero or one based Page and Rows indexes are supported. By default, Pages are 1 based and
|
||||
* Rows are 0 based.
|
||||
*
|
||||
* At any time, -1 is returned to represent "out of range" i.e. for next, previous, last page.
|
||||
*
|
||||
* Pseudo-code for traversing through a collection of N items (10 at a time):
|
||||
*
|
||||
* Paging paging = new Paging();
|
||||
* Cursor page = paging.createCursor(N, paging.createPage(1, 10));
|
||||
* while (page.isInRange())
|
||||
* {
|
||||
* for (long i = page.getStartRow(); i <= page.getEndRow(); i++)
|
||||
* {
|
||||
* ...collection[i]...
|
||||
* }
|
||||
* page = paging.createCursor(N, paging.createPage(page.getNextPage(), page.getPageSize());
|
||||
* }
|
||||
*
|
||||
* Cursor window = paging.createCursor(N, paging.createWindow(0, 10));
|
||||
* while (window.isInRange())
|
||||
* {
|
||||
* for (long i = window.getStartRow(); i <= window.getEndRow(); i++)
|
||||
* {
|
||||
* ...collection[i]...
|
||||
* }
|
||||
* window = paging.createCursor(N, paging.createWindow(window.getNextPage(), window.getPageSize());
|
||||
* }
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class Paging
|
||||
{
|
||||
public enum PageType
|
||||
{
|
||||
PAGE,
|
||||
WINDOW
|
||||
};
|
||||
|
||||
boolean zeroBasedPage = false;
|
||||
boolean zeroBasedRow = true;
|
||||
|
||||
/**
|
||||
* Sets zero based page index
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @param zeroBasedPage true => 0 based, false => 1 based
|
||||
*/
|
||||
public void setZeroBasedPage(boolean zeroBasedPage)
|
||||
{
|
||||
this.zeroBasedPage = zeroBasedPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is zero based page index?
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @return true => 0 based, false => 1 based
|
||||
*/
|
||||
public boolean isZeroBasedPage()
|
||||
{
|
||||
return zeroBasedPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets zero based row index
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @param zeroBasedRow true => 0 based, false => 1 based
|
||||
*/
|
||||
public void setZeroBasedRow(boolean zeroBasedRow)
|
||||
{
|
||||
this.zeroBasedRow = zeroBasedRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is zero based row index?
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @return true => 0 based, false => 1 based
|
||||
*/
|
||||
public boolean isZeroBasedRow()
|
||||
{
|
||||
return zeroBasedRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Page or Window from standardised request arguments
|
||||
*
|
||||
* For Paged based index (take precedence over window based index, if both are specified):
|
||||
*
|
||||
* - request args
|
||||
* pageNo => page number index
|
||||
* pageSize => size of page
|
||||
*
|
||||
* For Window based index (as defined by CMIS):
|
||||
*
|
||||
* - request args (take precedence over header values if both are specified)
|
||||
* skipCount => row number start index
|
||||
* maxItems => size of page
|
||||
*
|
||||
* @param args request args
|
||||
* @return page (if pageNumber driven) or window (if skipCount driven)
|
||||
*/
|
||||
public Page createPageOrWindow(Map<String, String> args)
|
||||
{
|
||||
// page number
|
||||
Integer pageNo = null;
|
||||
String strPageNo = args.get("pageNo");
|
||||
if (strPageNo != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageNo = new Integer(strPageNo);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
// page size
|
||||
Integer pageSize = null;
|
||||
String strPageSize = args.get("pageSize");
|
||||
if (strPageSize != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageSize = new Integer(strPageSize);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
// skip count
|
||||
Integer skipCount = null;
|
||||
String strSkipCount = args.get("skipCount");
|
||||
if (strSkipCount != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
skipCount = new Integer(strSkipCount);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
// max items
|
||||
Integer maxItems = null;
|
||||
String strMaxItems = args.get("maxItems");
|
||||
if (strMaxItems != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
maxItems = new Integer(strMaxItems);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
return createPageOrWindow(pageNo, pageSize, skipCount, maxItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Page or Window
|
||||
*
|
||||
* @param pageNumber page number (optional and paired with pageSize)
|
||||
* @param pageSize page size (optional and paired with pageNumber)
|
||||
* @param skipCount skipCount (optional and paired with maxItems)
|
||||
* @param maxItems maxItems (optional and paired with skipCount)
|
||||
* @return page (if pageNumber driven) or window (if skipCount driven)
|
||||
*/
|
||||
public Page createPageOrWindow(Integer pageNumber, Integer pageSize, Integer skipCount, Integer maxItems)
|
||||
{
|
||||
if (pageNumber != null || pageSize != null)
|
||||
{
|
||||
return createPage(pageNumber == null ? isZeroBasedPage() ? 0 : 1 : pageNumber, pageSize == null ? -1 : pageSize);
|
||||
}
|
||||
else if (skipCount != null || maxItems != null)
|
||||
{
|
||||
return createWindow(skipCount == null ? isZeroBasedRow() ? 0 : 1 : skipCount, maxItems == null ? -1 : maxItems);
|
||||
}
|
||||
return createUnlimitedPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Page
|
||||
*
|
||||
* @param pageNumber page number
|
||||
* @param pageSize page size
|
||||
* @return the page
|
||||
*/
|
||||
public Page createPage(int pageNumber, int pageSize)
|
||||
{
|
||||
return new Page(PageType.PAGE, zeroBasedPage, pageNumber, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an unlimited Page
|
||||
*
|
||||
* @return page (single Page starting at first page of unlimited page size)
|
||||
*/
|
||||
public Page createUnlimitedPage()
|
||||
{
|
||||
return new Page(PageType.PAGE, zeroBasedPage, zeroBasedPage ? 0 : 1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Window
|
||||
* @param skipRows number of rows to skip
|
||||
* @param maxRows maximum number of rows in window
|
||||
* @return the window
|
||||
*/
|
||||
public Page createWindow(int skipRows, int maxRows)
|
||||
{
|
||||
return new Page(PageType.WINDOW, zeroBasedRow, skipRows, maxRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Cursor
|
||||
*
|
||||
* @param totalRows total number of rows in cursor (< 0 for don't know)
|
||||
* @param page the page / window within cursor
|
||||
* @return the cursor
|
||||
*/
|
||||
public Cursor createCursor(int totalRows, Page page)
|
||||
{
|
||||
if (page.getType() == PageType.PAGE)
|
||||
{
|
||||
return new PagedCursor(zeroBasedRow, totalRows, page.zeroBasedIdx, page.startIdx, page.pageSize);
|
||||
}
|
||||
else if (page.getType() == PageType.WINDOW)
|
||||
{
|
||||
return new WindowedCursor(zeroBasedRow, totalRows, page.startIdx, page.pageSize);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Paged Result Set
|
||||
*
|
||||
* @param results the results for the page within the cursor
|
||||
* @param cursor the cursor
|
||||
* @return the paged result set
|
||||
*/
|
||||
public PagedResults createPagedResults(Object[] results, Cursor cursor)
|
||||
{
|
||||
return new PagedResults(results, cursor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Paged Result Set
|
||||
*
|
||||
* @param result the results for the page within the cursor
|
||||
* @param cursor the cursor
|
||||
* @return the paged result set
|
||||
*/
|
||||
public PagedResults createPagedResult(Object result, Cursor cursor)
|
||||
{
|
||||
return new PagedResults(result, cursor);
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Paging. A utility for maintaining paged indexes for a collection of N items.
|
||||
*
|
||||
* There are two types of cursor:
|
||||
*
|
||||
* a) Paged
|
||||
*
|
||||
* This type of cursor is driven from a page number and page size. Random access within
|
||||
* the collection is possible by jumping straight to a page. A simple scroll through
|
||||
* the collection is supported by iterating through each next page.
|
||||
*
|
||||
* b) Windowed
|
||||
*
|
||||
* This type of cursor is driven from a skip row count and maximum number of rows. Random
|
||||
* access is not supported. The collection of items is simply scrolled through from
|
||||
* start to end by iterating through each next set of rows.
|
||||
*
|
||||
* In either case, a paging cursor provides a start row and end row which may be used
|
||||
* to extract the items for the page from the collection of N items.
|
||||
*
|
||||
* A zero (or less) page size or row maximum means "unlimited".
|
||||
*
|
||||
* Zero or one based Page and Rows indexes are supported. By default, Pages are 1 based and
|
||||
* Rows are 0 based.
|
||||
*
|
||||
* At any time, -1 is returned to represent "out of range" i.e. for next, previous, last page.
|
||||
*
|
||||
* Pseudo-code for traversing through a collection of N items (10 at a time):
|
||||
*
|
||||
* Paging paging = new Paging();
|
||||
* Cursor page = paging.createCursor(N, paging.createPage(1, 10));
|
||||
* while (page.isInRange())
|
||||
* {
|
||||
* for (long i = page.getStartRow(); i <= page.getEndRow(); i++)
|
||||
* {
|
||||
* ...collection[i]...
|
||||
* }
|
||||
* page = paging.createCursor(N, paging.createPage(page.getNextPage(), page.getPageSize());
|
||||
* }
|
||||
*
|
||||
* Cursor window = paging.createCursor(N, paging.createWindow(0, 10));
|
||||
* while (window.isInRange())
|
||||
* {
|
||||
* for (long i = window.getStartRow(); i <= window.getEndRow(); i++)
|
||||
* {
|
||||
* ...collection[i]...
|
||||
* }
|
||||
* window = paging.createCursor(N, paging.createWindow(window.getNextPage(), window.getPageSize());
|
||||
* }
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class Paging
|
||||
{
|
||||
public enum PageType
|
||||
{
|
||||
PAGE,
|
||||
WINDOW
|
||||
};
|
||||
|
||||
boolean zeroBasedPage = false;
|
||||
boolean zeroBasedRow = true;
|
||||
|
||||
/**
|
||||
* Sets zero based page index
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @param zeroBasedPage true => 0 based, false => 1 based
|
||||
*/
|
||||
public void setZeroBasedPage(boolean zeroBasedPage)
|
||||
{
|
||||
this.zeroBasedPage = zeroBasedPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is zero based page index?
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @return true => 0 based, false => 1 based
|
||||
*/
|
||||
public boolean isZeroBasedPage()
|
||||
{
|
||||
return zeroBasedPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets zero based row index
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @param zeroBasedRow true => 0 based, false => 1 based
|
||||
*/
|
||||
public void setZeroBasedRow(boolean zeroBasedRow)
|
||||
{
|
||||
this.zeroBasedRow = zeroBasedRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is zero based row index?
|
||||
*
|
||||
* Note: scoped to this paging cursor instance
|
||||
*
|
||||
* @return true => 0 based, false => 1 based
|
||||
*/
|
||||
public boolean isZeroBasedRow()
|
||||
{
|
||||
return zeroBasedRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Page or Window from standardised request arguments
|
||||
*
|
||||
* For Paged based index (take precedence over window based index, if both are specified):
|
||||
*
|
||||
* - request args
|
||||
* pageNo => page number index
|
||||
* pageSize => size of page
|
||||
*
|
||||
* For Window based index (as defined by CMIS):
|
||||
*
|
||||
* - request args (take precedence over header values if both are specified)
|
||||
* skipCount => row number start index
|
||||
* maxItems => size of page
|
||||
*
|
||||
* @param args request args
|
||||
* @return page (if pageNumber driven) or window (if skipCount driven)
|
||||
*/
|
||||
public Page createPageOrWindow(Map<String, String> args)
|
||||
{
|
||||
// page number
|
||||
Integer pageNo = null;
|
||||
String strPageNo = args.get("pageNo");
|
||||
if (strPageNo != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageNo = new Integer(strPageNo);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
// page size
|
||||
Integer pageSize = null;
|
||||
String strPageSize = args.get("pageSize");
|
||||
if (strPageSize != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageSize = new Integer(strPageSize);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
// skip count
|
||||
Integer skipCount = null;
|
||||
String strSkipCount = args.get("skipCount");
|
||||
if (strSkipCount != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
skipCount = new Integer(strSkipCount);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
// max items
|
||||
Integer maxItems = null;
|
||||
String strMaxItems = args.get("maxItems");
|
||||
if (strMaxItems != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
maxItems = new Integer(strMaxItems);
|
||||
}
|
||||
catch(NumberFormatException e) {};
|
||||
}
|
||||
|
||||
return createPageOrWindow(pageNo, pageSize, skipCount, maxItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Page or Window
|
||||
*
|
||||
* @param pageNumber page number (optional and paired with pageSize)
|
||||
* @param pageSize page size (optional and paired with pageNumber)
|
||||
* @param skipCount skipCount (optional and paired with maxItems)
|
||||
* @param maxItems maxItems (optional and paired with skipCount)
|
||||
* @return page (if pageNumber driven) or window (if skipCount driven)
|
||||
*/
|
||||
public Page createPageOrWindow(Integer pageNumber, Integer pageSize, Integer skipCount, Integer maxItems)
|
||||
{
|
||||
if (pageNumber != null || pageSize != null)
|
||||
{
|
||||
return createPage(pageNumber == null ? isZeroBasedPage() ? 0 : 1 : pageNumber, pageSize == null ? -1 : pageSize);
|
||||
}
|
||||
else if (skipCount != null || maxItems != null)
|
||||
{
|
||||
return createWindow(skipCount == null ? isZeroBasedRow() ? 0 : 1 : skipCount, maxItems == null ? -1 : maxItems);
|
||||
}
|
||||
return createUnlimitedPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Page
|
||||
*
|
||||
* @param pageNumber page number
|
||||
* @param pageSize page size
|
||||
* @return the page
|
||||
*/
|
||||
public Page createPage(int pageNumber, int pageSize)
|
||||
{
|
||||
return new Page(PageType.PAGE, zeroBasedPage, pageNumber, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an unlimited Page
|
||||
*
|
||||
* @return page (single Page starting at first page of unlimited page size)
|
||||
*/
|
||||
public Page createUnlimitedPage()
|
||||
{
|
||||
return new Page(PageType.PAGE, zeroBasedPage, zeroBasedPage ? 0 : 1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Window
|
||||
* @param skipRows number of rows to skip
|
||||
* @param maxRows maximum number of rows in window
|
||||
* @return the window
|
||||
*/
|
||||
public Page createWindow(int skipRows, int maxRows)
|
||||
{
|
||||
return new Page(PageType.WINDOW, zeroBasedRow, skipRows, maxRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Cursor
|
||||
*
|
||||
* @param totalRows total number of rows in cursor (< 0 for don't know)
|
||||
* @param page the page / window within cursor
|
||||
* @return the cursor
|
||||
*/
|
||||
public Cursor createCursor(int totalRows, Page page)
|
||||
{
|
||||
if (page.getType() == PageType.PAGE)
|
||||
{
|
||||
return new PagedCursor(zeroBasedRow, totalRows, page.zeroBasedIdx, page.startIdx, page.pageSize);
|
||||
}
|
||||
else if (page.getType() == PageType.WINDOW)
|
||||
{
|
||||
return new WindowedCursor(zeroBasedRow, totalRows, page.startIdx, page.pageSize);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Paged Result Set
|
||||
*
|
||||
* @param results the results for the page within the cursor
|
||||
* @param cursor the cursor
|
||||
* @return the paged result set
|
||||
*/
|
||||
public PagedResults createPagedResults(Object[] results, Cursor cursor)
|
||||
{
|
||||
return new PagedResults(results, cursor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Paged Result Set
|
||||
*
|
||||
* @param result the results for the page within the cursor
|
||||
* @param cursor the cursor
|
||||
* @return the paged result set
|
||||
*/
|
||||
public PagedResults createPagedResult(Object result, Cursor cursor)
|
||||
{
|
||||
return new PagedResults(result, cursor);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,188 +1,188 @@
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.repo.web.util.paging.Paging.PageType;
|
||||
|
||||
|
||||
/**
|
||||
* Cursor implementation based on notion of a Window.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class WindowedCursor implements Cursor, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 521131539938276413L;
|
||||
|
||||
private boolean zeroBasedRow;
|
||||
private int totalRows;
|
||||
private int skipRows;
|
||||
private int maxRows;
|
||||
private int rowsPerPage;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param zeroBasedRow true => 0 based, false => 1 based
|
||||
* @param totalRows total rows in collection
|
||||
* @param skipRows number of rows to skip (0 - none)
|
||||
* @param maxRows maximum number of rows in window
|
||||
*/
|
||||
WindowedCursor(boolean zeroBasedRow, int totalRows, int skipRows, int maxRows)
|
||||
{
|
||||
this.zeroBasedRow = zeroBasedRow;
|
||||
this.totalRows = totalRows;
|
||||
this.skipRows = skipRows;
|
||||
this.maxRows = maxRows;
|
||||
this.rowsPerPage = (maxRows <= 0) ? totalRows - skipRows : maxRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageType()
|
||||
*/
|
||||
public String getPageType()
|
||||
{
|
||||
return PageType.WINDOW.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageSize()
|
||||
*/
|
||||
public int getPageSize()
|
||||
{
|
||||
return maxRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalPages()
|
||||
*/
|
||||
public int getTotalPages()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalRows()
|
||||
*/
|
||||
public int getTotalRows()
|
||||
{
|
||||
return totalRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getCurrentPage()
|
||||
*/
|
||||
public int getCurrentPage()
|
||||
{
|
||||
return skipRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getFirstPage()
|
||||
*/
|
||||
public int getFirstPage()
|
||||
{
|
||||
if (totalRows <=0)
|
||||
return -1;
|
||||
|
||||
return zeroBasedRow ? 0 : 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getLastPage()
|
||||
*/
|
||||
public int getLastPage()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getNextPage()
|
||||
*/
|
||||
public int getNextPage()
|
||||
{
|
||||
return (skipRows + rowsPerPage < totalRows) ? skipRows + maxRows : -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPrevPage()
|
||||
*/
|
||||
public int getPrevPage()
|
||||
{
|
||||
return (skipRows > 0) ? Math.max(0, skipRows - maxRows) : -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#isInRange()
|
||||
*/
|
||||
public boolean isInRange()
|
||||
{
|
||||
return skipRows >= 0 && skipRows < totalRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasFirstPage()
|
||||
*/
|
||||
public boolean getHasFirstPage()
|
||||
{
|
||||
return getFirstPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasLastPage()
|
||||
*/
|
||||
public boolean getHasLastPage()
|
||||
{
|
||||
return getLastPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasNextPage()
|
||||
*/
|
||||
public boolean getHasNextPage()
|
||||
{
|
||||
return getNextPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasPrevPage()
|
||||
*/
|
||||
public boolean getHasPrevPage()
|
||||
{
|
||||
return getPrevPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getStartRow()
|
||||
*/
|
||||
public int getStartRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return skipRows + (zeroBasedRow ? 0 : 1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getEndRow()
|
||||
*/
|
||||
public int getEndRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return getStartRow() + Math.min(rowsPerPage, totalRows - skipRows) - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getRowCount()
|
||||
*/
|
||||
public int getRowCount()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return getEndRow() - getStartRow() + 1;
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.web.util.paging;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.alfresco.repo.web.util.paging.Paging.PageType;
|
||||
|
||||
|
||||
/**
|
||||
* Cursor implementation based on notion of a Window.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public class WindowedCursor implements Cursor, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 521131539938276413L;
|
||||
|
||||
private boolean zeroBasedRow;
|
||||
private int totalRows;
|
||||
private int skipRows;
|
||||
private int maxRows;
|
||||
private int rowsPerPage;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param zeroBasedRow true => 0 based, false => 1 based
|
||||
* @param totalRows total rows in collection
|
||||
* @param skipRows number of rows to skip (0 - none)
|
||||
* @param maxRows maximum number of rows in window
|
||||
*/
|
||||
WindowedCursor(boolean zeroBasedRow, int totalRows, int skipRows, int maxRows)
|
||||
{
|
||||
this.zeroBasedRow = zeroBasedRow;
|
||||
this.totalRows = totalRows;
|
||||
this.skipRows = skipRows;
|
||||
this.maxRows = maxRows;
|
||||
this.rowsPerPage = (maxRows <= 0) ? totalRows - skipRows : maxRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageType()
|
||||
*/
|
||||
public String getPageType()
|
||||
{
|
||||
return PageType.WINDOW.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPageSize()
|
||||
*/
|
||||
public int getPageSize()
|
||||
{
|
||||
return maxRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalPages()
|
||||
*/
|
||||
public int getTotalPages()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getTotalRows()
|
||||
*/
|
||||
public int getTotalRows()
|
||||
{
|
||||
return totalRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getCurrentPage()
|
||||
*/
|
||||
public int getCurrentPage()
|
||||
{
|
||||
return skipRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getFirstPage()
|
||||
*/
|
||||
public int getFirstPage()
|
||||
{
|
||||
if (totalRows <=0)
|
||||
return -1;
|
||||
|
||||
return zeroBasedRow ? 0 : 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getLastPage()
|
||||
*/
|
||||
public int getLastPage()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getNextPage()
|
||||
*/
|
||||
public int getNextPage()
|
||||
{
|
||||
return (skipRows + rowsPerPage < totalRows) ? skipRows + maxRows : -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getPrevPage()
|
||||
*/
|
||||
public int getPrevPage()
|
||||
{
|
||||
return (skipRows > 0) ? Math.max(0, skipRows - maxRows) : -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#isInRange()
|
||||
*/
|
||||
public boolean isInRange()
|
||||
{
|
||||
return skipRows >= 0 && skipRows < totalRows;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasFirstPage()
|
||||
*/
|
||||
public boolean getHasFirstPage()
|
||||
{
|
||||
return getFirstPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasLastPage()
|
||||
*/
|
||||
public boolean getHasLastPage()
|
||||
{
|
||||
return getLastPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasNextPage()
|
||||
*/
|
||||
public boolean getHasNextPage()
|
||||
{
|
||||
return getNextPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#hasPrevPage()
|
||||
*/
|
||||
public boolean getHasPrevPage()
|
||||
{
|
||||
return getPrevPage() != -1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getStartRow()
|
||||
*/
|
||||
public int getStartRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return skipRows + (zeroBasedRow ? 0 : 1);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getEndRow()
|
||||
*/
|
||||
public int getEndRow()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return -1;
|
||||
|
||||
return getStartRow() + Math.min(rowsPerPage, totalRows - skipRows) - 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.web.util.paging.Cursor#getRowCount()
|
||||
*/
|
||||
public int getRowCount()
|
||||
{
|
||||
if (totalRows <= 0)
|
||||
return 0;
|
||||
|
||||
return getEndRow() - getStartRow() + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user