use of org.apache.cayenne.query.PrefetchProcessor in project cayenne by apache.
the class SelectAction method forSuppressedDistinct.
private <T> ResultIterator<T> forSuppressedDistinct(ResultIterator<T> iterator, SelectTranslator translator) {
if (!translator.isSuppressingDistinct() || queryMetadata.isSuppressingDistinct()) {
return iterator;
}
// wrap result iterator if distinct has to be suppressed
// a joint prefetch warrants full row compare
final boolean[] compareFullRows = new boolean[1];
compareFullRows[0] = translator.hasJoins();
final PrefetchTreeNode rootPrefetch = queryMetadata.getPrefetchTree();
if (!compareFullRows[0] && rootPrefetch != null) {
rootPrefetch.traverse(new PrefetchProcessor() {
@Override
public void finishPrefetch(PrefetchTreeNode node) {
}
@Override
public boolean startDisjointPrefetch(PrefetchTreeNode node) {
// continue to children only if we are at root
return rootPrefetch == node;
}
@Override
public boolean startDisjointByIdPrefetch(PrefetchTreeNode node) {
// continue to children only if we are at root
return rootPrefetch == node;
}
@Override
public boolean startUnknownPrefetch(PrefetchTreeNode node) {
// continue to children only if we are at root
return rootPrefetch == node;
}
@Override
public boolean startJointPrefetch(PrefetchTreeNode node) {
if (rootPrefetch != node) {
compareFullRows[0] = true;
return false;
}
return true;
}
@Override
public boolean startPhantomPrefetch(PrefetchTreeNode node) {
return true;
}
});
}
return new DistinctResultIterator<>(iterator, queryMetadata.getDbEntity(), compareFullRows[0]);
}
Aggregations