db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/singlevm PersistenceBrokerImpl.java
Date Thu, 02 Jan 2003 09:36:19 GMT
brj         2003/01/02 01:36:19

  Modified:    src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  support "distinct" in getCount()
  
  Revision  Changes    Path
  1.102     +18 -3     jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- PersistenceBrokerImpl.java	31 Dec 2002 11:42:41 -0000	1.101
  +++ PersistenceBrokerImpl.java	2 Jan 2003 09:36:18 -0000	1.102
  @@ -2275,8 +2275,9 @@
       {
           ReportQueryByCriteria reportQuery;
           Criteria reportCrit = null;
  -        String[] columns = new String[]{"count(*)"};
           Iterator iter;
  +        FieldDescriptor[] pkFields = getClassDescriptor(query.getSearchClass()).getPkFields();
  +        String[] columns = new String[pkFields.length];
           int result = 0;
   
           // build a ReportQuery based on query
  @@ -2285,7 +2286,21 @@
           {
               reportCrit = query.getCriteria().copy(false, false, false);
           }
  -
  +   
  +        // BRJ: add a column for each pkField, make it distinct if query is distinct
  +        // tbd check if it really works for multiple keys ?
  +        for (int i = 0; i < pkFields.length; i++)
  +        {
  +            if (query.isDistinct())
  +            {
  +                columns[i] = "count(distinct " + pkFields[i].getAttributeName() + ")";
  +            }
  +            else
  +            {
  +                columns[i] = "count(" + pkFields[i].getAttributeName() + ")";
  +            }
  +        }
  +        
           // BRJ: we have to preserve indirection table !
           if (query instanceof MtoNQuery)
           {
  
  
  

Mime
View raw message