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