[security-dev] Picketlink 3 IDM - Counting of query results

Marek Posolda mposolda at redhat.com
Wed Dec 5 17:09:56 EST 2012


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();



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);


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



More information about the security-dev mailing list