mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-8855 - Start to change ScriptPagingDetails to be based on PagingRequest
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28330 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
package org.alfresco.util;
|
package org.alfresco.util;
|
||||||
|
|
||||||
|
import org.alfresco.query.PagingRequest;
|
||||||
|
import org.alfresco.query.PagingResults;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple paging details wrapper, to hold things like the
|
* A simple paging details wrapper, to hold things like the
|
||||||
* skip count, max items and total items. This is typically
|
* skip count, max items and total items. This is typically
|
||||||
@@ -9,8 +12,10 @@ package org.alfresco.util;
|
|||||||
* Note that {@link org.alfresco.repo.web.paging.Paging}
|
* Note that {@link org.alfresco.repo.web.paging.Paging}
|
||||||
* provides an alternate solution for other paging
|
* provides an alternate solution for other paging
|
||||||
* use cases.
|
* use cases.
|
||||||
|
*
|
||||||
|
* TODO Set a value for {@link #setRequestTotalCountMax(int)}
|
||||||
*/
|
*/
|
||||||
public class ScriptPagingDetails
|
public class ScriptPagingDetails extends PagingRequest
|
||||||
{
|
{
|
||||||
public enum ItemsSizeConfidence {
|
public enum ItemsSizeConfidence {
|
||||||
EXACT,
|
EXACT,
|
||||||
@@ -19,24 +24,21 @@ public class ScriptPagingDetails
|
|||||||
UNKNOWN
|
UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
private int skipCount = -1; // TODO To PagingRequest
|
|
||||||
private String queryExecutionId = null; // TODO To PagingRequest
|
|
||||||
private int maxItems = -1; // TODO To PagingRequest
|
|
||||||
|
|
||||||
private int totalItems = -1;
|
private int totalItems = -1;
|
||||||
private int totalItemsRangeMax = -1;
|
private int totalItemsRangeMax = -1;
|
||||||
private ItemsSizeConfidence confidence = ItemsSizeConfidence.UNKNOWN;
|
private ItemsSizeConfidence confidence = ItemsSizeConfidence.UNKNOWN;
|
||||||
|
|
||||||
public ScriptPagingDetails() {}
|
public ScriptPagingDetails()
|
||||||
|
{
|
||||||
|
super(-1, null);
|
||||||
|
}
|
||||||
public ScriptPagingDetails(int maxItems, int skipCount)
|
public ScriptPagingDetails(int maxItems, int skipCount)
|
||||||
{
|
{
|
||||||
this(maxItems, skipCount, null);
|
this(maxItems, skipCount, null);
|
||||||
}
|
}
|
||||||
public ScriptPagingDetails(int maxItems, int skipCount, String queryExecutionId)
|
public ScriptPagingDetails(int maxItems, int skipCount, String queryExecutionId)
|
||||||
{
|
{
|
||||||
this.maxItems = maxItems;
|
super(skipCount, maxItems, queryExecutionId);
|
||||||
this.skipCount = skipCount;
|
|
||||||
this.queryExecutionId = queryExecutionId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemsSizeConfidence getConfidence()
|
public ItemsSizeConfidence getConfidence()
|
||||||
@@ -52,6 +54,13 @@ public class ScriptPagingDetails
|
|||||||
{
|
{
|
||||||
return totalItems;
|
return totalItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records the total number of items that were found. If the value is -1,
|
||||||
|
* then the confidence is set to {@link ItemsSizeConfidence#UNKNOWN}, otherwise
|
||||||
|
* the confidence is {@link ItemsSizeConfidence#EXACT}
|
||||||
|
* @param totalItems The total number of items the search found
|
||||||
|
*/
|
||||||
public void setTotalItems(int totalItems)
|
public void setTotalItems(int totalItems)
|
||||||
{
|
{
|
||||||
this.totalItems = totalItems;
|
this.totalItems = totalItems;
|
||||||
@@ -66,6 +75,43 @@ public class ScriptPagingDetails
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records the total number of results found, and the confidence
|
||||||
|
* in this, from the Paging Results
|
||||||
|
* @param results The PagingResults to extract the information from
|
||||||
|
*/
|
||||||
|
public <R> void setTotalItems(PagingResults<R> results)
|
||||||
|
{
|
||||||
|
Integer min = results.getTotalResultCount().getFirst();
|
||||||
|
Integer max = results.getTotalResultCount().getSecond();
|
||||||
|
|
||||||
|
// Get the total count and confidence
|
||||||
|
if(min == null)
|
||||||
|
{
|
||||||
|
this.totalItems = -1;
|
||||||
|
this.confidence = ItemsSizeConfidence.UNKNOWN;
|
||||||
|
}
|
||||||
|
else if(max == null)
|
||||||
|
{
|
||||||
|
this.totalItems = min;
|
||||||
|
this.confidence = ItemsSizeConfidence.AT_LEAST;
|
||||||
|
}
|
||||||
|
else if(min == max)
|
||||||
|
{
|
||||||
|
this.totalItems = min;
|
||||||
|
this.confidence = ItemsSizeConfidence.EXACT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.totalItems = min;
|
||||||
|
this.totalItemsRangeMax = max;
|
||||||
|
this.confidence = ItemsSizeConfidence.RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally record the query execution ID
|
||||||
|
setQueryExecutionId(results.getQueryExecutionId());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where the confidence is {@link ItemsSizeConfidence#RANGE}, returns
|
* Where the confidence is {@link ItemsSizeConfidence#RANGE}, returns
|
||||||
* the upper bound of the range.
|
* the upper bound of the range.
|
||||||
@@ -75,28 +121,17 @@ public class ScriptPagingDetails
|
|||||||
return totalItemsRangeMax;
|
return totalItemsRangeMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxItems()
|
|
||||||
{
|
|
||||||
return maxItems;
|
|
||||||
}
|
|
||||||
public void setMaxItems(int maxItems)
|
public void setMaxItems(int maxItems)
|
||||||
{
|
{
|
||||||
this.maxItems = maxItems;
|
super.setMaxItems(maxItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSkipCount()
|
|
||||||
{
|
|
||||||
return skipCount;
|
|
||||||
}
|
|
||||||
public void setSkipCount(int skipCount)
|
public void setSkipCount(int skipCount)
|
||||||
{
|
{
|
||||||
this.skipCount = skipCount;
|
super.setSkipCount(skipCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQueryExecutionId() {
|
|
||||||
return queryExecutionId;
|
|
||||||
}
|
|
||||||
public void setQueryExecutionId(String queryExecutionId) {
|
public void setQueryExecutionId(String queryExecutionId) {
|
||||||
this.queryExecutionId = queryExecutionId;
|
super.setQueryExecutionId(queryExecutionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user