[security-dev] Picketlink 3 IDM - Counting of query results
Marek Posolda
mposolda at redhat.com
Thu Dec 6 05:36:21 EST 2012
On 06/12/12 11:10, Marek Posolda wrote:
> On 05/12/12 23:21, Shane Bryzak wrote:
>> On 12/06/2012 08:09 AM, Marek Posolda wrote:
>>> Hi all,
>>>
>>> I have possible request for API change and hope it's not too late for
>>> first IDM iteration.
>>>
>>> My suggestion is to have method on class IdentityStore with signature like:
>>>
>>> int countQueryResults(Map<QueryParameter,Object> parameters);
>>>
>>> in addition to current:
>>>
>>> List<IdentityType> fetchQueryResults(Map<QueryParameter,Object> parameters);
>>>
>>>
>>> Example use-case could be: give me count of all users with first name "John"
>>>
>>> My motivation is, that for proper pagination support (searching
>>> use-cases), you usually need to know total number of pages (records) and
>>> then show searching results only from first page. Then user can browse
>>> between pages (if more than one page is available). Something like
>>> www.google.com is doing :-) Also we need to support this in GateIn portal.
>>>
>>> Note that having this method is redundant at first look, as you can
>>> always obtain same results with: fetchQueryResults(queryParams).size()
>>> But then we are obviously losing performance. For example in JPA (DB)
>>> it's way more performant to call DB query like: select count(id) from
>>> users;
>>> instead of: select * from users;
>>>
>>> Also to properly support this, we may also need additional method on
>>> IdentityQuery with signature like:
>>>
>>> int getResultCount();
>> I have no problem adding this.
>>
>>>
>>> Also with respect to IdentityQuery, I am not sure how are information
>>> about offset and limit propagated to IdentityStore? For example I have:
>>> IdentityQuery query = IdentityManager().<User> createQuery(User.class);
>>> query.setParameter(User.FIRST_NAME, "John");
>>> query.setOffset(0);
>>> query.setLimit(10);
>>> query.getResultList();
>>>
>>> Calling of "getResultList" on last line will invoke
>>> "fetchQueryResults(queryParams)" of configured IdentityStore. But how is
>>> ensured that result from IdentityStore will return only first 10 records
>>> as requested? So I think we can either:
>>>
>>> a) Change signature of method on IdentityStore to be:
>>>
>>> List<IdentityType> fetchQueryResults(Map<QueryParameter,Object>
>>> parameters, int offset, int limit);
>> We should probably just support this:
>>
>> List<IdentityType> fetchQueryResults(IdentityQuery query);
> That would mean that we need additional getter methods on IdentityQuery
> interface, so that IdentityStore have access to all needed info.
> Something like:
>
> Class<T> getIdentityType();
>
> Map<QueryParameter, Object[]> getParameters();
>
> int getOffset();
>
> int getLimit();
>
>
>
> Other approach is to have offset, limit and identityType available as
> additional queryParameters (like mentioned below in approach (b)) and on
> IdentityStore supports only this:
>
> <T extends IdentityType> List<T> fetchQueryResults(Class<T>
> identityType, Map<QueryParameter,Object[]> parameters);
>
> <T extends IdentityType> int
> countQueryResults(Map<QueryParameter,Object[]> parameters);
oops, sorry. I meant to have this on IdentityStore (if we use the
approach with encapsulating identityType, offset and limit as query
parameters):
List<T> fetchQueryResults(Map<QueryParameter, Object[]> parameters);
int countQueryResults(Map<QueryParameter, Object[]> parameters);
Marek
>
> Marek
>
>>
>>
>>> b) Add QueryParameters for pagination support, which will be sent to
>>> IdentityStore. Maybe we can have something like this on IdentityQuery
>>> class:
>>>
>>> QueryParameter OFFSET = new QueryParameter() {};
>>>
>>> QueryParameter LIMIT = new QueryParameter() {};
>>>
>>> And something like this on DefaultIdentityQuery class:
>>>
>>> @Override
>>> public IdentityQuery<T> setOffset(int offset) {
>>> parameters.put(IdentityQuery.OFFSET, offset);
>>> return this;
>>> }
>>>
>>> @Override
>>> public IdentityQuery<T> setLimit(int limit) {
>>> parameters.put(IdentityQuery.LIMIT, limit);
>>> return this;
>>> }
>>>
>>> Currently I am not seeing any query parameters for pagination in codebase.
>>>
>>> WDYT?
>>> Marek
>>>
>>> _______________________________________________
>>> security-dev mailing list
>>> security-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/security-dev
>> _______________________________________________
>> security-dev mailing list
>> security-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/security-dev
> _______________________________________________
> security-dev mailing list
> security-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/security-dev
More information about the security-dev
mailing list