if (this.disableIntersectingCrossCatalogQueries) {
try {
int totalResults = 0;
LinkedHashMap<String, Integer> catalogToSizeOfMap = new LinkedHashMap<String, Integer>();
for (String catalogId : catalogIds) {
Catalog catalog = this.getCatalog(catalogId);
QueryExpression qe = this.reduceToUnderstoodExpressions(catalog, queryExpression);
if (qe != null) {
int catalogResultSize = catalog.sizeOf(qe);
totalResults += catalogResultSize;
catalogToSizeOfMap.put(catalogId, catalogResultSize);
}
}
LOG.log(Level.INFO, "Routing query to catalogs as non-cross catalog intersecting queries . . .");
if (totalResults <= this.crossCatalogResultSortingThreshold) {
List<CatalogReceipt> catalogReceipts = new Vector<CatalogReceipt>();
for (String catalogId : catalogToSizeOfMap.keySet()) {
Catalog catalog = this.getCatalog(catalogId);
QueryExpression qe = this.reduceToUnderstoodExpressions(catalog, queryExpression);
if (qe != null)
catalogReceipts.addAll(catalog.query(qe));
}
List<TransactionReceipt> transactionReceipts = this.getPossiblyUnindexedTransactionReceipts(catalogReceipts);
LOG.log(Level.INFO, "Sorting Query Results . . . ");
Collections.sort(transactionReceipts, new Comparator<TransactionReceipt>() {
public int compare(TransactionReceipt o1,
TransactionReceipt o2) {
return o2.getTransactionDate().compareTo(o1.getTransactionDate());
}
});
QueryPager queryPager = new QueryPager(transactionReceipts);
queryPager.setPageInfo(pageInfo);
return this.getPage(queryExpression, catalogIds, queryPager);
}else {
int currentIndex = 0;
int desiredStartingIndex = pageInfo.getPageNum() * pageInfo.getPageSize();
List<CatalogReceipt> pageOfReceipts = new Vector<CatalogReceipt>();
for (Entry<String, Integer> entry : catalogToSizeOfMap.entrySet()) {
if (desiredStartingIndex - currentIndex <= entry.getValue()) {
Catalog catalog = this.getCatalog(entry.getKey());
QueryExpression qe = this.reduceToUnderstoodExpressions(catalog, queryExpression);
if (qe != null) {
List<CatalogReceipt> receipts = catalog.query(qe, desiredStartingIndex - currentIndex, Math.min((desiredStartingIndex - currentIndex) + pageInfo.getPageSize(), entry.getValue()));
pageOfReceipts.addAll(receipts);
if (pageOfReceipts.size() >= pageInfo.getPageSize())
break;
}
}else {