================================================================================ Merge Diffs: /ade/cdelahun_toplinkmain/tldev/source/essentials/oracle/toplink/essentials/queryframework/ReportQuery.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/cdelahun/cdelahun_ri_gf675_060809/ade_storage/000001/AB0952363AC40CBFE034080020E8C54E.27 Report generated at Wed Aug 9 16:47:22 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/cdelahun/cdelahun_ri_gf675_060809/ade_storage/000001/AB0952363AC40CBFE034080020E8C54E.27 Wed Aug 9 13:04:54 2006 --- /ade/cdelahun_toplinkmain/tldev/source/essentials/oracle/toplink/essentials/queryframework/ReportQuery.java Wed Aug 9 16:47:22 2006 *************** *** 911,969 **** * Added to fix bug 3268040, addCount(objectAttribute) not supported. */ protected void prepareObjectAttributeCount(Dictionary clonedExpressions) { ! ReportItem countItem = (getItems().isEmpty() ? null : (ReportItem)getItems().elementAt(0)); ! if ((countItem != null) && (countItem.getAttributeExpression() instanceof FunctionExpression)) { ! FunctionExpression count = (FunctionExpression)countItem.getAttributeExpression(); ! if (count.getOperator().getSelector() == ExpressionOperator.Count) { ! Expression baseExp = count.getBaseExpression(); ! boolean distinctUsed = false; ! if (baseExp.isFunctionExpression() && (((FunctionExpression)baseExp).getOperator().getSelector() == ExpressionOperator.Distinct)) { ! distinctUsed = true; ! baseExp = ((FunctionExpression)baseExp).getBaseExpression(); ! } ! if (baseExp.isQueryKeyExpression()) { ! QueryKeyExpression countExp = (QueryKeyExpression)baseExp; ! ! // now need to find out if it is a direct to field or something else. ! DatabaseMapping mapping = getLeafMappingFor(countExp, getDescriptor()); ! if ((mapping != null) && !mapping.isDirectToFieldMapping() && (mapping.getReferenceDescriptor() != null)) { ! // At this point we are committed to rewriting the query. ! ClassDescriptor newDescriptor = mapping.getReferenceDescriptor(); ! if (distinctUsed) { ! // If this is a subselect countExp is yet uncloned, ! // and will miss out if moved now from items into a selection criteria. ! if (clonedExpressions != null) { ! if (clonedExpressions.get(countExp.getBuilder()) != null) { ! countExp = (QueryKeyExpression)countExp.copiedVersionFrom(clonedExpressions); } else { ! countExp = (QueryKeyExpression)countExp.rebuildOn(getExpressionBuilder()); } ! } ! ! // Now the reference class of the query needs to be reversed. ! // See the bug description for an explanation. ! ExpressionBuilder countBuilder = countExp.getBuilder(); ! ExpressionBuilder outerBuilder = new ExpressionBuilder(); ! ! ReportQuery subSelect = new ReportQuery(getReferenceClass(), countBuilder); ! subSelect.setShouldRetrieveFirstPrimaryKey(true); ! ! // Make sure the outerBuilder does not appear on the left of the subselect. ! // Putting a builder on the left is desirable to trigger an optimization. ! if (getSelectionCriteria() != null) { ! outerBuilder.setQueryClass(newDescriptor.getJavaClass()); ! subSelect.setSelectionCriteria(getSelectionCriteria().and(outerBuilder.equal(countExp))); } else { ! subSelect.setSelectionCriteria(countExp.equal(outerBuilder)); } - setSelectionCriteria(outerBuilder.exists(subSelect)); - getItems().setElementAt(new ReportItem(countItem.getName(), outerBuilder.count()), 0); - setReferenceClass(newDescriptor.getJavaClass()); - changeDescriptor(getSession()); - } else { - // Here everything worked fine, save an empty COUNT() was being generated. - Expression newCount = countExp.prefixSQL("*").count(); - getItems().setElementAt(new ReportItem(countItem.getName(), newCount), 0); } } } --- 911,973 ---- * Added to fix bug 3268040, addCount(objectAttribute) not supported. */ protected void prepareObjectAttributeCount(Dictionary clonedExpressions) { ! int numOfReportItems = getItems().size(); ! //gf675: need to loop through all items to fix all count(..) instances ! for (int i =0;i