this.rootEntity = metadata.getObjEntity();
// create an internal query, it is a partial replica of
// the original query and will serve as a value holder for
// various parameters
this.internalQuery = new SelectQuery(rootEntity);
this.internalQuery.setFetchingDataRows(metadata.isFetchingDataRows());
this.internalQuery.setResolvingInherited(metadata.isResolvingInherited());
this.internalQuery.setPrefetchTree(metadata.getPrefetchTree());
this.helper = createHelper(metadata);
boolean resolvesFirstPage = true;
if (!metadata.isFetchingDataRows() && (query instanceof SelectQuery)) {
SelectQuery select = (SelectQuery) query;
// optimize SelectQuery:
// * just select ID columns - this gives a 5-10x speedup
// * strip prefetches as they blow the iterated result, and are actually not
// needed
SelectQuery clone = select.queryWithParameters(Collections.EMPTY_MAP, true);
clone.clearPrefetches();
// I guess this check is redundant, as custom attributes warrant data rows
if (!select.isFetchingCustomAttributes()) {
for (DbAttribute attribute : rootEntity.getDbEntity().getPrimaryKeys()) {
clone.addCustomDbAttribute(attribute.getName());
}
}
query = clone;
resolvesFirstPage = false;