-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: What does the distinction variable in performList method do
PostPosted: Mon Aug 22, 2016 2:58 am 
Newbie

Joined: Mon Aug 22, 2016 2:36 am
Posts: 1
Why they declared distinction local variable in org.hibernate.engine.query.spi.HQLQueryPlan class.
I am not understand why they provided this condition : if (!distinction.add(result) || ++includedCount < first) continue;

Code:
public List performList(QueryParameters queryParameters, SessionImplementor session) throws HibernateException {
        boolean needsLimit;
        QueryParameters queryParametersToUse;
        if (LOG.isTraceEnabled()) {
            LOG.tracev("Find: {0}", (Object)this.getSourceQuery());
            queryParameters.traceParameters(session.getFactory());
        }
        boolean hasLimit = queryParameters.getRowSelection() != null && queryParameters.getRowSelection().definesLimits();
        boolean bl = needsLimit = hasLimit && this.translators.length > 1;
        if (needsLimit) {
            LOG.needsLimit();
            RowSelection selection = new RowSelection();
            selection.setFetchSize(queryParameters.getRowSelection().getFetchSize());
            selection.setTimeout(queryParameters.getRowSelection().getTimeout());
            queryParametersToUse = queryParameters.createCopyUsing(selection);
        } else {
            queryParametersToUse = queryParameters;
        }
        ArrayList combinedResults = new ArrayList();
        IdentitySet distinction = new IdentitySet();
        int includedCount = -1;
        block0 : for (QueryTranslator translator : this.translators) {
            List tmp = translator.list(session, queryParametersToUse);
            if (needsLimit) {
                int first = queryParameters.getRowSelection().getFirstRow() == null ? 0 : queryParameters.getRowSelection().getFirstRow();
                int max = queryParameters.getRowSelection().getMaxRows() == null ? -1 : queryParameters.getRowSelection().getMaxRows();
                for (Object result : tmp) {
                    if (!distinction.add(result) || ++includedCount < first) continue;
                    combinedResults.add(result);
                    if (max < 0 || includedCount <= max) continue;
                    break block0;
                }
                continue;
            }
            combinedResults.addAll(tmp);
        }
        return combinedResults;
    }


Top
 Profile  
 
 Post subject: Re: Why use distinction variable in performList method
PostPosted: Mon Aug 29, 2016 6:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It might be used for when you use pagination along with a JOIN FETCH, when the pagination cannot be applied at SQL-level so it needs to be performed after the whole List is being fetched. Check out this article for more information on this topic.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.