Package org.alfresco.query
Class AbstractCannedQuery<R>
- java.lang.Object
-
- org.alfresco.query.AbstractCannedQuery<R>
-
- All Implemented Interfaces:
CannedQuery<R>
public abstract class AbstractCannedQuery<R> extends Object implements CannedQuery<R>
Basic support for canned query implementations.- Since:
- 4.0
- Author:
- Derek Hulley
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCannedQuery(CannedQueryParameters parameters)
Construct the canned query given the original parameters applied.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected List<List<R>>
applyPostQueryPaging(List<R> results, CannedQueryPageDetails pageDetails)
Called after thesorting phase
to pull out results specific to the required pages.protected List<R>
applyPostQueryPermissions(List<R> results, int requestedCount)
Called after the query to filter out results based on permissions.protected List<R>
applyPostQuerySorting(List<R> results, CannedQuerySortDetails sortDetails)
Called beforeapplyPostQueryPermissions(List, int)
to allow the results to be sorted prior to permission checks.CannedQueryResults<R>
execute()
Execute the named query, which was provided to support theparameters
originally provided.CannedQueryParameters
getParameters()
Get the original parameters used to generate the query.protected Pair<Integer,Integer>
getTotalResultCount(List<R> results)
Get the total number of available results after querying, filtering, sorting and permission checking.protected boolean
isApplyPostQueryPaging()
Override to get post-query calls to do pull out paged results.protected boolean
isApplyPostQueryPermissions()
Override to get post-query calls to apply permission filters.protected boolean
isApplyPostQuerySorting()
Override to get post-query calls to do sorting.protected abstract List<R>
queryAndFilter(CannedQueryParameters parameters)
Implement the basic query, returning either filtered or all results.String
toString()
-
-
-
Constructor Detail
-
AbstractCannedQuery
protected AbstractCannedQuery(CannedQueryParameters parameters)
Construct the canned query given the original parameters applied. A random GUID query execution ID will be generated.- Parameters:
parameters
- the original query parameters
-
-
Method Detail
-
getParameters
public CannedQueryParameters getParameters()
Description copied from interface:CannedQuery
Get the original parameters used to generate the query.- Specified by:
getParameters
in interfaceCannedQuery<R>
- Returns:
- the parameters used to obtain the named query.
-
execute
public final CannedQueryResults<R> execute()
Description copied from interface:CannedQuery
Execute the named query, which was provided to support theparameters
originally provided. Note: This method can only be used once; to requery, get a new instance from thefactory
.- Specified by:
execute
in interfaceCannedQuery<R>
- Returns:
- the query results
-
queryAndFilter
protected abstract List<R> queryAndFilter(CannedQueryParameters parameters)
Implement the basic query, returning either filtered or all results. The implementation may optimally select, filter, sort and apply permissions. If not, however, the subsequent post-query methods (applyPostQuerySorting(List, CannedQuerySortDetails)
,applyPostQueryPermissions(List, int)
andapplyPostQueryPaging(List, CannedQueryPageDetails)
) can be used to trim the results as required.- Parameters:
parameters
- the full parameters to be used for execution
-
isApplyPostQuerySorting
protected boolean isApplyPostQuerySorting()
Override to get post-query calls to do sorting.- Returns:
- true to get a post-query call to sort (default false)
-
applyPostQuerySorting
protected List<R> applyPostQuerySorting(List<R> results, CannedQuerySortDetails sortDetails)
Called beforeapplyPostQueryPermissions(List, int)
to allow the results to be sorted prior to permission checks. Note that the query implementation may optimally sort results during retrieval, in which case this method does not need to be implemented.- Parameters:
results
- the results to sortsortDetails
- details of the sorting requirements- Returns:
- the results according to the new sort order
-
isApplyPostQueryPermissions
protected boolean isApplyPostQueryPermissions()
Override to get post-query calls to apply permission filters.- Returns:
- true to get a post-query call to apply permissions (default false)
-
applyPostQueryPermissions
protected List<R> applyPostQueryPermissions(List<R> results, int requestedCount)
Called after the query to filter out results based on permissions. Note that the query implementation may optimally only select results based on available privileges, in which case this method does not need to be implemented. Permission evaluations should continue until the requested number of results are retrieved or all available results have been examined.- Parameters:
results
- the results to apply permissions torequestedCount
- the minimum number of results to pass the permission checks in order to fully satisfy the paging requirements- Returns:
- the remaining results (as a single "page") after permissions have been applied
-
getTotalResultCount
protected Pair<Integer,Integer> getTotalResultCount(List<R> results)
Get the total number of available results after querying, filtering, sorting and permission checking. The default implementation assumes that the given results are the final total possible.- Parameters:
results
- the results after filtering and sorting, but before paging- Returns:
- pair representing (a) the total number of results and (b) the estimated (or actual) number of maximum results possible for this query.
- See Also:
CannedQueryParameters.getTotalResultCountMax()
-
isApplyPostQueryPaging
protected boolean isApplyPostQueryPaging()
Override to get post-query calls to do pull out paged results.- Returns:
- true to get a post-query call to page (default true)
-
applyPostQueryPaging
protected List<List<R>> applyPostQueryPaging(List<R> results, CannedQueryPageDetails pageDetails)
Called after thesorting phase
to pull out results specific to the required pages. Note that the query implementation may optimally create page-specific results, in which case this method does not need to be implemented. The base implementation assumes that results are not paged and that the current results are all the available results i.e. that paging still needs to be applied.- Parameters:
results
- full results (all or excess pages)pageDetails
- details of the paging requirements- Returns:
- the specific page of results as per the query parameters
-
-